Skip to content

Instantly share code, notes, and snippets.

@yassersouri
Created November 27, 2012 13:05
Show Gist options
  • Star 5 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save yassersouri/4154139 to your computer and use it in GitHub Desktop.
Save yassersouri/4154139 to your computer and use it in GitHub Desktop.
DTFT in matlab
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
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');
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.
@Basavaraj-PN
Copy link

Basavaraj-PN commented Sep 4, 2017

i need program dtft without using built in function!!

@Basavaraj-PN
Copy link

Basavaraj-PN commented Sep 4, 2017

too many error in the program

@bakhtawarkhalid
Copy link

% 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

@mmmm95
Copy link

mmmm95 commented Mar 30, 2020

15235

help me to solve this problem...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment