DFT Implementation
DFT is used to convert a signal sample array x(n) of size 1 x N to signal spectral component array X(k) of size 1 x N.
%programme
clear all;
ln = length(xn);
xk = zeros(1,ln);
ixk = zeros(1,ln);
for n=0:ln-1
xk(k+1) = xk(k+1)+(xn(n+1)*exp((-i)*2*pi*k*n/ln));
end
end%hear xk(k+1); because of in matlab array index start form 1
t = 0:ln-1;
subplot(3,2,1);
stem(t,xn);
subplot(3,2,1);
stem(t,xn);
title ('Input Sequence x(n)');
xlabel('Time Index');
ylabel('Amplitude');
xlabel('Time Index');
ylabel('Amplitude');
t = 0:ln-1;
subplot(3,2,2);
stem(t,xk);
subplot(3,2,2);
stem(t,xk);
ylabel ('Amplitude');
title ('X(K)');
xlabel ('K');
title ('X(K)');
xlabel ('K');
t = 0:ln-1;
subplot(3,2,3);
stem(t,abs(xk));
subplot(3,2,3);
stem(t,abs(xk));
ylabel ('Amplitude');
%-------------------------------------------------------------------%
%Output
%Enter the sequence[ 1 2 3 3 2 1]
No comments:
Post a Comment