MATLAB: Dtft error in matlab

dft errordtft errror

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.

Best Answer

MATLAB does not have any function named dtft()
You could consider https://www.mathworks.com/matlabcentral/fileexchange/63830-digital-signal-processing-discrete-time-fourier-transform-dtft
Related Question