Computation of N point DFT of a given sequence and to plot
magnitude and phase spectrum.
Discrete Fourier Transform (DFT) is used for performing frequency
analysis of discrete time signals. DFT gives a discrete frequency domain
representation whereas the other transforms are continuous in frequency
domain.
Program to compute N point DFT using 'fft' commandfft’ command
clc;
close all;
clear all;
N=4
N=4
N = 4
x=[1,2,3,6];
xk=fft(x,N);
Plot of input sequence
n=[Link]N-1;
subplot(3,1,1);
n1=[Link]length(x)-1;
stem(n1,x);
xlabel(' n');
ylabel('x[n]');
title('original signal');
Plot of amplitude spectrum
subplot(3,1,2);
stem(n,abs(xk));
xlabel(' k');
ylabel('lxkl');
title('Magnitude spectrum');
Phase spectrum
subplot(3,1,3);
stem(n,angle(xk));
xlabel(' k');
ylabel('angle(xk)');
title('phase spectrum');
1
N=8
N=8
N = 8
x=[1,2,3,6];
xk=fft(x,N);
Plot of input sequence
n=[Link]N-1;
subplot(3,1,1);
n1=[Link]length(x)-1;
stem(n1,x);
xlabel(' n');
ylabel('x[n]');
title('original signal');
Plot of amplitude spectrum
subplot(3,1,2);
stem(n,abs(xk));
xlabel(' k');
ylabel('lxkl');
title('Magnitude spectrum');
2
Phase spectrum
subplot(3,1,3);
stem(n,angle(xk));
xlabel(' k');
ylabel('angle(xk)');
title('phase spectrum');
When: n1=0:7; x = cos(*pi*n1*250/8000); %x[n] sequence of 250Hz with
fs=8kHz, & N=8 point DFT
N=8
N = 8
x=[1,2,3,6];
n1=0:7;
x=cos(2*pi*n1*250/8000);
%x is a sequence of 250Hz with
%fs=8kHz
xk=fft(x,N);
Plot of input sequence
n=[Link]N-1;
subplot(3,1,1);
n1=[Link]length(x)-1;
3
stem(n1,x);
xlabel(' n');
ylabel('x[n]');
title('original signal');
Plot of amplitude spectrum
subplot(3,1,2);
stem(n,abs(xk));
xlabel(' k');
ylabel('lxkl');
title('Magnitude spectrum');
Phase spectrum
subplot(3,1,3);
stem(n,angle(xk));
xlabel(' k');
ylabel('angle(xk)');
title('phase spectrum');
When: n1=0:7; x=cos(2*pi*n1*250/8000); %x[n] sequence of 250Hz with
fs=8kHz, & N=80 point DFT
N=80
4
N = 80
x=[1,2,3,6];
n1=0:7;
x=cos(2*pi*n1*250/8000);
%x is a sequence of 250Hz with
%fs=8kHz
xk=fft(x,N);
Plot of input sequence
n=[Link]N-1;
subplot(3,1,1);
n1=[Link]length(x)-1;
stem(n1,x);
xlabel(' n');
ylabel('x[n]');
title('original signal');
Plot of amplitude spectrum
subplot(3,1,2);
stem(n,abs(xk));
xlabel(' k');
ylabel('lxkl');
title('Magnitude spectrum');
Phase spectrum
subplot(3,1,3);
stem(n,angle(xk));
xlabel(' k');
ylabel('angle(xk)');
title('phase spectrum');
5
When: n1=0:79; x=cos(2*pi*n1*250/8000); %x[n] sequence of 250Hz with
fs=8kHz, & N=80 point DFT
N=80
N = 80
x=[1,2,3,6];
n1=0:79;
x=cos(2*pi*n1*250/8000);
%x is a sequence of 250Hz with
%fs=8kHz
xk=fft(x,N);
Plot of input sequence
n=[Link]N-1;
subplot(3,1,1);
n1=[Link]length(x)-1;
stem(n1,x);
xlabel(' n');
ylabel('x[n]');
title('original signal');
Plot of amplitude spectrum
6
subplot(3,1,2);
stem(n,abs(xk));
xlabel(' k');
ylabel('lxkl');
title('Magnitude spectrum');
Phase spectrum
subplot(3,1,3);
stem(n,angle(xk));
xlabel(' k');
ylabel('angle(xk)');
title('phase spectrum');
When: n1=0:79; x=cos(2*pi*n1*250/8000); %x[n] sequence of 250Hz with
fs=8kHz, & N=160 point DFT
N=160
N = 160
x=[1,2,3,6];
n1=0:79;
x=cos(2*pi*n1*250/8000);
%x is a sequence of 250Hz with
%fs=8kHz
xk=fft(x,N);
7
Plot of input sequence
n=[Link]N-1;
subplot(3,1,1);
n1=[Link]length(x)-1;
stem(n1,x);
xlabel(' n');
ylabel('x[n]');
title('original signal');
Plot of amplitude spectrum
subplot(3,1,2);
stem(n,abs(xk));
xlabel(' k');
ylabel('lxkl');
title('Magnitude spectrum');
Phase spectrum
subplot(3,1,3);
stem(n,angle(xk));
xlabel(' k');
ylabel('angle(xk)');
title('phase spectrum');
8
Inference
%%N point dft of given signal is computed and magnitude and phase spectrum are plotted