0% found this document useful (0 votes)
44 views6 pages

Exp 2

This document discusses and provides examples of the discrete Fourier transform (DFT) and linear convolution using a DFT-based approach. It includes code to: 1) Calculate the N-point DFT for different values of N 2) Calculate the DFT of an impulse response 3) Perform linear convolution of two sequences via multiplication in the DFT domain and inverse DFT Plots of amplitude and phase are generated for the DFT results, and plots compare the input and convolved sequences.

Uploaded by

Rishi Sharma
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
44 views6 pages

Exp 2

This document discusses and provides examples of the discrete Fourier transform (DFT) and linear convolution using a DFT-based approach. It includes code to: 1) Calculate the N-point DFT for different values of N 2) Calculate the DFT of an impulse response 3) Perform linear convolution of two sequences via multiplication in the DFT domain and inverse DFT Plots of amplitude and phase are generated for the DFT results, and plots compare the input and convolved sequences.

Uploaded by

Rishi Sharma
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 6

N Point DFT:

N = input('Enter length of DFT\n');


M=10;

for k = 1:N
if(k<M)
x(k)=1;
else
x(k)=0;
end
end

for k = 1:N
X(k) = 0;
for n = 1:N
X(k) = X(k)+ x(k)*(cos(2*pi*k*n/N)-sqrt(-1)*sin(2*pi*k*n/N));
end
end

k = 1:N;

subplot(2,1,1)

stem(abs(X));

title('Amplitude plot');

ylabel('amplitude');
xlabel('Time');

subplot(2,1,2)

stem(angle(X));
title('Phase plot');
ylabel('amplitude');
xlabel('Time');

N_point_DFT
Enter length of DFT
10

M =

10

1.0e-14 *

Columns 1 through 6
-0.0444 + 0.0245i -0.0444 + 0.0268i -0.0222 + 0.0513i
0.0000 + 0.0425i 0.0000 + 0.0612i 0.0333 + 0.0914i

Columns 7 through 10
-0.4885 + 0.4934i 0.1221 + 0.1182i 0.2331 + 0.5535i
0.0000 + 0.000
Fig representing the N point DFT for M=10 and different values of N =10 && 100 && 256
DFT with given impulse response

x = input('Enter range of n');


n = length(x);

u = n/2;

for l = 1:n
if(x(l)==0)
h(l)=0.5;
else
h(l)=sin(0.5*pi*(l-u-1))/(pi*(l-u-1));
end
end

for k = 1:n
X(k) = 0;
for l = 1:n
X(k) = X(k)+ h(k)*(cos(2*pi*k*l/n)-sqrt(-
1)*sin(2*pi*k*l/n));
end
end

subplot(2,1,1)
stem(abs(X))

title('Amplitude plot')
grid on

ylabel('amplitude');
xlabel('Time');

subplot(2,1,2)
stem(angle(X))
title('Phase plot')
grid on

ylabel('amplitude');
xlabel('Time');
Fig representing DFT of impulse response h(n) for n=[-8:7],[-
16:15],[-64,63]
Linear Convolution via DFT based approach:
x=input('Input First Sequence');

h=input('Input Second Sequence');

n1=length(x);
n2=length(h);
N=n1+n2-1;

x1=[x zeros(1,N-n1)];

x2=[h zeros(1,N-n2)];

a=fft(x, N);

b=fft(h, N);

c=a.*b;

d=ifft(c, N);

disp('First Sequence');
disp(x)
disp('Second Sequence');
disp(h)
disp('Convolved Sequence');
disp(d)

n=0:N-1;

subplot(3,1,1);

stem(x);
title('First Sequence');
ylabel('Signal');
xlabel('Time');

subplot(3,1,2);

stem(h);
title('Second Sequence');
ylabel('Signal');
xlabel('Time');

subplot(3,1,3);

stem(d);
title('Convolved Sequence');
ylabel('Signal');
xlabel('Time');
Fig representing Linear Convolution via DFT based approach of
two sequences

You might also like