0% found this document useful (0 votes)
38 views

Discrete Fourier Transform

The document discusses the discrete Fourier transform (DFT) and its application to linear and circular convolution. It provides code to calculate the DFT of input signals, multiply their frequency domain representations to obtain the convolution, and use the inverse DFT to return to the time domain. Results are plotted to show the input, impulse response, and convoluted signals in both the time and frequency domains.

Uploaded by

Pavani Sampath
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
38 views

Discrete Fourier Transform

The document discusses the discrete Fourier transform (DFT) and its application to linear and circular convolution. It provides code to calculate the DFT of input signals, multiply their frequency domain representations to obtain the convolution, and use the inverse DFT to return to the time domain. Results are plotted to show the input, impulse response, and convoluted signals in both the time and frequency domains.

Uploaded by

Pavani Sampath
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 7

Discrete fourier Transform

clear all
clc
x=[ 4 1 3 4 ];
N=length(x);
n=0:N-1;
for k=0:N-1
W=exp((-j*2*pi*n*k)/N);
X(k+1)=sum(x.*W);
fprintf('X(%f) = %f+%fi
\n',k,real(X(k+1)),imag(X(k+1)));
end

figure(1);
subplot(3,1,1);
stem(n,x);
xlabel('n');
ylabel('x(n)');
title('input signal');

subplot(3,1,2);
stem(n,X);
xlabel('n');
ylabel('X(k) (kth sample)');
title('DFT');

subplot(3,1,3);
stem(n,fft(x));
xlabel('n');
ylabel('X(k) (kth sample)');
title('FFT');
Output:
X(0.000000) = 12.000000+0.000000i
X(1.000000) = 1.000000+3.000000i
X(2.000000) = 2.000000+-0.000000i
X(3.000000) = 1.000000+-3.000000i
>>
input signal
4

x(n)
2

0
0 0.5 1 1.5 2 2.5 3
n
DFT
X(k) (kth sample)

20

10

0
0 0.5 1 1.5 2 2.5 3
n
FFT
X(k) (kth sample)

20

10

0
0 0.5 1 1.5 2 2.5 3
n
Linear convolution:
clear all
clc

x=[ 1 2 3 4 5 6];
h=[4 1 3 4];

nx=length(x);
nh=length(h);
ny=nx+nh-1;

padx=[x zeros(1, ny-nx)];


Xk=fft(padx);

padh=[h zeros(1, ny-nh)];


Hk=fft(padh);

Yk=Xk.*Hk

n=0:length(Xk)-1;
m=0:length(Hk)-1;
p=0:length(Yk)-1;

yn=ifft(Yk)
yt=conv(x,h)

figure(1);
subplot(3,1,1);
stem(n,Xk);
xlabel('nx');
ylabel('x(n)');
title('input signal');

subplot(3,1,2);
stem(m,Hk);
xlabel('nh');
ylabel('h(n)');
title('impulse response');
subplot(3,1,3);
stem(p,Yk);
xlabel('n');
ylabel('Yk');
title('Convoluted signal');

Output:

Yk =

1.0e+02 *

Columns 1 through 7

2.5200 + 0.0000i -0.8250 + 0.4136i -0.0294 +


0.0731i -0.2100 + 0.0520i -0.0155 - 0.1326i -0.0155 +
0.1326i -0.2100 - 0.0520i

Columns 8 through 9

-0.0294 - 0.0731i -0.8250 - 0.4136i

yn =

4.0000 9.0000 17.0000 29.0000 41.0000


53.0000 37.0000 38.0000 24.0000
yt =

4 9 17 29 41 53 37 38 24

>>

input signal
50
x(n)

-50
0 1 2 3 4 5 6 7 8
nx
impulse response
20
h(n)

-20
0 1 2 3 4 5 6 7 8
nh
Convoluted signal
500
Yk

-500
0 1 2 3 4 5 6 7 8
n

Circular Convolution:
clear all
clc

x=[ 1 2 3 4 5 6];
h=[4 1 3 4];

nx=length(x);
nh=length(h);
ny=max(nx,nh);

padx=[x zeros(1, ny-nx)];


Xk=fft(padx);

padh=[h zeros(1, ny-nh)];


Hk=fft(padh);

Yk=Xk.*Hk

n=0:length(Xk)-1;
m=0:length(Hk)-1;
p=0:length(Yk)-1;

yn=ifft(Yk)
yt=conv(x,h)

figure(1);
subplot(3,1,1);
stem(n,Xk);
xlabel('nx');
ylabel('x(n)');
title('input signal');

subplot(3,1,2);
stem(m,Hk);
xlabel('nh');
ylabel('h(n)');
title('impulse response');

subplot(3,1,3);
stem(p,Yk);
xlabel('ny');
ylabel('Yk');
title('Convoluted signal');

Output:

Yk =
1.0e+02 *

2.5200 + 0.0000i 0.2100 + 0.0520i -0.2100 +


0.0520i -0.0600 + 0.0000i -0.2100 - 0.0520i 0.2100 -
0.0520i

yn =

41 47 41 29 41 53

yt =

4 9 17 29 41 53 37 38 24

input signal
50
x(n)

-50
0 0.5 1 1.5 2 2.5 3 3.5 4 4.5 5
nx
impulse response
20
h(n)

-20
0 0.5 1 1.5 2 2.5 3 3.5 4 4.5 5
nh
Convoluted signal
500
Yk

-500
0 0.5 1 1.5 2 2.5 3 3.5 4 4.5 5
ny

You might also like