DSP Lab Manual
DSP Lab Manual
of
DIGITAL SIGNAL PROCESSING
Bachelor of Technology
In
ENGINEERING
INDIA
List of Practical
12 To illustrate zero state and zero input response for first and second order system
EXPERIMENT NO.1
Aim: To study Fourier transform of given sequence.
Theory: Fourier transform convert the time domain to frequency domain. It is of two types.
i. CTFT: Continuous Time Fourier Transform
ii. DTFT: Discrete Time Fourier Transform
Output:
enter the signal x:[1 2 3 4 5 6 7]
absolute of X phase of X
30 60
40
20
20
10
0
0 -20
0 50 100 0 50 100
real of X imagnary of X
40 40
20
20
0
0
-20
-20 -40
0 50 100 0 50 100
EXPERIMENT NO.2
Theory:
Definition: It states that sampling frequency must be greater than or equal to twice that of maximum
signal frequency.
fs≥2fin
Output:
Enter the first frequency:0.3
Enter the second frequency:0.9
Enter no. of samples required:99
continuous signal
2
Amplitude
-1
0 20 40 60 80 100 120
T
sampling signal
2
1
Amplitude
-1
0 10 20 30 40 50 60 70 80 90 100
N
EXPERIMENT NO.3
a. Low pass filter: It allows low frequencies to pass through it. For low-pass filter transfer function
is
±
H(z)=( )( ± )
j0
ω=0 z=e =1
ω=π z=ejπ=-1
Syntax in matlab: B1=FIR(N, ωn, ‘low’);
b. High pass filter: It allows high frequencies to pass through it. For high-pass filter transfer
function is
±
H(z)=( )( ± )
j0
ω=0 z=e =1
ω=π z=ejπ=-1
Syntax in matlab: B2=FIR(N, ωn, ‘high’);
c. Band pass filter: It allows certain frequencies of band to pass through it.
Syntax in matlab: B3=FIR(N, ω, ‘band-pass’);
d. Band stop filter: It attenuates certain band of frequencies.
Syntax in matlab: B4=FIR(N, ω, ‘band-stop);
Conclusion: Hence we have studied design of all types of filter.
%design of filters%
N=input('enter the order of fir filter')
wn=input('enter the cutoff frequency')
w1=input('enter the first cutoff frequency')
w2=input('enter the second cutoff frequency')
W=[w1 w2]
B1=FIR1(N,wn,'low')
B2=FIR1(N,wn,'high')
B3=FIR1(N,w,'bandpass')
B1=FIR1(N,w,'stop')
FREQZ(B1)
figure
FREQZ(B2)
figure
FREQZ(B3)
figure
FREQZ(B4)
Figure
Output:
Enter the order of FIR filter:90
Enter the cut off frequency:0.30
Enter the first cut off frequency:0.4
Enter the second cut off frequency:0.80
50
Magnitude (dB)
-50
-100
-150
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1
Normalized Frequency ( rad/sample)
0
Phase (degrees)
-1000
-2000
-3000
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1
Normalized Frequency ( rad/sample)
Magnitude (dB) 50
-50
-100
-150
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1
Normalized Frequency ( rad/sample)
2000
Phase (degrees)
-2000
-4000
-6000
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1
Normalized Frequency ( rad/sample)
50
Magnitude (dB)
-50
-100
-150
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1
Normalized Frequency ( rad/sample)
0
Phase (degrees)
-1000
-2000
-3000
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1
Normalized Frequency ( rad/sample)
Magnitude (dB) 50
-50
-100
-150
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1
Normalized Frequency ( rad/sample)
0
Phase (degrees)
-2000
-4000
-6000
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1
Normalized Frequency ( rad/sample)
EXPERIMENT NO.4
Theory: When x(n) and h(n) are two causal sequence are given as input to the LTI system then output is
y[n]= h[k]x[n − k]
Then using above equation we can find the values of h[n] as follows
y[0]= h[k]x[0 − k]
y[0]=h[0] x[0]
[ ]
h[0]= [ ]
-----------------------------------------------------------------------------------------------------------------(1)
y[1]= h[k]x[1 − k]
[ ] [ ] [ ]
h[1]= [ ]
--------------------------------------------------------------------------------------------(2)
y[2]= h[k]x[2 − k]
[ ] [ ] [ ] [ ] [ ]
h[2]= ------------------------------------------------------------------------------------------(3)
[ ]
By observing equation (1), (2), (3)
We can write the general formula for h[n] as follows
[ ] ( ) ( )
h[n]=
[ ]
Conclusion: We can find the impulse response input if we know that the input sequence and total
output of LTI system.
%impulse response of LTI system%
clear all
x=input('enter the sequence')
y=input('enter the response')
h(1)=y(1)/x(1)
n1=length(x)
n2=length(y)
N=n2-n1+1
for n=2:1:N
s=0
for k=1:1:n-1
s=s+h(k)*x(n-k+1)
end
h(n)=(y(n)-s)/x(1)
end
disp(h)
stem(h)
Output:
enter the sequence[1 1 1]
enter the response [1 8 7 6 5]
-1
1 1.2 1.4 1.6 1.8 2 2.2 2.4 2.6 2.8 3
EXPERIMENT NO.5
Output:
Enter the frequency: 0.33
absolute frequency of hlp
20
15
10
0
0 100 200 300 400 500 600
angle of hlp
4
-2
-4
0 100 200 300 400 500 600
EXPERIMENT NO.6
Theory: If x(n) is given sequence of length N, l is circular shift factor then x(n) can be circularly shifted
as follows
Conclusion : Hence we have studied the circular shift property of a given sequence.
%circular shifting property%
clc
x=input('enter the sequence')
N=length(x)
l=input ('enter the shift factor' )
for n=1:1:N
if (n>l)
x1(n)=x(n-l)
else
x1(n)=x(n-l+N)
end
end
disp(x1)
Output:
enter the sequence[ 6 5 4 3 2 1]
Output:
x=
6 5 4 3 2 1
N=
6
enter the shift factor3
l=
3
x1 =
3 6 1 2 3 4
x1 =
3 2 1 2 3 4
x1 =
3 2 1 2 3 4
x1 =
3 2 1 6 3 4
x1 =
3 2 1 6 5 4
x1 =
3 2 1 6 5 4
3 2 1 6 5 4
EXPERIMENT NO.7
Theory:
It is sampled from a continuous time Fourier transform
x(n) is sequence of length N
X(ω)= x(n)e
x(k)= X(ω)|ω=
( )
X(k)= x(n)e
k=0,1,-------------------N-1
DFT is periodic with period N
i.e. X[k+N]=X[k]
X*[n-k]=X[k]
For each value of k, N times complex multiplications are needed while N-1 times additions are needed.
While for N point DFT we require
N2=complex multiplication
N(N-1)=complex addition
Conclusion: Hence we studied discrete Fourier transform of sequence.
%discrete Fourier transform%
x=input('enter the discrete signal x')
N=length(x)
for k=0:1:N-1
n=0:1:N-1
e=exp(-j*2*pi*n*k/N)
x(k+1)=x*e'
end
subplot(2,2,1)
stem(abs(x))
title('absolute of x')
subplot(2,2,2)
stem(phase(x))
title('phase of x')
subplot(2,2,3)
stem(real(x))
title('real of x')
subplot(2,2,4)
stem(imag(x))
title('imagnary of x')
Output:
Enter the discrete signal X:[1 2 3 4 5 6 7]
absolute of x phase of x
100 2
0
50
-2
0 -4
0 2 4 6 8 0 2 4 6 8
real of x imagnary of x
40 50
20 0
0 -50
-20 -100
0 2 4 6 8 0 2 4 6 8
EXPERIMENT NO.8
Aim: To implement DFT-FFT algorithm using matlab.
Software: Matlab
Theory: Fast Fourier Transform (FFT). The FFT is an algorithm that efficiently computes the
DFT.
The DFT of a sequence x[n] of length N is given by complex value sequence, X(k)
X(k)= x[n] 0< k ≤ N-1
ωn=
Symmetric property W = −W
Periodicity property W =W
Decimation in FFT
Let us assume that x(n) represents sequence of N values where N is
integer of power 2 i.e. N=2
The given sequence is decimated into two N/2 point segments consisting of even and odd
segment.
X(k)= x[n] W
/ /
= x[2n] W + x[2n + 1] W
/ /
= x[2n] W / +W x[2n + 1] W /
Conclusion :Hence we have implemented DFT FFT algorithm and concluded that we can reduce
the multiplier by using DFT FFT.
%algorithm for fft%
x=input('enter the length and sequence')
for i=1:1:4
g(i)=x(i)+x(i+4)
g(i+4)=x(i)-x(i+4)
end
for i= 1:1:2
h(i)=g(i)+g(i+2)
h(i+2)=g(i)-g(i+2)
end
for i=5:1:6
h(i)=g(i)-(j*(g(i+2)))
h(i+2)=g(i)+(j*(g(i+2)))
end
y(i)=bitrevorder(h(i))
for i=1:1:4
X(i)=y(i)+exp(-j*2*pi*(i-1)/8)*y(i+4)
X(i+4)=y(i)+exp(-j*2*pi*(i+3)/8)*y(i+4)
end
z=fft(x)
disp('X=')
disp (X)
disp('z')
disp(z)
Output:
X=
Z=
Type2:
Symmetric impulse response of even length
Let L=6
h[n]={h0,h1,h2,h2,h1,h0}
Type3:
Anti-symmetric impulse response of odd length
Let L=7
h[n]={h0,h1,h2,0,-h2,-h1,-h0}
Type4:
Anti-symmetric impulse response of even length
Let L=6
h[n]={h0,h1,h2,- h2,-h1,-h0}
Z-plane: Z-plane zero plot of zeros Z and pole P with unit circle for reference . Each zero is
represented with ‘O’ and each pole with ‘X’. Multiple zeros and poles are indicated by
multiplicity number shown to upper right of zero or pole.
Output
Enter the first sequence [ 1 2 3 4 3 2 1]
Enter the second sequence [ 1 2 3 0 -3 -2 -1]
Enter the third sequence [ 1 2 3 -3 -2 -1]
Enter the forth sequence [ 1 2 3 3 2 1]
1.5
2
1
0.8 1
0.6
0.5
0.4
Imaginary Part
Imaginary Part
0.2 6
0
2 6
0
-0.2 -0.5
-0.4
-0.6 -1
-0.8
-1
2 -1.5
1.5
1
1 0.8
0.6
0.5
0.4
Imaginary Part
Imaginary Part
5 0.2
0
5
0
-0.5 -0.2
-0.4
-1
-0.6
-1.5 -0.8
-1
-2 -1.5 -1 -0.5 0 0.5 1 1.5 2 -1 -0.5 0 0.5 1
Real Part Real Part
EXPERIMENT NO.10
0.9
0.8
0.7
0.6
0.5
0.4
0.3
0.2
0.1
0
0 10 20 30 40 50 60 70 80 90 100
EXPERIMENT NO.11
Aim:
To illustrate step and impulse response of the system
Software:
MATLAB 7.3
Theory:
Step response: It is defined as the response or output of the system when an input
applied to the system is unit step signal.
Impulse response: It is defined as response or output of the system when input
applied is impulse signal.
Program:
%step and impulse reasponse
num=[2];
den=[2 1 2];
printsys(num,den)
a = tf(num,den);
subplot(211)
impulse(a);
subplot(212)
step(a)
Conclusion:
Thus, we have illustrated the step and impulse response of a system using matlab.
******************************************************************************
Sample output
******************************************************************************
num/den =
2
--------------
2 s^2 + s + 2
>>
Impulse Response
1
0.5
Amplitude
-0.5
0 5 10 15 20 25
Time (sec)
Step Response
1.5
1
Amplitude
0.5
0
0 5 10 15 20 25
Time (sec)
EXPERIMENT NO. 12
Aim:
To illustrate zero state and zero input response for first and second order system
Software:
MATLAB 7.3
Theory:
Zero state response: It is the response of the system when all initial conditions are
assumed to zero and considering only the input applied to the system.
Zero input response: It is the response of the system when input is zero and initial
conditions are considered. It gives state of the system before any input is applied.
Program:
%FIRST ORDER FUNCTION
function [ydot]=myfun1(t,y)
ydot=-4*y+2*cos(2*t).*(t >= 0);
%END OF FUNCTION
%matlab program to solve first order differential Eqution
tspan=[0:0.01:15];
y0=[2];
[t,y]=ode23('myfun1',tspan,y0);
%solve ODE using ode23
plot(t,y,'k');
grid on;
xlabel('time');
ylabel('output response y(t)');
title('total response=ZIR+ZSR:MATLAB Result verification for First order Differential
equation');
figure;
y=1.6*exp(-4*t)+0.2*sin(2*t)+0.4*cos(2*t);
plot(t,y,'k');
grid on;
xlabel('time');
ylabel('output Response y(t)');
title('Total Response=ZIR+ZSR:Analytical Result Verification for first order Differential
Equation');
*******************************************
%SECOND ORDER DIFFERENTIAL EQUATION
function [ydot]=myfunct2(t,y)
%usage:ydot=myfunc2(t,y)
ydot(1,1)=-5*y(1)-4*y(2)+3*cos(t)*(t>=0);
ydot(2,1)=y(1);
%end of function
Clear all;
tspan=[0:0.02:20];
y0=[-5;2];
[t,y]=ode23('myfunc2',tspan,y0)
plot(t,y(:,2),'k')
grid on;
xlabel('time');
ylabel('output Response y(t)');
title('Total Response=ZIR+ZSR:for second order Differential Equation');
figure;
y=(1/2)*exp(-t)+(21/17)*exp(-4*t)+(9/34)*cos(t)+(15/34)*sin(t);
plot(t,y,'k')
grid on;
xlabel('time');
ylabel('output Response y(t)');
title('Total Response=ZIR+ZSR:Analytical Result Verification for second order
Differential Equation');
Conclusion:
Thus, ZIR and ZSR for first order and second order differential equations are verified
using matlab.
SAMPLE OUTPUT
1.5
output response y(t)
0.5
-0.5
0 5 10 15
time
1.5
output Response y(t)
0.5
-0.5
0 5 10 15
time
Total Response=ZIR+ZSR:for second order Differential Equation
2
1.5
1
output Response y(t)
0.5
-0.5
-1
0 2 4 6 8 10 12 14 16 18 20
time
1.5
1
output Response y(t)
0.5
-0.5
-1
0 2 4 6 8 10 12 14 16 18 20
time