DSP Lab Manual

Download as pdf or txt
Download as pdf or txt
You are on page 1of 75

MLRIT/ ECE

Digital Signal Processing Lab


Exp.No:1

Generation of Sinusoidal Waveform


AIM:
TO Write the Matlab Program for sinusoidal signal generation through non-recursive
filtering (FIR filtering).
TOOL:
MATLAB Software 9.0
Concept of Filtering:
One application of an LTI discrete-time system is to pass certain frequency components
in an input sequence without any distortion and block other frequency components. Such systems
are called digitalfil ters and one of the main subjects of our laboratory. The key to the filtering
process is the inverse Discrete Fourier transform given by x(n)

1
2

X (e

)e j n d , Which

expresses an arbitrary input sequence as a linear weighed sum of an infinite number of


exponential sequence, or equivalently, as a linear weighted sum of sinusoidal sequences. As a
result, by appropriately choosing the values of magnitude function of the LTI digital filter at
frequencies corresponding to the frequencies of the sinusoidal components of the input, some of
these sinusoidal sequences can be selectively heavily attenuated or filtered with respect to the
others. Now we shall consider the design of a very simple digital Low pass Filter. The input
signal consists of a sum of two cosine sequences of angular frequencies 0.1 rad/samples and 0.4
rad/samples ,respectively. We need to design of a HPF that will pass the high frequency
components of the input but block the low frequency part.
For simplicity we assume the filter to be an FIR filter of length 3 with an impulse response
h[0]=h[2]=, h[1]=.
Hence, the input output relationship of an LTI discrete Time system as shown in fig, with an
impulse response h[n], is given by the convolution sum is given by

h[n]

X(n)

y[ n ]

y(n)

h [ n ]x [ n k ]

Therefore

y[n] h[0]x[n]h[1]x[n 1]h[2]x[n 2]


1|Page

MLRIT/ ECE

Digital Signal Processing Lab

y[n] x[n] x[n 1] x[n 2]


Thus our design objective is to choose suitable values for the filter parameters, and , so that
the output of the filter is a cosine sequence with a frequency 0.4 rad/samples.
The frequency response of the FIR filter is given by H (e j )

h(n)e

j n

H (e j ) h[0] h[1]e j h[2]e j 2


e j e j
H (e j ) (1 e j 2 ) e j 2
2

j
j
e e

(2 cos )e j
the magnitude and phase functions of this filter are

H (e j ) 2 cos ,

( ) .
In order to stop the low-frequency component from appearing at the output of the filter, the
magnitude function at 0.1 should be equal to zero .similarly ,to pass the high-frequency
component without any attenuation, we need to ensure that the magnitude function at 0.4 is
equal to 1. Thus, the two conditions that must be satisfied are

2 cos(0.1) 0 ,
2 cos(0.4) 1
Solving the above equations, we arrive at

6.76195, 13.456335
There fore we can get the input-output relation of the desired FIR filter as

y (n) 6.76195( x[n] x[n 2]) 13.456335 x[n 1],


With,
x[n] cos(0.1n) cos(0.4n).

2|Page

MLRIT/ ECE

Digital Signal Processing Lab

PROGRAM:
% Set up the filter coefficients
b = [-6.76195 13.456335 -6.76195];
% Set initial conditions to zero values
zi = [0 0];
% Generate the two sinusoidal sequences
n = 0:99;
x1=cos(0.1*n);
x2=cos(0.4*n);
% Generate the filter output sequence
y=filter(b, 1, x1+x2, zi);
% Plot the input and output sequences
subplot(1,1,1);
plot(n,y,r,n,x2,b,n,x1,g);
grid;
axis ([0 100 -1.2 4]);
ylabel(Amplitude); xlabel(Time index, n);
legend(r-,y[n],b,x2[n],g-.,x1[n])
OUTPUT WAVEFORM:

Q1.Define filter, what do be the filter coefficients?


Q2.What is meant by recursive function?

3|Page

MLRIT/ ECE

Digital Signal Processing Lab


Exp.No:2

Discrete & Inverse Discrete Fourier Transform


AIM:
To Write a Matlab program for determining DFT and IDFT of the given sequence.
TOOL:
MATLAB Software 9.0
PROGRAM:
%MATLAB program to determine DFT of the sequence and plot magnitude and
%phase response
clf;
xn=input('enter the input sequence:');
N=input('enter the length of sequence:');
% To compute N-point DFT of the sequence xn
L=length(xn);
%Checking for the length of the DFT
if (N<L)
error('N must be >=L');
end;
x1=[xn zeros(1,N-L)];%Appending zeros
%Computation of TWIDDLE FACTORS
for k=0:1:N-1;
for n=0:1:N-1
p=exp(-1i*2*pi*n*k/N);
x2(k+1,n+1)=p;
end
end
xk=x1*x2;
magxk=abs(xk);
k=0:N-1;
subplot(2,1,1);
stem(k,magxk);
grid;
title('MAGNITUDE RESPONSE');
xlabel('time index, k');
ylabel('Magnitude in dB');
angxk=angle(xk);
subplot(2,1,2);
stem(k,angxk);
grid;
title('PHASE RESPONSE');
xlabel('time index, k');
4|Page

MLRIT/ ECE

Digital Signal Processing Lab

ylabel('Phase angle in radians');


Digtal Signal Processing Lab
INPUTS:
enter the input sequence:[1 1 1 1]
enter the length of sequence:50

OUTPUT WAVEFORMS:

Write a MATLAB program for determining IDFT of the given sequence.

%MATLAB program to determine IDFT of the sequence and plot magnitude and phase response
clf;
xk=input('enter the input sequence:');
N=length(xk);
%Computation of TWIDDLE FACTORS
for n=0:1:N-1;
for k=0:1:N-1
p=exp(1i*2*pi*n*k/N);
x(k+1,n+1)=p;
end
end
xn=(xk*x)/N;
5|Page

MLRIT/ ECE

Digital Signal Processing Lab

magxn=abs(xn);
n=0:N-1;
subplot(2,1,1);
stem(n,magxn);
grid;
title('MAGNITUDE RESPONSE');
xlabel('time index, k');
ylabel('Magnitude in dB');
angxn=angle(xn);
subplot(2,1,2);
stem(n,angxn);
grid;
title('PHASE RESPONSE');
xlabel('time index, k');
ylabel('Phase angle in radians');
disp(xn);
INPUTS:
enter the input sequence:[4 1+i 0 1-i 0 1+i 0 1-i]

OUTPUT WAVEFORMS:

6|Page

MLRIT/ ECE

Digital Signal Processing Lab

Q1.Would the result is affected if an arbitrary number of zeros were appended to the original
sequence prior to convolution?

7|Page

MLRIT/ ECE

Digital Signal Processing Lab

Exp.No:3

Frequency Response
AIM:
To Write a Matlab program to plot the frequency response (magnitude and phase
1
1
response) of a given difference equation as a below y (n) y (n 1) y (n 2) x(n) .
6
6
.
TOOL:
MATLAB Software 9.0

PROGRAM:
%MATLAB program to plot the frequency response (magnitude and phase response)
%of a given difference equation.
clf;
clear all;
b=input('Enter the numerator coefficients:');
a=input('Enter the denominator coefficients:');
[h,ph]=freqz(b,a);
subplot(2,1,1);
plot(ph/pi,abs(h));
grid;
xlabel('Normalised Frequency');
ylabel('Magnitude in dB');
title('Magnitude Response');
subplot(2,1,2);
plot(ph/pi,angle(h));
grid;
xlabel('Normalised Frequency');
ylabel('phase in radians');
title('Phase Response');

INPUTS:
Enter the numerator coefficients: [1]
Enter the denominator coefficients: [1 -1/6 -1/6]

8|Page

MLRIT/ ECE

Digital Signal Processing Lab

OUTPUT WAVEFORMS:

Q1.Determine the dc gain and half-power bandwidth from the magnitude plot.
Q2. Determine the frequency response of an LTI system?

9|Page

MLRIT/ ECE

Digital Signal Processing Lab


Exp.No:4

Fast Fourier Transform


AIM:
To Write a Matlab program for determining FFT of the given Sequence.
TOOL:
MATLAB Software 9.0
PROGRAM:
clear all;
N=8; m=8;
a=input('Enter the input sequence:');
n=0:1:N-1;
subplot(2,2,1);
stem(n,a);
xlabel('Time Index n');
ylabel('Amplitude');
title('Input Sequence');
x=fft(a,m);
k=0:1:N-1;
subplot(2,2,2);
stem(k,abs(x));
ylabel('magnitude');
xlabel('Frequency Index K');
title('Magnitude of the FFT sample');
subplot(2,2,3);
stem(k,angle(x));
xlabel('Frequency Index K');
ylabel('Phase');
title('Phase of FFT sample');

INPUT:
Enter the input sequence:[1 1 1 1 0 0 0 0]

10 | P a g e

MLRIT/ ECE

Digital Signal Processing Lab

OUTPUT WAVEFORMS:

Q1.Distinguish between DFT and FFT?


Q2.How many multiplications and additions are required to compute N-point DFT using radix-2
FFT?
Q3.Find DFT of the sequence x(n)={1,2,3,0} using DIF algorithm?

11 | P a g e

MLRIT/ ECE

Digital Signal Processing Lab


EXP.NO:5

Power Spectrum
AIM:
To obtain power spectrum of given signal using MATLAB.
TOOL:
MATLAB Software 9.0

PROGRAM:
%Power spectral density
t = 0:0.001:0.6;
x =sin(2*pi*50*t)+sin(2*pi*120*t);
y = x + 2*randn(size(t));
subplot(2,1,1);
plot(1000*t(1:50),y(1:50));
grid;
title('Signal Corrupted with Zero-Mean Random Noise')
xlabel('time (milliseconds)');
ylabel('amplitude')
Y = fft(y,512);
%The power spectral density, a measurement of the energy at various frequencies, is:
Pyy = Y.* conj(Y) / 512; f = 1000*(0:256)/512;
subplot(2,1,2);
plot(f,Pyy(1:257));
grid;
title('Frequency content of y');
xlabel('frequency (Hz)');
ylabel('amplitude')

12 | P a g e

MLRIT/ ECE

Digital Signal Processing Lab

OUTPUT WAVFORMS:

Q.Define power spectrum density?

13 | P a g e

MLRIT/ ECE

Digital Signal Processing Lab


EXP.NO:6

Fir Low pass Filter


AIM:
To Write a Matlab program of FIR Low pass filter using rectangular, Hanning Hamming,
Blackman and Kaiser window.
.
TOOL:
MATLAB Software 9.0

PROGRAM:
%MATLAB program of FIR Low pass filter using Hanning
%Hamming, Blackman and Kaiser window
clf;
wc=.5*pi;
N=25;
w=0:0.1:pi;
b=fir1(N,wc/pi,blackman(N+1));
h=freqz(b,1,w);
subplot(3,2,1)
plot(w/pi,abs(h))
grid;xlabel('normalised frequency');
ylabel('magnitude in dB')
title('FIR LPF USING BLACKMAN WINDOW')
b=fir1(N,wc/pi,hamming(N+1));
h=freqz(b,1,w);
subplot(3,2,2)
plot(w/pi,abs(h));
grid;
xlabel('normalised frequency');
ylabel('magnitude in dB')
title('FIR LPF USING HAMMING WINDOW')
b=fir1(N,wc/pi,hanning(N+1));
h=freqz(b,1,w);
subplot(3,2,3)
plot(w/pi,abs(h));
grid;
xlabel('normalised frequency');
ylabel('magnitude in dB')
title('FIR LPF USING HANNING WINDOW')
b=fir1(N,wc/pi,kaiser(N+1,3.5));
h=freqz(b,1,w);
subplot(3,2,4)
14 | P a g e

MLRIT/ ECE

Digital Signal Processing Lab

plot(w/pi,abs(h));
grid;
xlabel('normalised frequency');
ylabel('magnitude in dB')
title('FIR LPF USING KAISER WINDOW')

OUTPUT WAVEFORMS:

Q1.Indicate what frequencies you would consider as low frequencies. Does this system
approximate a low pass or band pass etc. filter?
Q2.What is the 3db bandwidth?

15 | P a g e

MLRIT/ ECE

Digital Signal Processing Lab


EXP.NO:7

Fir High pass Filter


AIM:
To Write a Matlab program of FIR High pass filter using rectangular, triangular and
Kaiser Window.
.
TOOL:
MATLAB Software 9.0

PROGRAM:
%FIR Filter design window techniques
clc;
clear all;
close all;
rp=input('enter passband ripple');
rs=input('enter the stopband ripple');
fp=input('enter passband freq');
fs=input('enter stopband freq');
f=input('enter sampling freq ');
beta=input('enter beta value');
wp=2*fp/f; ws=2*fs/f;
num=-20*log10(sqrt(rp*rs))-13;
dem=14.6*(fs-fp)/f;
n=ceil(num/dem);
n1=n+1; if(rem(n,2)~=0) n1=n; n=n-1;
end
c=input('enter your choice of window function 1. rectangular 2. triangular 3.kaiser: \n ');
if(c==1) y=rectwin(n1);
disp('Rectangular window filter response');
end
if (c==2) y=triang(n1);
disp('Triangular window filter response');
end
if(c==3) y=kaiser(n1,beta);
disp('kaiser window filter response');
end
%HPF
b=fir1(n,wp,'high',y);
[h,o]=freqz(b,1,256);
m=20*log10(abs(h));
plot(o/pi,m);
16 | P a g e

MLRIT/ ECE

Digital Signal Processing Lab

title('HPF');
ylabel('Gain in dB-->');
xlabel('(b) Normalized frequency-->');

INPUT:
enter passband ripple:0.02
enter the stopband ripple:0.01
enter passband freq:1000
enter stopband freq:1500
enter sampling freq: 10000
enter beta value:5
OUTPUT WAVEFORM:
enter your choice of window function 1. rectangular 2. triangular 3.kaiser:
2
Triangular window filter response

Q1.What is window and why it is necessary?


Q2. What are the different types of filters based on impulse response?

17 | P a g e

MLRIT/ ECE

Digital Signal Processing Lab

enter your choice of window function 1. rectangular 2. triangular 3.kaiser:


1
Rectangular window filter response

Q1.What do you understand by linear phase response?


Q2.Compare hamming window and Kaiser Window?

18 | P a g e

MLRIT/ ECE

Digital Signal Processing Lab

enter your choice of window function 1. rectangular 2. triangular 3.kaiser:


3
kaiser window filter response

Q1.What is meant by Gibbs phenomenon? Where we found such type of effects in FIR filters?
Q2. Compare the window techniques from above figure?

19 | P a g e

MLRIT/ ECE

Digital Signal Processing Lab

EXP.NO:8

IIR LOWPASS FILTER


AIM:
To Design a Butterworth low pass filter for the given specifications using Matlab.
TOOL:
MATLAB Software 9.0

PROGRAM:
clf;
alphap=input('enter pass attenuation in db=');%passband attenuation in db
alphas=input('enter stopband attenuation in db=');% stopband attenuation in db
fp=input('enter passband frequency in hz='); % passband frequency in hz
fs=input('enter stopband frequency in hz='); % stopband frequency in hz
F=input('enter sampling frequency in hz='); % sampling frequency in hz
omp=2*fp/F; %frequency in radians
oms=2*fs/F;
%to find cutoff frequency and order of the filter
[n,wn]=buttord(omp,oms,alphap,alphas);
%system function of the filter
[b,a]=butter(n,wn);
w=0:0.01:pi;
[h,om]=freqz(b,a,w,'whole');
m=20*log10(abs(h));
an=angle(h);
subplot(1,2,1);
plot(om/pi,m);
grid;
xlabel('normalised frequency');
ylabel('gain in db');
title('magnitude response');
subplot(1,2,2);
plot(om/pi,an);
grid;
xlabel('normalised frequency');
ylabel('phase in radians');
title('phase response');
disp(b);
disp(a);

20 | P a g e

MLRIT/ ECE

Digital Signal Processing Lab

INPUTS:
enter pass attenuation in db=.4
enter stopband attenuation in db=30
enter passband frequency in hz=400
enter stopband frequency in hz=800
enter sampling frequency in hz=2000

OUTPUT WAVEFORM:

B=0.1518 0.6073 0.9109 0.6073 0.1518


A=1.0000 0.6418 0.6165 0.1449 0.0259
Q1.indicate what frequencies you would consider as low frequencies. Does this system
approximate a low or band pass etc. filter?
Q2. Indicate if the phase is linear or nonlinear?

21 | P a g e

MLRIT/ ECE

Digital Signal Processing Lab

(b) To Design a Butterworth Band stop filter for the given specifications using Matlab.
%To design a Butterworth Band stop filter for the given specifications
clf;
alphap=input('enter pass attenuation in db=');%passband attenuation in db
alphas=input('enter stopband attenuation in db=');% stopband attenuation in db
wp=[.1*pi .5*pi]; % passband frequency in rad
ws=[.2*pi .4*pi]; % stopband frequency in rad
%to find cutoff frequency and order of the filter
[n,wn]=buttord(wp/pi,ws/pi,alphap,alphas);
%system function of the filter
[b,a]=butter(n,wn,'stop');
w=0.1:0.01:pi;
[h,ph]=freqz(b,a,w);
m=20*log10(abs(h));
an=angle(h);
subplot(1,2,1);
plot(ph/pi,m);
grid;
xlabel('normalised frequency');
ylabel('gain in db');
title('magnitude response');
subplot(1,2,2);
plot(ph/pi,an);
grid;
xlabel('normalised frequency');
ylabel('phase in rad');
title('phase response');
disp(b);
disp(a);
INPUTS:
enter pass attenuation in db=2
enter stopband attenuation in db=20

22 | P a g e

MLRIT/ ECE

Digital Signal Processing Lab

OUTPUT WAVEFORMS:

B= 0.2348 -1.1611 3.0921 -5.2573 6.2629 -5.2573 3.0921 -1.1611 0.2348


A= 1.0000 -3.2803 5.4917 -6.1419 5.0690 -3.0524 1.3002 -0.3622 0.0558

Q. On an approximate basis verify if the output amplitudes of the 2 and 75Hz components agree
with the gain figures.

23 | P a g e

MLRIT/ ECE

Digital Signal Processing Lab

(c) To Design a Chebyshev-I low pass filter for the given specifications using Matlab.
% To design a chebyshev-1 Lowpass filter for the given specifications
clf;
aphap=input('passband attenuation in db='); %passband attenuation in db
alphas=input('stopband attenuation in db=');% stopband attenuation in db
wp=.2*pi;% passband frequency in rad
ws=.3*pi;% stopband frequency in rad
%order and cutoff frequency of the filter
[n,wn]=cheb1ord(wp/pi,ws/pi,alphap,alphas);
%system function of the filter
[b,a]=cheby1(n,alphap,wn);
w=0:0.01:pi;
[h,ph]=freqz(b,a,w);
m=20*log10(abs(h));
an=angle(h);
subplot(1,2,1);
plot(ph/pi,m);
grid;
xlabel('normalised frequency');
ylabel('gain in db');
title('magnitude response');
subplot(1,2,2);
plot(ph/pi,an);
grid;
xlabel('normalised frequency');
ylabel('phase in rad');
title('phase response');
% [b,a]=cheby1(n,alphap,wn)
disp(b);
disp(a);
INPUTS:
passband attenuation in db=1
stopband attenuation in db=15

24 | P a g e

MLRIT/ ECE

Digital Signal Processing Lab

OUTPUT WAVE FORMS:

B=0.0083 0.0248 0.0248 0.0083


A= 1.0000 -2.2800 1.9766 -0.6307
Q1.Give any two properties of Butterworth low pass filter?
Q2.Mention any two procedures for digitizing the transfer function of an analog filter?
Q3.What are the properties that are maintained same in the transfer of analog filter into a digital
filter?

25 | P a g e

MLRIT/ ECE

Digital Signal Processing Lab


EXP.NO:9

IIR HIGHPASS FILTER


AIM:
To Design a Butterworth high pass filter for the given specifications using Matlab

TOOL:
MATLAB Software 9.0

PROGRAM:

a) To Design a Butterworth High pass filter for the given specifications using Matlab.
%To design a Butterworth Highpass filter for the given specifications
clf;
alphap=input('enter pass attenuation in db=');%passband attenuation in db
alphas=input('enter stopband attenuation in db=');% stopband attenuation in db
fp=input('enter passband frequency in hz='); % passband frequency in hz
fs=input('enter stopband frequency in hz='); % stopband frequency in hz
F=input('enter sampling frequency in hz='); % sampling frequency in hz
omp=2*fp/F; %frequency in radians
oms=2*fs/F;
%to find cutoff frequency and order of the filter
[n,wn]=buttord(omp,oms,alphap,alphas);
%system function of the filter
[b,a]=butter(n,wn,'high');
w=0:0.01:pi;
[h,om]=freqz(b,a,w,'whole');
m=20*log10(abs(h));
an=angle(h);
subplot(1,2,1);
plot(om/pi,m);
grid;
xlabel('normalised frequency');
ylabel('gain in db');
title('magnitude response');
subplot(1,2,2);
plot(om/pi,an);
grid;
xlabel('normalised frequency');
ylabel('phase in radians');
title('phase response');
disp(b);
26 | P a g e

MLRIT/ ECE

Digital Signal Processing Lab

disp(a);
INPUTS:
enter pass attenuation in db=.4
enter stopband attenuation in db=30
enter passband frequency in hz=800
enter stopband frequency in hz=400
enter sampling frequency in hz=2000
OUTPUT WAVEFORMS:

B=0.0265 -0.1058 0.1587 -0.1058 0.0265


A= 1.0000 1.2948 1.0206 0.3575 0.0550

Q1.indicate what frequencies you would consider as low frequencies. Does this system
approximate a low or band pass etc. filter?
Q2. Indicate if the phase is linear or nonlinear?

27 | P a g e

MLRIT/ ECE

Digital Signal Processing Lab

b) To Design a Butterworth Band pass filter for the given specifications using Matlab.
%To design a Butterworth Band pass filter for the given specifications
clf;
alphap=input('enter pass attenuation in db=');%passband attenuation in db
alphas=input('enter stopband attenuation in db=');% stopband attenuation in db
wp=[.2*pi .4*pi]; % passband frequency in rad
ws=[.1*pi .5*pi]; % stopband frequency in rad
%to find cutoff frequency and order of the filter
[n,wn]=buttord(wp/pi,ws/pi,alphap,alphas);
%system function of the filter
[b,a]=butter(n,wn);
w=0.1:0.01:pi;
[h,ph]=freqz(b,a,w);
m=20*log10(abs(h));
an=angle(h);
subplot(1,2,1);
plot(ph/pi,m);
grid;
xlabel('normalised frequency');
ylabel('gain in db');
title('magnitude response');
subplot(1,2,2);
plot(ph/pi,an);
grid;
xlabel('normalised frequency');
ylabel('phase in rad');
title('phase response');
disp(b);
disp(a);
INPUTS:
enter pass attenuation in db=2
enter stopband attenuation in db=20

28 | P a g e

MLRIT/ ECE

Digital Signal Processing Lab

OUTPUT WAVE FORMS:

B=0.0060
0 -0.0240
0 0.0359
0 -0.0240
0 0.0060
A=1.0000 -3.8710 7.9699 -10.6417 10.0781 -6.8167 3.2579 -1.0044 0.1670
Q1.indicate what frequencies you would consider as low frequencies. Does this system
approximate a low or band pass etc. filter?
Q2. Indicate if the phase is linear or nonlinear?

29 | P a g e

MLRIT/ ECE

Digital Signal Processing Lab

(c) To Design a Chebyshev-I High pass filter for the given specifications using Matlab.
% To design a chebyshev-1 Hihpass filter for the given specifications
clf;
aphap=input('passband attenuation in db='); %passband attenuation in db
alphas=input('stopband attenuation in db=')% stopband attenuation in db
wp=.3*pi;% passband frequency in rad
ws=.2*pi;% stopband frequency in rad
%order and cutoff frequency of the filter
[n,wn]=cheb1ord(wp/pi,ws/pi,alphap,alphas);
%system function of the filter
[b,a]=cheby1(n,alphap,wn,'high');
w=0:0.01:pi;
[h,ph]=freqz(b,a,w);
m=20*log10(abs(h));
an=angle(h);
subplot(1,2,1);
plot(ph/pi,m);
grid;
xlabel('normalised frequency');
ylabel('gain in db');
title('magnitude response');
subplot(1,2,2);
plot(ph/pi,an);
grid;
xlabel('normalised frequency');
ylabel('phase in rad');
title('phase response');
disp(b);
disp(a);
INPUTS:
passband attenuation in db=1
stopband attenuation in db=15

30 | P a g e

MLRIT/ ECE

Digital Signal Processing Lab

OUTPUT WAVE FORMS:

B=0.2790 -0.8371 0.8371 -0.2790


A=1.0000 -0.7794 0.5677 0.1150

Q1. What is the difference between IIR and FIR filters?


Q2.Mention any two procedures for digitizing the transfer function of an analog filter?
Q3.What are the advantages of bilinear transformation?

31 | P a g e

MLRIT/ ECE

Digital Signal Processing Lab


EXP.NO:10

GENERATION OF SINUSOIDAL SIGNAL THROUGH FILTERING


AIM:
To write Matlab program for Generation of Sinusoidal signal through filtering.

TOOL:
MATLAB Software 9.0

PROGRAM:
% Write a MATLAB program of signal through by filter
R=50;
d=rand(R,1)-0.5;
m=0:1:R-1;
s=10*sin(2*50*m);
x=s+d';
subplot(1,2,1);
plot(m,d,'r-',m,s,'b--',m,x,'g:');
xlabel('time ');
ylabel('amplitude');
title('input signal with radom noise')
legend('r-','d[n]','b--','s[n]','g:','x[n]');
pause
M=input('number of samples=');
b=ones(M,1)/M;
y=filter(b,1,x);
subplot(1,2,2);
plot(m,s,'r-',m,y,'b--');
legend('r-','s[n]','b--','y[n]');
pause
xlabel('time ');
ylabel('amplitude');
title('input signal through filtering')
INPUT:
No.of.samples:3

32 | P a g e

MLRIT/ ECE

Digital Signal Processing Lab

OUTPUT WAVEFORMS:

Q1. What is meant by random noise?


Q2. What are the specifications of digital filter?
Q3.What are the advantages of filtering?

33 | P a g e

MLRIT/ ECE

Digital Signal Processing Lab


EXP.NO:11

GENERATION OF DTMF SIGNALS


AIM:
To Write a Matlab program for Generation of DTMF signals.
TOOL:
MATLAB Software 9.0

About DTMF:

PROGRAM:
close all;clear all
% DTMF tone generator
fs=8000;
t=[0:1:204]/fs;
x=zeros(1,length(t));
x(1)=1;
y852=filter([0 sin(2*pi*852/fs) ],[1 -2*cos(2*pi*852/fs) 1],x);
y1209=filter([0 sin(2*pi*1209/fs) ],[1 -2*cos(2*pi*1209/fs) 1],x);
y7=y852+y1209;
subplot(2,1,1);plot(t,y7);grid
ylabel('y(n) DTMF: number 7');
xlabel('time (second)');
title('signal tone number 7')
Ak=2*abs(fft(y7))/length(y7);Ak(1)=Ak(1)/2;
f=[0:1:(length(y7)-1)/2]*fs/length(y7);
subplot(2,1,2);plot(f,Ak(1:(length(y7)+1)/2));grid
ylabel('Spectrum for y7(n)');
xlabel('frequency (Hz)');
title('absolute value of signal tone number 7')

34 | P a g e

MLRIT/ ECE

Digital Signal Processing Lab

OUTPUT WAVEFORM:

Q1.Why multi tone signal generator is required?


Q2.What are the advantages of multi tone signal generator?
Q3.What are the applications of dual tone signal generator?

35 | P a g e

MLRIT/ ECE

Digital Signal Processing Lab


EXP.NO:12

DECIMATION PROCESS
AIM:
To Write a Matlab program for Down-sampling of a sinusoidal input sequence.
TOOL:
MATLAB Software 9.0

Matlab Functions Used:

The function decimate can be employed to reduce the sampling rate of an input signal vector X
by an integer factor M generating the output signal vector Y and is available with four options:
(i)Y=decimate(X,M) : This function employs an eight-order Type 1 Chebyshev IIR Lowpass
filter by default and filters the input sequence in both directions to ensure zero-phase filtering.
(ii)Y=decimate(X,M,n) : This function utilizes an order-n Type 1 Chebyshev IIR Lowpass filter
where n should be less than 13 to avoid numerical stability.
(iii)Y=decimate(X,M,fir) : This function employs a 30- tap FIR lowpass filter which filters
the input only in the forward direction. The FIR filter is designed with stop edge at /M using the
function fir1 of MATLAB.
(iv)Y=decimate(X,M,N,fir) : This function design and employs a length-N FIR lowpass filter.
PROGRAM:
%MATLAB program of Down-Sampling by an integer factor
clf;
N=input('Enter the length of output sequence=');
M=input('Enter the Down-Sampling factor=');
fo=input('Enter the input signal frequency=');
%Generate the input sinusoidal sequence
n=0:N-1;
m=0:N*M-1;
X=sin(2*pi*fo*m);
%Generate the Down-Sampled sequence
Y=X(1:M:length(X));
%Plot input and Down-Sampled sequences
subplot(2,1,1);
36 | P a g e

MLRIT/ ECE

Digital Signal Processing Lab

stem(n,X(1:N));
title('input sequence');
xlabel('Time Index,n');
ylabel('Amplitude');
subplot(2,1,2);
stem(n,Y);
title(' Down-Sampled sequence');
xlabel('Time Index,n');
ylabel('Amplitude');
INPUTS:
Enter the length of output sequence=50
Enter the Down-Sampling factor=3
Enter the input signal frequency=0.042

OUTPUT WAVEFORM:

Q1.What is meant by down sampling?


Q2.What is meant by Y=decimate(X,M,n) in matlab?
Q3.What is meant by Y=decimate (X,M,N,fir) in matlab?
37 | P a g e

MLRIT/ ECE

Digital Signal Processing Lab

(b) .Write a Matlab program of decimation of a sum of sinusoidal sequences of normalized


frequencies f1 and f2 by an arbitrary down-sampling factor M.
%MATLAB program of decimation process
clf;
N=input('Enter the length of input sequence=');
M=input('Enter the Down-Sampling factor=');
f1=input('Enter the input signal frequency of first sinusoid=');
f2=input('Enter the input signal frequency of second sinusoid=');
%Generate the input sinusoidal sequence
n=0:N-1;
X=sin(2*pi*f1*n)+sin(2*pi*f2*n);
%Generate the Decimated output sequence
Y = decimate(X,M,'fir');
%Plot input and Decimated output sequences
subplot(2,1,1);
stem(n,X(1:N));
title('input sequence');
xlabel('Time Index,n');
ylabel('Amplitude');
subplot(2,1,2);
m=0:N/M-1;
stem(m,Y(1:N/M));
title(' Decimated output sequence');
xlabel('Time Index,n');ylabel('Amplitude');

INPUTS:
Enter the length of input sequence=100
Enter the Down-Sampling factor=2
Enter the input signal frequency of first sinusiod=0.043
Enter the input signal frequency of second sinusiod=0.031

38 | P a g e

MLRIT/ ECE

Digital Signal Processing Lab

OUTPUT WAVEFORM:

Q1.What is meant by aliasing effect?


Q2.What is meant by Y=decimate(X,M) in matlab?
Q3.What are the uses of decimation process?
Q4.What are the applications of decimation process?

39 | P a g e

MLRIT/ ECE

Digital Signal Processing Lab


EXP.NO:13

INTERPOLATION PROCESS
AIM:
To Write a Matlab program for Up-sampling of a sinusoidal input sequence.
TOOL:
MATLAB Software 9.0

Matlab Functions Used:


The signal processing toolbox of MATLAB includes three specific functions for sampling rate
alteration.These are decimate ,interp and resample.
The function interp can be employed to increase the sampling rate of an input signal vector X
by an integer factor L generating the output signal vector Y. It is available with three options.
(i). Y = interp(X,L): In this function the default values of and N are respectively, 0.5 and 4.
(ii). Y = interp(X,L,N,alpha): In this function the bandedge of the input signal and length
N of the interpolation filter can be specified.
(iii). [Y,h] = interp(X,L,N,alpha): In this function the bandedge of the input signal and
length N of the interpolation filter can be specified. Also, In this function the output data
contains in addition to the interpolated output vector Y, the filter coefficients h.
PROGRAM:
%MATLAB program of Up-Sampling by an integer factor
clf;
N=input('Enter the length of input sequence=');
L=input('Enter the Up-Sampling factor=');
fo=input('Enter the input signal frequency=');
%Generate the input sinusoidal sequence
n=0:N-1;
X=sin(2*pi*fo*n);
%Generate the Up-Sampled sequence
Y=zeros(1,L*length(X));
Y([1:L:length(Y)])=X;
%Plot input and Up-Sampled sequences
subplot(2,1,1);
stem(n,X);
title('input sequence');
40 | P a g e

MLRIT/ ECE

Digital Signal Processing Lab

xlabel('Time Index,n');
ylabel('Amplitude');
subplot(2,1,2);
stem(n,Y(1:length(X)));
title(' Up-Sampled sequence');
xlabel('Time Index,n');
ylabel('Amplitude');

INPUTS:
Enter the length of input sequence=50
Enter the Up-Sampling factor=10
Enter the input signal frequency100

OUTPUT WAVEFORMS:

Q1.What is meant by Y = interp(X,L) in matlab?


Q2.What are the applications of interpolation process?

41 | P a g e

MLRIT/ ECE

Digital Signal Processing Lab

(b). Write a Matlab program of interpolation of a sum of sinusoidal sequences of


normalized frequencies f1 and f2 by an arbitrary interpolating factor L.
%MATLAB program of interpolation process
clf;
N=input('Enter the length of input sequence=');
L=input('Enter the Up-Sampling factor=');
f1=input('Enter the input signal frequency of first sinusiod');
f2=input('Enter the input signal frequency of second sinusiod');
%Generate the input sinusoidal sequence
n=0:N-1;
X=sin(2*pi*f1*n)+sin(2*pi*f2*n);
%Generate the interpolated output sequence
Y = interp(X,L);
%Plot input and interpolated output sequences
subplot(2,1,1);
stem(n,X(1:N));
title('input sequence');
xlabel('Time Index,n');
ylabel('Amplitude');
subplot(2,1,2);
m=0:N*L-1;
stem(m,Y(1:N*L));
title(' interpolated output sequence');
xlabel('Time Index,n');
ylabel('Amplitude');

INPUT:
Enter the length of input sequence=50
Enter the Down-Sampling factor=2
Enter the input signal frequency of first sinusiod=0.043
Enter the input signal frequency of second sinusiod=0.031

42 | P a g e

MLRIT/ ECE

Digital Signal Processing Lab

OUTPUTWAVEFORMS:

Q1.What is meant by up- sampling?


Q2.What is meant by Y = interp(X,L,N,alpha) in matlab?
Q3.What is meant by [Y,h] = interp(X,L,N,alpha) in matlab?

43 | P a g e

MLRIT/ ECE

Digital Signal Processing Lab


EXP.NO:14

INTERPOLATION/DECIMATION SAMPLING RATE CONVERTERS


AIM:
To Write a MATLAB program of the sampling rate increase by a ratio of two positive
integers of a signal composed of two sinusoids with frequencies f1 and f2.

TOOL:
MATLAB Software 9.0

Matlab Functions Used:


The function resample in MATLAB can be utilized to increase the sampling rate of an input
vector X by a ratio of two positive integers, L/M, generating an output vector Y. There are five
functions available with this resample function.
(i). Y = resample(X, L, M)
(ii). Y = resample(X, L,M,R)
(iii). Y = resample(X, L,M,R,beta)
(iv). Y = resample(X,L,M,h)
(v).[ Y,h] = resample(X,L,M)

PROGRAM:
%MATLAB program of sampling rate alteration by a ratio of two integers
clf;
N=input('Enter the length of input sequence=');
L=input('Enter the Up-Sampling factor=');
M=input('Enter the Down-Sampling factor=');
f1=input('Enter the input signal frequency of first sinusiod');
f2=input('Enter the input signal frequency of second sinusiod');
%Generate the input sinusoidal sequence
n=0:N-1;
X=sin(2*pi*f1*n)+sin(2*pi*f2*n);
%Generate the Resampled output sequence
Y = resample(X,L,M);
44 | P a g e

MLRIT/ ECE

Digital Signal Processing Lab

%Plot input and Resampled output sequences


subplot(2,1,1);
stem(n,X(1:N));
title('input sequence');
xlabel('Time Index,n');
ylabel('Amplitude');
subplot(2,1,2);
m=0:N*L-1;
stem(m,Y(1:N*L/M));
title(' resampled output sequence');
xlabel('Time Index,n');ylabel('Amplitude');
INPUTS:
Enter the length of input sequence=50
Enter the Up-Sampling factor=10
Enter the Down-Sampling factor=5
Enter the input signal frequency of first sinusiod0.043
Enter the input signal frequency of second sinusiod0.031

OUTPUT WAVEFORMS:

Q1.What is the use of sampling rate converters?


Q2.What is meant by Y = resample(X, L, M) in matlab?
Q3.What is meant by resampling process?
45 | P a g e

MLRIT/ ECE

Digital Signal Processing Lab


EXP.NO:15

IMPULSE RESPONSE OF THE SYSTEM


AIM:
To find the impulse response of first order system by using MATLAB.
TOOL:
MATLAB Software 9.0
PROGRAM:
close all;
clear all;
n=0:10;
b=[1 0 0];
a=[1 -0.6 0];
y=dimpulse(b,a,length(n));
subplot(2,2,1);
stem(n,y);
xlabel('t');
ylabel('a');
title('impulse response of first order system');
w=abs(y);
subplot(2,2,2);
stem(n,w);
xlabel('t');
ylabel('a');
title('magnitude response');
x=angle(y);
subplot(2,2,3);
stem(n,x);
xlabel('t');
ylabel('a');
title ('phase response');

46 | P a g e

MLRIT/ ECE

Digital Signal Processing Lab

OUTPUT WAVEFORMS:

Q1.What are the properties of convolution?


Q2.What are uses of impulse response of a system?

47 | P a g e

MLRIT/ ECE

Digital Signal Processing Lab

(b) . To find the impulse response of second order system by using Matlab.
close all;
clear all;
n=0:10;
b=[1 0 0];
a=[1 -0.6 0.08];
y=dimpulse(b,a,length(n));
subplot(2,2,1);
stem(n,y);
xlabel('t');
ylabel('a');
title('impulse response of second order system');
w=abs(y);
subplot(2,2,2);
stem(n,w);
xlabel('t');
ylabel('a');
title('magnitude response');
x=angle(y);
subplot(2,2,3);
stem(n,x);
xlabel('t');
ylabel('a');
title ('phase response');
OUTPUT WAVEFORMS:

Q. What is meant by impulse response of a system?


48 | P a g e

MLRIT/ ECE

Digital Signal Processing Lab


PART II
EXP.NO:1

LINEAR CONVOLUTION
AIM:
TO write a C- program to find linear convolution of given two sequences.

EQUIPMENT REQUIRED:
System
Power supply
Windows XP
Core 2 Dua l Processor
MATLAB 7.8 VERSION
Procedure to work on code composer studio:
To create the New Project
Project New (File Name. pjt, Eg: Vectors.pjt)
To create a Source file
File New Type the code (Save & give file name, Eg: sum.c).
To Add Source files to Project
Project Add files to Project sum.c
To Add rts.lib file & Hello.cmd:
Project Add files to Project rts6700.lib
Library files: rts6700.lib (Path: c:\ti\c6000\cgtools\lib\ rts6700.lib)
Note: Select Object& Library in (*.o,*.l) in Type of files
Project Add files to Projecthello.cmd
CMD file- Which is common for all non real time programs.
(Path: c:\ti \ tutorial\dsk6713\hello1\hello.cmd)

49 | P a g e

MLRIT/ ECE

Digital Signal Processing Lab

Note: Select Linker Command file (*.cmd) in Type of files


Compile:
To Compile: Project Compile
To Rebuild: project rebuild,
Which will create the final .out executable file. (Eg.Vectors.out).
Procedure to Lode and Run program:
Load the Program to DSK: File Load program Vectors.out
To Execute project: Debug Run

PROGRAM:

#include<stdio.h>
int m=6;
int n=6;
int i=0,j;
int x[15]={1,2,3,4,5,6,0,0,0,0,0,0};
int h[15]={1,2,3,4,5,6,0,0,0,0,0,0};
int y[20];
main()
{
for(i=0;i<m+n-1;i++)
{
y[i]=0;
for(j=0;j<=i;j++)

y[i]+=x[j]*h[i-j];
}
for(i=0;i<m+n-1;i++)
printf("%d \n",y[i]);
}

50 | P a g e

MLRIT/ ECE

Digital Signal Processing Lab

RESULTS: Thus the C- Program for Linear convolution was written and the output was
verified.
OUTPUT:
4
10
20
35
56
70
76
73
60
36

51 | P a g e

MLRIT/ ECE

Digital Signal Processing Lab

52 | P a g e

MLRIT/ ECE

Digital Signal Processing Lab

VIVA QUESTIONS:
1. What is the requirement for the convolution?
2. What is the difference between convolution & Correction?
3. What is meant by Impulse response?
4. Is it possible to represent any discreet time signal in terms of impulses? If yes represent by
using Example?
5. What is the difference between continues & Discrete convolution?
6. Write the expression for LIF System convolution formula & causal LIF system Conv.
Formula?
7. What is the length of linear convolution if lengths of Input & Impulse responses are N1 &
N2 respectively?

53 | P a g e

MLRIT/ ECE

Digital Signal Processing Lab


EXP.NO:2

CIRCULAR CONVOLUTION
AIM:
TO write a C- program to find Circular convolution of given two sequences

EQUIPMENT REQUIRED:
System
Power supply
Windows XP
Core 2 Dua l Processor
MATLAB 7.8 VERSION
Procedure to Work on Code Composer Studio:
To create the New Project
Project New (File Name. pjt, Eg: Vectors.pjt)
To create a Source file
File New Type the code (Save & give file name, Eg: sum.c).
To Add Source files to Project
Project Add files to Project sum.c
To Add rts.lib file & Hello.cmd:
Project Add files to Project rts6700.lib
Library files: rts6700.lib (Path: c:\ti\c6000\cgtools\lib\ rts6700.lib)
Note: Select Object& Library in (*.o,*.l) in Type of files
Project Add files to Projecthello.cmd
CMD file- Which is common for all non real time programs.
(Path: c:\ti \ tutorial\dsk6713\hello1\hello.cmd)

54 | P a g e

MLRIT/ ECE

Digital Signal Processing Lab

Note: Select Linker Command file (*.cmd) in Type of files


Compile:
To Compile: Project Compile
To Rebuild: project rebuild,
Which will create the final .out executable file. (Eg.Vectors.out).
Procedure to Lode and Run program:
Load the Program to DSK: File Load program Vectors.out
To Execute project: Debug Run

PROGRAM:

#include<stdio.h>
int m,n,x[30],h[30],y[30],i,j,temp[30],k,x2[30],a[30];
void main()
{
printf("enter the length of the 1st sequence\n");
scanf("%d",&m);
printf("enter the length of the second sequence\n");
scanf("%d",&n);
printf("enter the 1st sequence\n");
for(i=0;i<m;i++)
scanf("%d",&x[i]);
printf("enter the second sequence\n");
for(j=0;j<n;j++)
scanf("%d",&h[j]);
if(m-n!=0)
{
if(m>n)
{
for(i=n;i<m;i++)
h[i]=0;
n=m;
}
for(i=m;i<n;i++)
x[i]=0;
55 | P a g e

MLRIT/ ECE

Digital Signal Processing Lab

m=n;
}
y[0]=0;
a[0]=h[0];
for(j=1;j<n;j++)
a[j]=h[n-j];
for(i=0;i<n;i++)
y[0]+=x[i]*a[i];
for(k=1;k<n;k++)
{
y[k]=0;
for(j=1;j<n;j++)
x2[j]=a[j-1];
x2[0]=a[n-1];
for(i=0;i<n;i++)
{
a[i]=x2[i];
y[k]+=x[i]*x2[i];
}
}
printf("the circular convolution is\n");
for(i=0;i<n;i++)
printf("%d\t",y[i]);
}
INPUT:
enter the length of the 1st sequence
5
enter the length of the second sequence
5
enter the 1st sequence
1
2
3
4
5
enter the second sequence
56 | P a g e

MLRIT/ ECE

Digital Signal Processing Lab

1
2
3
4
5
OUTPUT:
the circular convolution is
45

50

50

45

35

57 | P a g e

MLRIT/ ECE

Digital Signal Processing Lab

RESULTS: Thus the C- Program for Circular convolution was written and the output was
verified.
58 | P a g e

MLRIT/ ECE

Digital Signal Processing Lab

VIVA QUESTIONS
1. Why we need circular convolution
2. What is the difference between Circular and Linear Convolution
3. What is the length of output Sequence after circular convolution if the lengths of input
impulse responses are M1 and M2 respectively
4. State the circular convolution property of discrete Fourier transformer
5. Where we require convolution property
6. What is zero padding, where we require zero padding concept
7. What is the difference between linear shifting and circular shifting of a signal, show with
example?
8. What is the difference between linear and circular folding of signal show with example.

59 | P a g e

MLRIT/ ECE

Digital Signal Processing Lab

FAST FOURIER TRANSFORM


AIM:
To write a C- program to compute 8 FFT of given sequences using DIF FFT
algorithm.

EQUIPMENT REQUIRED:
System
Power supply
Windows XP
Core 2 Dua l Processor
MATLAB 7.8 VERSION
Procedure to Work on Code Composer Studio
To create the New Project
Project New (File Name. pjt, Eg: Vectors.pjt)
To create a Source file
File New Type the code (Save & give file name, Eg: sum.c).
To Add Source files to Project
Project Add files to Project sum.c
To Add rts.lib file & Hello.cmd:
Project Add files to Project rts6700.lib
Library files: rts6700.lib (Path: c:\ti\c6000\cgtools\lib\ rts6700.lib)
Note: Select Object& Library in (*.o,*.l) in Type of files
Project Add files to Projecthello.cmd
CMD file- Which is common for all non real time programs.
(Path: c:\ti \ tutorial\dsk6713\hello1\hello.cmd)
Note: Select Linker Command file (*.cmd) in Type of files

60 | P a g e

MLRIT/ ECE

Digital Signal Processing Lab

Compile:
To Compile: Project Compile
To Rebuild: project rebuild,
Which will create the final .out executable file. (Eg.Vectors.out).
Procedure to Lode and Run program:
Load the Program to DSK: File Load program Vectors.out
To Execute project: Debug Run

PROGRAM:

#include<stdio.h>
#include<math.h>
#define N 8
#define PI 3.14159
typedef struct
{
float real,imag;
}
complex;
main()
{
int i;
complex w[N];
complex x[8]={0,0.0,1,0.0,2,0.0,3,0.0,4,0.0,5,0.0,6,0.0,7,0.0};
complex temp1,temp2;
int j,k,upper_leg,lower_leg,leg_diff,index,step;
for(i=0;i<N;i++)
{
w[i].real=cos((2*PI*i)/(N*2.0));
w[i].imag=-sin((2*PI*i)/(N*2.0));
}
leg_diff=N/2;
step=2;
for(i=0;i<3;i++)
61 | P a g e

MLRIT/ ECE

Digital Signal Processing Lab

{
index=0;
for(j=0;j<leg_diff;j++)
{
for(upper_leg=j;upper_leg<N;upper_leg+=(2*leg_diff))
{
lower_leg=upper_leg+leg_diff;
temp1.real=(x[upper_leg]).real+(x[lower_leg]).real;
temp1.imag=(x[upper_leg]).imag+(x[lower_leg]).imag;
temp2.real=(x[upper_leg]).real-(x[lower_leg]).real;
temp2.imag=(x[upper_leg]).imag-(x[lower_leg]).imag;
(x[lower_leg]).real=temp2.real*(w[index]).real-temp2.imag*(w[index]).imag;
(x[lower_leg]).imag=temp2.real*(w[index]).imag+temp2.imag*( w[index]).real;
(x[upper_leg]).real=temp1.real;
(x[upper_leg]).imag=temp1.imag;
}
index+=step;
}
leg_diff=(leg_diff)/2;
step=step*2;
}
j=0;
for(i=1;i<(N-1);i++)
{
k=N/2;
while(k<=j)
{
j=j-k;
k=k/2;
}
j=j+k;
if(i<j)
{
temp1.real=(x[j]).real;
temp1.imag=(x[j]).imag;
(x[j]).real=(x[i]).real;
(x[j]).imag=(x[i]).imag;
(x[i]).real=temp1.real;
(x[i]).imag=temp1.imag;
62 | P a g e

MLRIT/ ECE

Digital Signal Processing Lab

}
}
printf("the fft of the given input sequence is \n");
for(i=0;i<8;i++)
{
printf("%f %f \n",(x[i]).real,(x[i]).imag);
}
}
OUTPUT:
the fft of the given input sequence is:
28.000000 0.000000
-4.000012 9.656858
-4.000005 4.000000
-4.000010 1.656851
-4.000000 0.000000
-3.999998 -1.656858
-3.999995 -4.000000
-3.999980 -9.656851

63 | P a g e

MLRIT/ ECE

Digital Signal Processing Lab


FFT 1-D

AIM:
TO write a C- program to compute FFT of the given 1- D signal and plot.
EQUIPMENT REQUIRED:
System
Power supply
Windows XP
Core 2 Dua l Processor
MATLAB 7.8 VERSION
ALGORITHM:
1.
2.
3.
4.
5.

Select no. of points for FFT


Generate a sine wave of frequency f.
Take sampled data and apply FFT algorithm.
Use Graph option to view the input and output.
Repeat step 1to 4 for different no. of points and frequencies.

PROGRAM:

#include<stdio.h>
#include<math.h>
#define N 32
#define PI 3.14159
typedef struct
{
float real,imag;
}
complex;
float iobuffer[N];
float y[N];
main()
{
int i;
complex w[N];
complex x[N];
complex temp1,temp2;
int j,k,upper_leg,lower_leg,leg_diff,index,step;
for(i=0;i<N;i++)
64 | P a g e

MLRIT/ ECE

Digital Signal Processing Lab

{
iobuffer[i]=sin((2*PI*2*i)/32.0);
}
for(i=0;i<N;i++)
{
x[i].real=iobuffer[i];
x[i].imag=0.0;
}
for(i=0;i<N;i++)
{
w[i].real=cos((2*PI*i)/(N*2.0));
w[i].imag=-sin((2*PI*i)/(N*2.0));
}
leg_diff=N/2;
step=2;
for(i=0;i<5;i++)
{
index=0;
for(j=0;j<leg_diff;j++)
{
for(upper_leg=j;upper_leg<N;upper_leg+=(2*leg_diff))
{
lower_leg=upper_leg+leg_diff;
temp1.real=(x[upper_leg]).real+(x[lower_leg]).real;
temp1.imag=(x[upper_leg]).imag+(x[lower_leg]).imag;
temp2.real=(x[upper_leg]).real-(x[lower_leg]).real;
temp2.imag=(x[upper_leg]).imag-(x[lower_leg]).imag;
(x[lower_leg]).real=temp2.real*(w[index]).realtemp2.imag*(w[index]).imag;
(x[lower_leg]).imag=temp2.real*(w[index]).imag+temp2.imag*(w[index]).real;
(x[upper_leg]).real=temp1.real;
(x[upper_leg]).imag=temp1.imag;
}
index+=step;
}
leg_diff=(leg_diff)/2;
step=step*2;
}
j=0;
for(i=1;i<(N-1);i++)
65 | P a g e

MLRIT/ ECE

Digital Signal Processing Lab

{
k=N/2;
while(k<=j)
{
j=j-k;
k=k/2;
}
j=j+k;
if(i<j)
{
temp1.real=(x[j]).real;
temp1.imag=(x[j]).imag;
(x[j]).real=(x[i]).real;
(x[j]).imag=(x[i]).imag;
(x[i]).real=temp1.real;
(x[i]).imag=temp1.imag;
}
}
for(i=0;i<N;i++)
{
y[i]=sqrt((x[i].real*x[i].real)+(x[i].imag*x[i].imag));
}
for(i=0;i<N;i++)
{
printf("%f\t",y[i]);
}
return(0);
}

OUTPUT:

66 | P a g e

MLRIT/ ECE

Digital Signal Processing Lab

67 | P a g e

MLRIT/ ECE

Digital Signal Processing Lab

VIVA QUESTIONS:
1.What is ment by y=[zeros(1,2),ones(1,1) , zeros(1,2) ;?
2.What is meant by subplot(m,n,p)?
3.What do you mean by stem(x,r)?
4.What do you mean by butter(n,wn,'s');
5.What do you mean by grid on?
6.What do you mean by fft?
7.What is difference between dft and fft?

68 | P a g e

MLRIT/ ECE

Digital Signal Processing Lab

POWER DENSITY SPECTRUM


AIM:
TO write a C- program to compute power density spectrum of given one dimensional
signal and plot.

EQUIPMENT REQUIRED:
System
Power supply
Windows XP
Core 2 Dua l Processor
MATLAB 7.8 VERSION
ALGORITHM:
1.
2.
3.
4.
5.
6.

Select no. of points for FFT


Generate a sine wave of frequency f.(Sampling rate = No. of points of FFT)
Compute the Auto Correlation of sine wave.
Take output of auto correlation, apply FFT algorithm.
Use Graph option to the PDS. .
Repeat step 1to 4 for different no. of points and frequencies.

PROGRAM:

#include<stdio.h>
#include<math.h>
#define N 16
#define PI 3.14159
typedef struct
{
float real,imag;
}
complex;
complex x[N];
float iobuffer[N];
float x1[N],y[N];
int i;
69 | P a g e

MLRIT/ ECE

Digital Signal Processing Lab

main()
{
complex w[N];
complex temp1,temp2;
float sum=0.0;
int j,k,n,upper_leg,lower_leg,leg_diff,index,step;
for(i=0;i<N;i++)
{
iobuffer[i]=sin((2*PI*2*i)/15.0);
}
for(n=0;n<N;n++)
{
sum=0;
for(k=0;k<N-n;k++)
{
sum=sum+(iobuffer[k]*iobuffer[n+k]);
}
x1[n]=sum;
}
for(i=0;i<N;i++)
{
x[i].real=x1[i];
x[i].imag=0.0;
}
for(i=0;i<N;i++)
{
w[i].real=cos((2*PI*i)/(N*2.0));
w[i].imag=-sin((2*PI*i)/(N*2.0));
}
leg_diff=N/2;
step=2;
for(i=0;i<4;i++)
{
index=0;
for(j=0;j<leg_diff;j++)
{
for(upper_leg=j;upper_leg<N;upper_leg+=(2*leg_diff))
{
lower_leg=upper_leg+leg_diff;
70 | P a g e

MLRIT/ ECE

Digital Signal Processing Lab

temp1.real=(x[upper_leg]).real+(x[lower_leg]).real;
temp1.imag=(x[upper_leg]).imag+(x[lower_leg]).imag;
temp2.real=(x[upper_leg]).real-(x[lower_leg]).real;
temp2.imag=(x[upper_leg]).imag-(x[lower_leg]).imag;
(x[lower_leg]).real=temp2.real*(w[index]).real-temp2.imag*(w[index]).imag;
(x[lower_leg]).imag=temp2.real*(w[index]).imag+temp2.imag*(w[index]).real;
(x[upper_leg]).real=temp1.real;
(x[upper_leg]).imag=temp1.imag;
}
index+=step;
}
leg_diff=(leg_diff)/2;
step=step*2;
}
j=0;
for(i=1;i<(N-1);i++)
{
k=N/2;
while(k<=j)
{
j=j-k;
k=k/2;
}
j=j+k;
if(i<j)
{
temp1.real=(x[j]).real;
temp1.imag=(x[j]).imag;
(x[j]).real=(x[i]).real;
(x[j]).imag=(x[i]).imag;
(x[i]).real=temp1.real;
(x[i]).imag=temp1.imag;
}
}
for(i=0;i<N;i++)
{
y[i]=sqrt((x[i].real*x[i].real)+(x[i].imag*x[i].imag));
}
for(i=0;i<N;i++)
71 | P a g e

MLRIT/ ECE

Digital Signal Processing Lab

{
printf("%f\t",y[i]);
}
return(0);
}
OUTPUT:

72 | P a g e

MLRIT/ ECE

Digital Signal Processing Lab

73 | P a g e

MLRIT/ ECE

Digital Signal Processing Lab

VIVA QUESTIONS:
1. What is the difference between correlation and auto correlation function
2. What is the difference between power spectrum density and energy spectrum density
3. What is the unit for energy density spectrum
4. What is the formula for Power Spectrum Density of a function
5. Same power density spectrum signals always have same magnitude and Phase
spectrum Is this statement is true or False, justify your answer
6. If we know the impulse response of the system how can you find out signal power
density from the input signal
7. What is the unit for power density spectrum
8. What is the relation between auto correlation and Power spectrum density of function

74 | P a g e

MLRIT/ ECE

Digital Signal Processing Lab

75 | P a g e

You might also like