3. DFT Computation using MATLAB The functions to compute the DFT and the IDFT are fft and ifft These functions make use of fft algorithms which are computationally highly efficient compared with the direct computation Figure in the next slide shows the dft and DTFT of the sequence cos(6xn/16)0≤n≤15
3. DFT Computation using MATLAB
3. DFT Computation using MATLAB O DF DTF WW
3. DFT Computation using MATLAB
3. DFT Computation using MATLAB o EXample DF T computation using MATLAB M-point DFT Uk
3. DFT Computation using MATLAB ⚫ Example DFT computation using MATLAB M –point DFT U[k]
3. DFT Computation using MATLAB Program 5 %lustration of DFT Computation 9 Read in the length n of sequence and the desired length M of the DFT N= input( Type in the length of the sequence=) M= input( Type in the length of the DFT=); u= [ones(1, N)]; %Generate the length-Ntime-domain sequence U=fft(u, M); %Compute its M-point DFT t=0: 1: N-1; Plot the time-domain sequence and its DFT stem(t, u) title (Original time-domain sequence); Xlabel(Time index n): ylabel (Amplitude) pause subplot(2, 1, 1):k=0: 1: M-1; stem(k, abs(U title(Magnitude of the DFT samples") xlabel(Frequency index k): ylabel( Magnitude) subplot(2, 1, 2); stem(k, angle(U)) title(Phase of the dF T samples); xlabel( Frequency index k); ylabel(Phase")
% Program 5_1 % Illustration of DFT Computation % Read in the length N of sequence and the desired length M of the DFT N = input('Type in the length of the sequence = '); M = input('Type in the length of the DFT = '); u = [ones(1,N)]; % Generate the length-N time-domain sequence U = fft(u,M); % Compute its M-point DFT t = 0:1:N-1; % Plot the time-domain sequence and its DFT stem(t,u) title('Original time-domain sequence'); xlabel('Time index n'); ylabel('Amplitude') pause subplot(2,1,1); k = 0:1:M-1; stem(k,abs(U)) title('Magnitude of the DFT samples') xlabel('Frequency index k'); ylabel('Magnitude') subplot(2,1,2); stem(k,angle(U)) title('Phase of the DFT samples'); xlabel('Frequency index k'); ylabel('Phase') 3. DFT Computation using MATLAB
3. DFT Computation using MATLAB Program Illustration of idF T Computation Read in the length K of the dF T and the desired length n of the IDFT K= input( Type in the length of the DFT=) N= input( Type in the length of the IDFT=); k=O: K-1;% Generate the length-KDFT sequence V=k/K. V= ifft(V, N); %Compute its N-point IDFT stem(k,V) Plot the dft and its idFT xlabel(Frequency index k); ylabel(Amplitude); title('Original DFT samples) pause subplot(2, 1, 1) n=0:N-1 stem(n, real(v)); title(Real part of the time-domain samples) xlabel(Time index n"); ylabel(Amplitude,) subplot(2, 1, 2); stem(n,imag(v)); title(lmaginary part of the time-domain samples) xlabel( time index n); ylabel (amplitude)
Program 5_2 % Illustration of IDFT Computation % Read in the length K of the DFT and the desired length N of the IDFT K = input('Type in the length of the DFT = '); N = input('Type in the length of the IDFT = '); k = 0:K-1; % Generate the length-K DFT sequence V = k/K; v = ifft(V,N); % Compute its N-point IDFT stem(k,V) % Plot the DFT and its IDFT xlabel('Frequency index k'); ylabel('Amplitude'); title('Original DFT samples') pause subplot(2,1,1) n = 0:N-1; stem(n,real(v)) ; title('Real part of the time-domain samples'); xlabel('Time index n'); ylabel('Amplitude') subplot(2,1,2); stem(n,imag(v)); title('Imaginary part of the time-domain samples') xlabel('Time index n'); ylabel('Amplitude') 3. DFT Computation using MATLAB