필터 지우기
필터 지우기

Plotting DTFT in Matlab

조회 수: 45 (최근 30일)
Tomasz Nowopolski
Tomasz Nowopolski 2022년 11월 26일
답변: Ishan 2022년 11월 29일
I'm trying to create a DTFT function in Matlab for my assignment.
I'm using the built-in FFT function to compare my results and wager if my results are correct (I'm assuming the results should be the same just with different error margins), but the result I'm getting is entirely different and I'm not sure why.
Main code:
L = 1000;
fg = 1000;
fs = 100000;
T = 1/fs;
tmin = 0;
K = 1;
n = tmin:L;
t = n*T;
%Base function calculation
x = xdp1(K, fg, t);
%Fourier transform calculation
w = t;
%X = dtft(x, t);
%X = dtft2(x, w, n);
X = dtft3(x, w, n);
X_FFT = fft(x);
% Top plot
tiledlayout(3,1)
nexttile
plot(t, x)
ylim([min(x) max(x)])
xlim([0 max(t)])
title('Signal')
% Middle plot
nexttile
plot(t, abs(X));
title('DTFT')
% Bottom plot
nexttile
plot(t, abs(X_FFT))
ylim([min(abs(X_FFT)) max(abs(X_FFT))])
xlim([0 max(t)])
title('FFT')
Signal calc code (xdp1):
function x = xdp1(K, fg, t)
x = K * 2 * fg * sinc(2 * pi * fg * t);
end
DTFT calc code (dtft3):
function X = dtft3(x, w, n)
X = exp(-1i*w'*n) * x.';
end
My other attempts that minimized the Matlab exclusive syntax:
DTFT calc code (dtft2):
function X = dtft2(x, w, n)
for i=1:length(w)
X(i)=sum(x.*exp(-1i*w(i)*n));
end
end
DTFT calc code (dtft):
function X = dtft(x, w)
X = zeros(1, length(x));
for n=1:length(x)
X = X + x(n) * exp(-1i * w * n);
end
end
Result plot:

답변 (1개)

Ishan
Ishan 2022년 11월 29일
Hi Tomasz,
I understand you are trying to cross verify your DTFT function. You can refer to the functions in the file exchange attached below
Hope this helps out!

카테고리

Help CenterFile Exchange에서 Discrete Fourier and Cosine Transforms에 대해 자세히 알아보기

태그

제품

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by