digital signal processing laboratory
TRANSCRIPT
-
8/12/2019 Digital Signal Processing Laboratory
1/14
DIGITAL SIGNAL PROCESSING LABORATORY
Sub Code : 10ECL57
A LIST OF EXPERIMENTS USING MATLAB/SCILAB/OCTAVE/WAB
1. Verification of sampling theorem.
2. Impulse response of a given system
3. Linear convolution of two given sequences.
4. Circular convolution of two given sequences
5. Autocorrelation of a given sequence and verification of its properties.
6. Cross correlation of given sequences and verification of its properties.
7. Solving a given difference equation.
8. Computation of N point DFT of a given sequence and to plot magnitude
and phase spectrum.
9. Linear convolution of two sequences using DFT and IDFT.
10. Circular convolution of two given sequences using DFT and IDFT
11. Design and implementation of FIR filter to meet given specifications.
12. Design and implementation of IIR filter to meet given specifications.
B. LIST OF EXPERIMENTS USING DSP PROCESSOR
(Note: Experiments no: 1, 2, 3 & 7 may be performed on CCS)
1. Linear convolution of two given sequences.
2. Circular convolution of two given sequences.
3. Computation of N- Point DFT of a given sequence
4. Realization of an FIR filter (any type) to meet given specifications .The
input can be a signal from function generator / speech signal .
5. Audio applications such as to plot time and frequency (Spectrum)
display of Microphone output plus a cosine using DSP. Read a wav file
and match with their respective spectrograms
6. Noise: Add noise above 3kHz and then remove; Interference suppression
using 400 Hz tone.
-
8/12/2019 Digital Signal Processing Laboratory
2/14
7. Impulse response of first order and second order system
REFERENCE BOOKS:
1. Sanjeet Mitra, Digital signal processing using MATLAB, TMH,2001
2. J.G.Proakis & Ingale, Digital signal processing using MATLAB,.MGH, 2000
3. B.Venkataramani and Bhaskar, Digital signal processors,TMH,2002
Experiment 1Verification of Sampling theorem
Aim :To verify sampling theorem.
Theory :
Sampling
The process of obtaining the signal values from the continuous signal at regular tim
intervals is known as sampling. The sampling interval is denoted as Ts and its reciproca
the sampling frequency or sample-rate is denoted as fs, where fs = 1/Ts. The result of th
process is just a sequence of numbers called a discrete time signal and is denoted as x[
where n is the index used to refer to the samples.
Interpolation
We can reconstruct the original continuous signal from its samples by using Interpolatio
Interpolation is the process of guessing signal values at arbitrary instants of time, whic
fall - in general - in between the actual samples. Thereby interpolation creates a continuou
time signal and can be seen as an inverse process to sampling.
Ideally, the continuous signal obtained from interpolation should be equal to the origin
continuous signal. One of the very popular interpolation methods is linear interpolation -
-
8/12/2019 Digital Signal Processing Laboratory
3/14
reconstruct a signal value we simply connect the values at our sampling instants wit
straight lines.
sophisticated interpolation methods such as sinc-interpolation will yield smoother an
more faithful reconstructions than the simple linear interpolation.
Sampling Theorem:
Sampling theorem states that Exact reconstruction of a continuous time signal from its
samples is possible, if the signal is band-limited and the sampling frequency is greater tha
twice the signal bandwidth.
While sampling a signal the sampling frequencyfsmust be greater than twice the
highest frequency componentfmin the signal. iefs>=2fm.This is the Nyquist Sampling
Theorem.
When the above condition is not met, i.e, If the signal is sampled at a frequenc
lesser than twice the highest frequency present in the signal and reconstruct the signal an
way, an odd phenomenon called Aliasing occurs.
The following figure shows a 100Hz signal and is sampled at a sampling rate
80Hz .When the signal is reconstructed from the samples it results in a different sign
with frequency of 20 Hz.Entirely different from the original 100Hz signal !!
Procedure:1)Generate a Sinusoidal Wave of given frequency f
2)Sample the given signal with sampling rate fs.
3)Plot the discrete time signal.
-
8/12/2019 Digital Signal Processing Laboratory
4/14
4)Reconstruct signal by using linear interpolation (plotting the samples).
5)Repeat the steps 1 to 4 for different sampling frequencies.
6) In step 4 use sinc interpolation to reconstruct the signal repeat the procedur
1 to 5.
Program 1.
%**********************************************************************************%To verify smpling theorem
% using linear interpolation Reconstruction.
% This m-file illustrates the effects of aliasing in time domain.
%********************************************************************************************
% Clears Command window/Close all figures/Clear all variables
clc;
close all;
clear all;
%******************************Generate Analog Signal *****************************
t=0:0.001:.3;
xt=sin(2*pi*30*t);
plot(t,xt);
xlabel('t --->');ylabel(' x(t) ----->');title('Analog signal')
disp('Observe analog Signal . To Sample the signal press ENTER')
%*****************************************Sampling**********************************
fs =input('Enter sampling frequency : ')
ts=1/fs;
n=0:ts:.3;
xn=sin(2*pi*30*n);
% ***************************************Plot the discrete sequence**************
hold
stem(n,xn,'r', 'filled')
xlabel('n --->');ylabel(' x(n) ----->');title('Analog signal in BLUE, Smpled Signal in RED')
-
8/12/2019 Digital Signal Processing Laboratory
5/14
disp('TO RECONSTRUCT THE SIGNAL FOM SAMPLES PRESS ENTER ')
pause
% ***************************************Reconstruction of signal**************
plot(n,xn,'g')
title('Analog signal in BLUE , smpled signal in RED ,Reconstructed signal in GREEN')
Sample run Out put :
Observe analog Signal . To Sample the signal press ENTER
Enter sampling frequency : 65
fs =
65
Current plot held
TO RECONSTRUCT THE SIGNAL FOM SAMPLES PRESS ENTER
Compare the reconstructed signal with the original signal.
Program 2.%*************************************************************************************************
-
8/12/2019 Digital Signal Processing Laboratory
6/14
%To verify smpling theorem
% Reconstruction using sinc interpolation.
% This m-file illustrates the effects of aliasing in time domain.
%**************************************************************************************************
Clears Command window/Close all figures/Clear all variables
clc;
close all;
clear all;
%******************************Generate Analog Signal****************************************
t=0:0.001:.3;
xt=sin(2*pi*30*t);
plot(t,xt);
xlabel('t --->');ylabel(' x(t) ----->');title('Analog signal')
disp('Observe analog Signal . To Sample the signal press ENTER')
%*****************************************Sampling******************************************
fs =input( 'Enter sampling frequency')
ts=1/fs;
n=0:ts:.3;
xn=sin(2*pi*30*n);
% ***************************************Plot the discrete sequence**********************
hold
stem(n,xn,'r', 'filled')
xlabel('n --->');ylabel(' x(n) ----->');title('Analog signal in BLUE, Smpled Signal in RED')
disp('TO RECONSTRUCT THE SIGNAL FOM SAMPLES PRESS ENTER ')
pause
% ***************************************Reconstruction of signal**********************
ni=0:0.001:.3;
xr=interp1(n,xn,ni,'sinc');
plot(ni,xr,'g')
-
8/12/2019 Digital Signal Processing Laboratory
7/14
title('Analog signal in BLUE , smpled signal in RED ,Reconstructed signal in GREEN')
Sample run:
Observe analog Signal . To Sample the signal press ENTER
Enter sampling frequency : 100
fs =
100
Current plot held
TO RECONSTRUCT THE SIGNAL FOM SAMPLES PRESS ENTER
Observe that reconstructed signal is almost matching with the original signal.
Exercise :1.Generate the sinusoidal signals with following frequencies and verify sampling theorem.
i) 100Hz ii)3000 Hz iii) 10,000Hz iv) 1 MHz
2.Generate the following signal and verify sampling theorem.
x(t) =2sin(40t) + 3cos(1000t)
3.Generate the following signal and verify sampling theorem.
x(t) =2sin(40t) cos(1000t)
Experiment 2 Impulse response of a given system
Aim:To find the impulse response h(n) of a system
i) The difference equation characterizing the system.
ii) The system function H(Z) is given.
-
8/12/2019 Digital Signal Processing Laboratory
8/14
Theory:
The response of a discrete-time system to a unit sample sequence[n]is called theunit
sample responseor, simply, theimpulse response, and denoted ash[n].
The impulse response can be used to represent the relation between input and the output
of the system.
A discrete-time system is called afinite impulse response(FIR) system if its impulse
responseh[n] is of finite length. Otherwise, it is aninfinite impulse response(IIR) system.
If a linear, time-invariant discrete-time system is characterized by an impulse responseh[n
The responsey[n] to a input excitationx[n] is given by
=
=k
knhkxny ][][][
and is referred to as convolution.
It is clear that the convolution process in the Z-domain entails the multiplication of two
polynomials.)().()(][*][][ ZHZXZYnhnxny ==
)(
)()(
ZX
ZYZH =
When the system function H(Z) is known the impulse response can be computed by finding
the inverse Z transform of )(ZH . ))((][1 ZHZnh =
The responsey[n] to a input excitationx[n] can also be given by using a difference equation
== +=M
k
N
k 0
k
1
k k)-x(nbk)-y(nay(n) OR
y(n)= b0x(n) + b1x(n-1) + b2x(n-2) +.+ b3x(n-M) - a1y(n-1) - a2y(n-2) -.- a3y(n-N)
Let's take theztransform of both sides; The terms in Y (Z) may be grouped together on
theleft-hand side to get
-
8/12/2019 Digital Signal Processing Laboratory
9/14
Y(Z)= b0X(Z) + b1Z-1X(Z) + b2Z
-2X(Z) +.+ b3Z-MX(Z)
- a1Z-1Y(Z) - a2Z
-2Y(Z) -.- a3Z-NY(Z)
Factoring out the common terms Y(Z) and X(Z) and rearranging
)(.....1
.....
)(
)(2
2
1
1
2
2
1
10ZH
ZaZaZa
ZbZbZbb
ZX
ZY
N
N
M
M=
++++
++++=
The impulse response can be computed by finding the inverse Z transform of )(ZH .
Program:
The difference equation that characterizes the system is given. Compute impulse response
of the system.
y[n]0.4y[n1]+0.75y[n2] = 2.2403x[n]+2.4908x[n1]+2.2403x[n2]
% Compute the impulse response y
close all, clear all
N = 40;
num = [2.2403 2.4908 2.2403]; % coefficients of x[n-k] or numerator of H(Z)
den = [1 -0.4 0.75]; % coefficients of y[n-k] or denomenator of H(Z)
y = impz(num,den,N);
% Plot the impulse response
stem(y);
xlabel('Time index n'); ylabel('Amplitude');
title('Impulse Response'); grid;
Experiment 3 Linear convolution of two given sequencesAIM:To compute the linear convolution of
i) two causal sequences.
ii) Noncausal sequences.
-
8/12/2019 Digital Signal Processing Laboratory
10/14
The linear, time-invariant discrete-time system is characterized by a signal called th
IMPULSE RESPONSE denoted by h[n]. The procedure of finding the output of such an LTI
system for a given input can be described by a mathematical operation called
CONVOLUTION.
The responsey[n] to a input excitationx[n] is given by the superposition of weighted,
shifted impulse responses. Mathematically,
=
=k
knhkxny ][][][
Procedure:
a.Causal sequences
i. Read the input sequenceii. convolve
iii.Plot input and out put signal.
b. Non Causal sequences
For Non-causal sequences using of function conv may not be appropriate since the indexes
may not match.
In Convolution
Beginning index of the convolved sequence =
Index of the first element of the sequence x(n) + index of the first element of the sequence
y(n)
Ending index of the convolved sequence =
Index of the Last element of the sequence x(n) + index of the Last element of the sequence
y(n)
So we modify the program for convolution to perform convolution of Non-causal sequences
as given below.
Accept the Sequences x and h
Accept the index vectors for x and h
Compute Starting and Ending indexes for y
-
8/12/2019 Digital Signal Processing Laboratory
11/14
Compute convolution using function conv.
Plot computed indexes for y Vs y
Program 1
%linear convolution
clc;
close all;
clear all;
x=input('Enter the input sequence x[n] with origin at 0: ');
h=input ('Enter the impulse response h[n] of the system with origin at 0: ');
y=conv(x,h)
subplot(311)
n1=0:length(x)-1;
stem(n1,x, 'filled');
title ('Plot of input sequence x[n]');
n2=0:length(h)-1;
subplot(312)
stem(n2,h,'filled');
title ('Plot of output responce h[n]');
n3=0:length(y)-1;
subplot(313)
stem(n3,y,'filled');
title('Plot of output response y[n]');
xlabel('n---->');ylabel('Amplitude-->')
Sample run
Enter the input sequence x[n] with origin at 0: [1 2 2 1]
-
8/12/2019 Digital Signal Processing Laboratory
12/14
Enter the impulse response h[n] of the system with origin at 0: [1 2 3 4]
y =
1 4 9 15 16 11 4
Program 2:
% to compute the convolution of two sided sequences (Causal Sequences).
clc;
x=input ('enter the first sequence: ');
h=input ('enter the second sequence: ');
nx=input('index vector for first sequence: ');
nh=input('index vector for second sequence: ');
nyb=nx(1)+nh(1);
nye=nx(length(x))+nh(length(h));
ny=[nyb:nye];
y=conv(x,h)
subplot(3,1,1);stem(nx,x)
ylabel('x----->')
subplot(3,1,2);stem(nh,h)
ylabel('h----->')
subplot(3,1,3);stem(ny,y)
xlabel('n--->');ylabel('y----->')
%************ ***************END***********************************
Sample Run:
enter the first sequence: [1 2 3 4 5]
enter the second sequence: [3 4 3]
index vector for first sequence: [-1:3]
index vector for second sequence: [-1:1]
y =
-
8/12/2019 Digital Signal Processing Laboratory
13/14
3 10 20 30 40 32 15
Exercise :
ii) Write and use the function file given below to compute convolution of non causal
sequences.
Function conv_m.m :
Note :Save this Function as a separate fileconv_m.m
%************************* Function Begins Here***********************
% modified convolution routine for Convolution of two sequences
function[y,ny]=conv_m(x,nx,h,nh);
nyb=nx(1)+nh(1);
nye=nx(length(x))+nh(length(h));
ny=[nyb:nye];
y=conv(x,h)
%******************************END ofFunction****************************************
Experiment 4 Cross Correlation
% cross correlation
% Exp a% x ! ["# 11# $# 0# -1# # 2]
% nx![-"&"]
x!inp't(Enter te inp't se'ence x[n]!)nx !inp't(Enter +n,ex ector for x[n])
[y#ny] ! si.sift(x#nx#2)
/ ! ran,n(1#len.t(y))n/ ! ny % .enerate /(n)
[y#ny] ! si.a,,(y#ny#/#n/) % obtain y(n) ! x(n-2) /(n)
nyb!nx(1)ny(1)
nye!nx(len.t(x))ny(len.t(y))nrxy!nyb&nye
rxy!xcorr(x#y)
s'bplot(2#1#1)ste(nrxy#rxy)axis([-##-30#230])xlabel(la. ariable l)
ylabel(rxy)title(4rosscorrelation& noise se'ence)
*****************Supporting Functions********************
sigadd.m
f'nction [y#n] ! si.a,,(x1#n1#x2#n2)
% ipleents y(n) ! x1(n)x2(n)% -----------------------------
-
8/12/2019 Digital Signal Processing Laboratory
14/14
% [y#n] ! si.a,,(x1#n1#x2#n2)% y ! s' se'ence oer n# /ic incl',es n1 an, n2
% x1 ! first se'ence oer n1
% x2 ! secon, se'ence oer n2 (n2 can be ,ifferent fro n1)%
n ! in(in(n1)#in(n2))&ax(ax(n1)#ax(n2)) % ,'ration of y(n)
y1 ! 5eros(1#len.t(n)) y2 ! y1 % initiali5ationy1(fin,((n6!in(n1))7(n8!ax(n1))!!1))!x1 % x1 /it ,'ration of y
y2(fin,((n6!in(n2))7(n8!ax(n2))!!1))!x2 % x2 /it ,'ration of y
y ! y1y2 % se'ence a,,ition
sigfold.m
f'nction [y#n] ! si.fol,(x#n)% ipleents y(n) ! x(-n)
% -----------------------
% [y#n] ! si.fol,(x#n)%
y ! fliplr(x) n ! -fliplr(n)
sigshift.m
f'nction [y#n] ! si.sift(x##n0)
% ipleents y(n) ! x(n-n0)% -------------------------
% [y#n] ! si.sift(x##n0)
%n ! n0 y ! x
Experiment 5 AutoCorrelation
clcclear all
close all
,isp(9'tocorrelation &),isp(Exaple +np'ts )
,isp( x ! ["# 11# $# 0# -1# # 2] )
,isp(nx![-"&"])x!inp't(Enter te inp't se'ence x[n]!)
nx ! inp't(Enter +n,ex ector nx for x[n]!)
nyb!2*nx(1)nye!2*nx(len.t(x))nrxy!nyb&nye
rxy!xcorr(x)
s'bplot(2#1#1)ste(nrxy#rxy)axis([-##-30#230])xlabel(la. ariable l)
ylabel(rxy)title(9'tocorrelation& noise se'ence)