Complex Discrete Fourier Transform Function, Lecture notes of Mathematical Methods for Numerical Analysis and Optimization

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

2018/2019

Uploaded on 03/18/2019

faizah-faizar
faizah-faizar 🇲🇾

2 documents

1 / 6

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
function [Ck,fk] = DFTCmplx( T,F )
%UNTITLED2 Summary of this function goes here
% Detailed explanation goes here
N=length(F)/2; dt=(T(2*N)-T(1))/(2*N-1);
fk=[0:N]/(dt*2*N); Ck(1)=sum(F(1:2*N))/(2*N);
for k=2:N
CkI(k)=0; CkR(k)=0;
for j=1:2*N
CkI(k)=CkI(k)+F(j)*sin(pi*(k-1)*T(j)/(dt*N));
CkR(k)=CkR(k)+F(j)*cos(pi*(k-1)*T(j)/(dt*N));
end
Ck(k)=(CkR(k)-CkI(k)*i)/(2*N);
end
Ck(N+1)=0;
for j=1:2*N
Ck(N+1)=Ck(N+1)+F(j)*cos(pi*N*T(j)/(dt*N));
end
Ck(N+1)=Ck(N+1)/(4*N);
end
nu = 200; Frq=200;
Fun = @ (t) sin(2*pi*Frq*t)+0.5*sin(2*pi*4*Frq*t)+0.8*cos(2*pi*2*Frq*t)
+0.4*cos(2*pi*12*Frq*t);
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(tp*1000,yp, 'k' ,ts*1000,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(2i*C); B=imag(2i*C);
figure;
stem(fr,A ,'or' ,'markersize' ,12,'LineWidth' ,1);
figure;
stem(fr,B ,'or' ,'markersize' ,12,'LineWidth' ,1);
pf3
pf4
pf5

Partial preview of the text

Download Complex Discrete Fourier Transform Function and more Lecture notes Mathematical Methods for Numerical Analysis and Optimization in PDF only on Docsity!

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);