To perform Discrete Fourier Transform and to study magnitude spectrum of the DT signal > Matlab

To perform Discrete Fourier Transform and to study magnitude spectrum of the DT signal > Matlab

Digital Signal Processing 


Program:

x = [2 3 -1 4];
N = length(x);
X = zeros(4,1)
for k = 0:N-1
    for n = 0:N-1
        X(k+1) = X(k+1) + x(n+1)*exp(-j*pi/2*n*k)
    end
end


t = 0:N-1
subplot(311)
stem(t,x);
xlabel('Time (s)');
ylabel('Amplitude');
title('Time domain - Input sequence')

subplot(312)
stem(t,X)
xlabel('Frequency');
ylabel('|X(k)|');
title('Frequency domain - Magnitude response')

subplot(313)
stem(t,angle(X))
xlabel('Frequency');
ylabel('Phase');
title('Frequency domain - Phase response')

X         % to check |X(k)|
angle(X)  % to check phase


OUTPUT:

X =
     0
     0
     0
     0
X =

     2
     0
     0
     0


X =

     5
     0
     0
     0


X =

     4
     0
     0
     0


X =

     8
     0
     0
     0


X =

     8
     2
     0
     0


X =

   8.0000         
   2.0000 - 3.0000i
        0         
        0         


X =

   8.0000         
   3.0000 - 3.0000i
        0         
        0         


X =

   8.0000         
   3.0000 + 1.0000i
        0         
        0         


X =

   8.0000         
   3.0000 + 1.0000i
   2.0000         
        0         


X =

   8.0000         
   3.0000 + 1.0000i
  -1.0000 - 0.0000i
        0         


X =

   8.0000         
   3.0000 + 1.0000i
  -2.0000 - 0.0000i
        0         


X =

   8.0000         
   3.0000 + 1.0000i
  -6.0000 - 0.0000i
        0         


X =

   8.0000         
   3.0000 + 1.0000i
  -6.0000 - 0.0000i
   2.0000         


X =

   8.0000         
   3.0000 + 1.0000i
  -6.0000 - 0.0000i
   2.0000 + 3.0000i


X =

   8.0000         
   3.0000 + 1.0000i
  -6.0000 - 0.0000i
   3.0000 + 3.0000i


X =

   8.0000          
   3.0000 + 1.0000i
  -6.0000 - 0.0000i
   3.0000 - 1.0000i


t =

     0     1     2     3


X =

   8.0000         
   3.0000 + 1.0000i
  -6.0000 - 0.0000i
   3.0000 - 1.0000i


ans =

         0
    0.3218
   -3.1416
   -0.3218


Comments

Popular posts from this blog

Intermediate Code Generation > C Program