



Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
This matlab script defines a function for performing the complex discrete fourier transform on a given input signal. The function takes the time vector and the frequency vector as inputs, and returns the complex coefficients of the transform. The script also includes a plot of the original signal and its frequency spectrum.
Typology: Lecture notes
1 / 6
This page cannot be seen from the preview
Don't miss anything!




function [Ck,fk] = DFTCmplx( T,F ) %UNTITLED2 Summary of this function goes here % Detailed explanation goes here N=length(F)/2; dt=(T(2N)-T(1))/(2N-1); fk=[0:N]/(dt2N); Ck(1)=sum(F(1:2N))/(2N); for k=2:N CkI(k)=0; CkR(k)=0; for j=1:2N CkI(k)=CkI(k)+F(j)sin(pi(k-1)T(j)/(dtN)); CkR(k)=CkR(k)+F(j)cos(pi(k-1)T(j)/(dtN)); end Ck(k)=(CkR(k)-CkI(k)i)/(2N); end Ck(N+1)=0; for j=1:2N Ck(N+1)=Ck(N+1)+F(j)cos(piNT(j)/(dtN)); end Ck(N+1)=Ck(N+1)/(4*N); end
nu = 200; Frq=200; Fun = @ (t) sin(2piFrqt)+0.5sin(2pi4Frqt)+0.8cos(2pi2Frqt) +0.4cos(2pi12Frqt); fS = 20000; dts = 1/fS; tau = 0.005; tp = linspace(0,tau,200); yp = Fun (tp) ; ts = 0:dts:tau-dts; ys = Fun (ts) ; plot(tp1000,yp, 'k' ,ts1000,ys,'oc') [C fr] = DFTCmplx(ts,ys); figure; stem(fr,real(C) ,'oc' ,'markersize' ,12,'LineWidth' ,1) figure stem(fr,imag(C) ,'oc', 'markersize' ,12, 'linewidth' ,1)
A=real(2iC); B=imag(2iC); figure; stem(fr,A ,'or' ,'markersize' ,12,'LineWidth' ,1); figure; stem(fr,B ,'or' ,'markersize' ,12,'LineWidth' ,1);