Created
November 27, 2012 13:05
-
-
Save yassersouri/4154139 to your computer and use it in GitHub Desktop.
DTFT in matlab
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function [ X ] = dtft( x, n, w ) | |
% [X] = dtft(x, n, w) | |
% X = DTFT values computed at w frequencies | |
% x = finite duration sequence over n | |
% n = sample position vector | |
% w = frequency location vector | |
temp = w' * n; | |
temp = -1i * temp; | |
e = exp(temp); | |
X = e * x'; | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
w = -2*pi:0.01:2*pi; | |
n = 0:1:100; | |
w0 = 2; | |
x = exp(n .* (1i*w0)); % x = exp(jw0n) | |
X = dtft(x, n, w); | |
subplot(2,1,1); plot(n, x); title('signal = exp(jw0n)'); | |
subplot(2,1,2); plot(w, X); title('DTFT'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
What I wanted to achieve in the implementation of DTFT was not using `for` loops. | |
Looking at the example it must be clear how to use this function. |
% Enter the range of non zero values of x
n=input('Enter array n (starting to ending value for the axis of x: ');
N=length(n);
%Finding x
x=[ ]
fori=n(1):n(length(n))
if(i<0)
a=0;
else
a=(1/2).^i;
end
x=[x a];
end
subplot(2,1,1)
stem(n,x)
title('Original')
X=DTFT(x,N)
subplot(2,1,2)
ezplot(abs(X))
title('Transform')
%DTFT Function
function[X]=DTFT(x,N)
symsw;
n=0:N-1;
f=x.exp(-1jw*n);
X=sum(f);
end
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
too many error in the program