dtft error in matlab
Show older comments
Hi, there this is piece of code and I am getting these errors (Undefined function or variable 'dtft'.Error in Lab9 (line 12) X_DTFT = dtft(x,w);) so, can you please help me out with this, Thanks in advance.
N =100; %signal length
M =2^16; %FFT size(M >= N)
n=0:N-1; %discrete time vector
x = (0.8.^ n).* cos (0.5* pi*n); %signal
%Calculate DFT and measure calculation time
tic;
X_DFT = fft(x,M);
toc;
%Calculate DTFT and measure calculation time
w = -pi :2* pi/M:pi -2* pi/M; % freq vector
tic;
X_DTFT = dtft(x,w);
toc;
%Elapsed time is 0.001090 seconds.
%Elapsed time is 0.000066 seconds.
%Plot magnitude and phase of DTFT ( blue solid line ) and DFT (red x)
figure;
subplot (2, 1, 1)
plot (w/pi , fftshift (abs ( X_DFT )), 'b-');
hold on;
plot (w/pi,abs(X_DTFT),'rx');
hold off ;
grid on;
title ('Magnitude')
xlabel ('Normalized Radian Frequency (\ times \pi rad / sample )');
ylabel ('Amplitude');
legend ('DFT','DTFT');
subplot (2, 1, 2)
plot (w/pi , fftshift ( angle ( X_DFT )/pi),'b-');
hold on;
plot (w/pi , angle (X_DTFT )/pi ,'rx');
hold off ;
grid on;
title ('Phase')
xlabel ('Normalized Radian Frequency (\ times \pi rad / sample )');
ylabel ('Phase (\ times \pi rad )');
legend ('DFT','DTFT');
%Elapsed time is 0.001090 seconds.
%Elapsed time is 0.000066 seconds.
Accepted Answer
More Answers (0)
Categories
Find more on Spectral Measurements in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!