30 lines
746 B
Matlab
30 lines
746 B
Matlab
function X = dtft ( x , n , w )
|
|
% DTFT Computes Discrete-time Fourier transform
|
|
% @param x : finite duration sequence (vector) over n
|
|
% @param n : sample indices vector
|
|
% @param w : frequency vector
|
|
% @return X : DTFT of x[n] at frequencies w
|
|
% this function does not use for loops
|
|
X = sum(x(:) .* exp(-1j * n(:) * w), 1);
|
|
end
|
|
|
|
n = -10:10;
|
|
x = (0.8) .^ abs(n) .* ((n >= -10) & (n < 11));
|
|
w = linspace(-pi, pi, 1000);
|
|
|
|
X = dtft(x, n, w);
|
|
|
|
magnitude = abs(X);
|
|
phase = angle(X);
|
|
figure;
|
|
subplot(2, 1, 1);
|
|
plot(w, magnitude);
|
|
title('Magnitude Response');
|
|
xlabel('Frequency (rad/sample)');
|
|
ylabel('|X(w)|');
|
|
subplot(2, 1, 2);
|
|
plot(w, phase);
|
|
title('Phase Response');
|
|
xlabel('Frequency (rad/sample)');
|
|
ylabel('Phase(rad)');
|