0% found this document useful (0 votes)
723 views9 pages

Lab p2

The document discusses computing the discrete Fourier transform (DFT) of discrete time signals. It provides code to calculate the N-point DFT of different input sequences using the 'fft' command and plot the magnitude and phase spectra. The code is run for different sequence lengths N and different input signals, including a 250Hz cosine signal with sampling frequency 8kHz.
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)
723 views9 pages

Lab p2

The document discusses computing the discrete Fourier transform (DFT) of discrete time signals. It provides code to calculate the N-point DFT of different input sequences using the 'fft' command and plot the magnitude and phase spectra. The code is run for different sequence lengths N and different input signals, including a 250Hz cosine signal with sampling frequency 8kHz.
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/ 9

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=0:1:N-1;
subplot(3,1,1);
n1=0:1: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=0:1:N-1;
subplot(3,1,1);
n1=0:1: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=0:1:N-1;
subplot(3,1,1);
n1=0:1: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=0:1:N-1;
subplot(3,1,1);
n1=0:1: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=0:1:N-1;
subplot(3,1,1);
n1=0:1: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=0:1:N-1;
subplot(3,1,1);
n1=0:1: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

You might also like