Вы находитесь на странице: 1из 35

DSP Lab Manual

Digital signal Processing


Lab Manual

Submitted by
Farzana Latif (08 TL 04)

Submitted To
Sir M. Abdullah

Department
Telecom (morning)
6th semester (3rd year)
Session (2008-2012)

University College of Engineering and Technology


(UCET)
The Islamia University of Bahawalpur
(IUB)

Department of Telecommunication Engineering (IUB)


DSP Lab Manual

EXPERIMENT # 1
Objective:
To become familiar with creating signals in MATLAB and then plotting them.
Part 1: Continuous-Time Signals
You are to plot three different signals using MATLAB.
 x 1 ( t )=4 e−t /5

 x 2 ( t )=sin ( 2 π ft + π /2 ) where f = 4Hz


 x ( t )=x 1 ( t ) x 2 ( t )
Use the subfigure command to create two separate plots on the same figure. In the upper region
of this figure, plot x1(t) and x2(t) overlaying each other. In the lower portion of this figure, plot
x(t). Only plot these signals on the range 0 to 10 seconds. For the upper plot, create a legend to
distinguish between the two traces.
To approximate continuous-time waveforms using discrete data points, use a “fast” sampling rate
(i.e. much faster than the Nyquist rate). Your continuous-time signals should look like they are
continuous in time (i.e. they should be smooth with no distinguishable “jagged edges” – for
example, a sine wave should look like a sine wave, as if you were to draw it by hand).
Solution

Department of Telecommunication Engineering (IUB)


DSP Lab Manual

Part 2: Discrete-Time Signals


You are to plot three different sequences using MATLAB
 x 1 [ n ] =2 ( 0. 8 )n


x 2 [ n ] =sin ( 2Nπn ) where N = 10 (this is the period)
 x [ n ]=x 1 [ n ] x 2 [ n ]
Use the subfigure command to create two separate plots on the same figure. In the upper region
of this figure, plot x1[n] and x2[n] overlaying each other. In the lower portion of this figure, plot
x[n]. Only plot these sequences on the range 0 to 20 samples.
On the upper plot, do not create a legend to distinguish the two traces, but instead plot the two
traces with different markers.

Department of Telecommunication Engineering (IUB)


DSP Lab Manual

Part 3:
Given a pair of sequences, use discrete convolution to find the response to the input x[n] of the
linear time-invariant system with impulse response h[n]. 
x[n]=[1 0 0 0 1 1 1 1 0 0 ]
y[n]= [1  1 0 1 ]
i. Use PLOT command to plot the x and y
ii. Write a MATLAB function to compute the convolution of the two finite-length
sequences and plot the results.

Department of Telecommunication Engineering (IUB)


DSP Lab Manual

iii. Use CONV command to verify the results from (ii)


Helpful Hints
x
 Exponentials of the form e use the MATLAB function exp
 π can be written in MATLAB using pi
 You can get help on any function by typing help function_name
 Do not forget axis labels and titles on your plots
 What sampling rate is necessary to make the “continuous-time signals” look smooth?

EXPERIMENT #2
Objective:
Digital filter frequency response

Department of Telecommunication Engineering (IUB)


DSP Lab Manual

Department of Telecommunication Engineering (IUB)


DSP Lab Manual

Department of Telecommunication Engineering (IUB)


DSP Lab Manual

Solution

Department of Telecommunication Engineering (IUB)


DSP Lab Manual

EXPERIMENT # 3
Objective:
Z-Transform in Matlab
Assume we have a transfer function in the z-domain given by
−1
z z
X ( z )= −1 −2
= 2
1−0 .25 z −0 .375 z z −0 .25 z−0 . 375 .

Factoring this, it’s partial fraction expansion can be found to be

z c1 z c2 z 0 .8 z −0 .8 z
X ( z )= = + = +
( z −0 .75 ) ( z+0 .5 ) ( z−0 . 75 ) ( z+ 0 .5 ) ( z−0 . 75 ) ( z+ 0 .5 ) .

The inverse z-transform of this is thus

x ( n )=[ ( 0 . 8 ) ( 0. 75 )n + (−0 . 8 )(−0. 5 )n ] u ( n )


There are several MATLAB functions that could assist with calculating and analyzing these results. We
can find the roots of the denominator polynomial using

>> den = [1 -0.25 -0.375];

>> roots(den)

ans =

0.7500

-0.5000

We can then plot the zeros and poles either with

(1) zeros and poles in column vectors


>> z = [0]
z=
0
>> p = [0.75; -0.5]
p=
0.7500
-0.5000
>> zplane(z,p)

Department of Telecommunication Engineering (IUB)


DSP Lab Manual

(2) numerator and denominator coefficients in row vectors


>> num = [0 1 0]
num =
0 1 0
>> den = [1 -0.25 -0.375]
den =
1.0000 -0.2500 -0.3750
(3) >> zplane(num,den)

Department of Telecommunication Engineering (IUB)


DSP Lab Manual

We can find the impulse response (or inverse z-transform) of the polynomial based on the power series
expansion method using the “impz” function
h = impz(num,den,N) where N is the number of terms or coefficients to compute

>> h = impz(num,den,10)
h=
0
1.0000
0.2500
0.4375
0.2031
0.2148
0.1299
0.1130
0.0770
0.0616

We can also plot the frequency response of a particular polynomial with freqz

z
X ( z )= 2
For z −0 . 25 z −0 .375 we would enter
>> num = [0 1 0];

>> den = [1 -0.25 -0.375];

>> freqz(num, den, 512)

Here we have used the form

freqz(num,den,N)

Department of Telecommunication Engineering (IUB)


DSP Lab Manual

where ‘num’ are the numerator coefficients, ‘den’ are the denominator coefficients, and ‘N’ is the number
of points to use in the plot which goes from 0 to . An alternative form is to use

[H,f] = freqz(num,den,N,Fs)

plot(f, abs(H))

‘num’ and ‘den’ are the same. ‘Fs’ is the sampling frequency. ‘N’ values between 0 and Fs are
calculated. The response data versus frequency are stored in H.

>> num = [0 1 0];

>> den = [1 -0.25 -0.375];

>> [H,f] = freqz(num,den,512,8000);

>> plot(f,abs(H))

Department of Telecommunication Engineering (IUB)


DSP Lab Manual

EXPERIMENT # 4
Objective
Z-transform and Impulse response
Description
a) Channel Response shown in figure 1.

0.8

0.6

0.4
Imaginary Part

0.2

-0.2

-0.4

-0.6

-0.8

-1

-1 -0.5 0 0.5 1
Real Part

Figure 1: Channel Response


Where Zeros are located at -0.5 - 0.5i and -0.5 + 0.5i .Poles at 0.5 + 0.5i and 0.5 - 0.5i
Find following and plot them using MATLAB
 H(z)
 H(ejw)
 h1[n]
b) Find the Inverse Response of above channel (show in figure)and plot them using MATLAB
 H(z)
 H(ejw)
 h2[n]

c) Also Find y[n] ,when x[n]=[1 0 1 2 3 5 0 4 5] and plot them using MATLAB

Department of Telecommunication Engineering (IUB)


DSP Lab Manual

 y[n] =x[n]*h1[n]
 y[n] =x[n]*h1[n]*h2[n]

Solution
a) Mathematical expression
For H(z)

As zeros are the roots of numerator of H(z) and poles are roots of denominator of H(z) so,

z 1=−0.5−0.5 i

z 2=−0.5+ 0.5i

p1=0.5+ 0.5i

p2=0.5−0.5 i

( z−z1 ) ( z−z 2) ( z +0.5+0.5 i ) ( z +0.5−0.5i)


H 1 ( z )= =
( z− p1 ) ( z−p 2) ( z−0.5−0.5 i) ( z−0.5+0.5 i)
( z +0.5 )2 −( 0.5i )2 z 2+ 0.25+ z+ 0.25
H 1 ( z )= 2 2
= 2
( z−0.5 ) −( 0.5 i ) z + 0.25−z +0.25
2
z 2 + z+ 0.5 z (1+ z + 0.5 z ) 1+ z−1+ 0.5 z −2
−1 −2
H 1 ( z )= 2 = =
z −z +0.5 z 2(1−z−1+ 0.5 z−2) 1−z−1 +0.5 z−2
For H(exp(jw))

Substituting z=e jω, we get

jω 1+e− jω +0.5 e−2 j ω


H 1( e )=
1−e− jω +0.5 e−2 jω
For h[n]

Department of Telecommunication Engineering (IUB)


DSP Lab Manual

Y ( z ) 1+ z−1 +0.5 z−2


=
X (z ) 1−z −1 +0.5 z−2

Y ( z ) ( 1− z−1+ 0.5 z−2 ) =X ( z )(1+ z −1 +0.5 z−2 )

Y ( z )−z−1 Y ( z )+ 0.5 z−2 Y ( z )=X ( z )+ z −1 X ( z )+ 0.5 z−2 X ( z )

y [ n ] − y [ n−1 ] +0.5 y [ n−2 ] =x [ n ] + x [ n−1 ] +0.5 x [ n−2 ]

y [ n ] = y [ n−1 ] −0.5 y [ n−2 ] + x [ n ] + x [ n−1 ] +0.5 x [ n−2 ]

Matlab code and expression

Department of Telecommunication Engineering (IUB)


DSP Lab Manual

Department of Telecommunication Engineering (IUB)


DSP Lab Manual

b) Mathematical expression
For H(z)
As zeros are the roots of numerator of H(z) and poles are roots of denominator of H(z) so,

p1=−0.5−0.5 i

p2=−0.5+0.5 i

z 1=0.5+0.5 i

z 2=0.5−0.5 i

( z−z 1) ( z−z 2) ( z−0.5−0.5 i) ( z −0.5+0.5 i)


H2 (z )= =
( z− p 1) ( z− p2) ( z +0.5+0.5 i ) ( z +0.5−0.5i)
( z +0.5 )2 −( 0.5i )2 z 2+ 0.25−z +0.25
H2 (z )= 2 2
= 2
( z−0.5 ) −( 0.5 i ) z + 0.25+ z+ 0.25
2
z 2−z +0.5 z ( 1−z + 0.5 z ) 1−z−1 +0.5 z−2
−1 −2
H2 (z )= 2 = =
z + z +0.5 z 2 (1+ z−1+ 0.5 z −2 ) 1+ z−1+ 0.5 z −2

Substituting z=e jω, we get

For H(exp(jw))
− jω −2 jω
jω 1−e +0.5 e
H 2 ( e )=
1+e− jω +0.5 e−2 jω
Y ( z ) 1−z −1 +0.5 z−2
=
X (z ) 1+ z−1 +0.5 z−2

For h[n]

Y ( z ) ( 1+ z−1 +0.5 z−2 )= X ( z ) (1−z −1 +0.5 z−2 )

Y ( z )+ z −1 Y ( z ) +0.5 z−2 Y ( z )= X ( z )−z −1 X ( z )+ 0.5 z−2 X ( z )

y [ n ] + y [ n−1 ] + 0.5 y [ n−2 ] =x [ n ]−x [ n−1 ] +0.5 x [ n−2 ]

y [ n ] =− y [ n−1 ]−0.5 y [ n−2 ] + x [ n ] −x [ n−1 ] + 0.5 x [ n−2 ]

Department of Telecommunication Engineering (IUB)


DSP Lab Manual

Matlab code and expression

Department of Telecommunication Engineering (IUB)


DSP Lab Manual

c) Mathematical expression

x[n] g[n] y[n]

Matlab code and expression

Department of Telecommunication Engineering (IUB)


DSP Lab Manual

EXPERIMENT # 5
Objective
Digital Processing of Continuous Signals
Description
Digital processing of analog signals has following advantages over its analog counterpart.
􀂾 Programmable Operations
􀂾 Greater flexibility
􀂾 Higher order of precision
􀂾 Better performance.
An analog signal can be converted into digital using the following steps

Department of Telecommunication Engineering (IUB)


DSP Lab Manual

􀀹 Sampling
􀀹 Quantization
􀀹 Digital Coding

Sampling Of a Sinusoidal Signal


It is the conversion of a continuous time signal into a discrete time signal by obtaining
“Samples” of the continuous time signal at discrete time instants. Thus if Xa(t) is the input to the
sampler, the output is Xa(nT) = X(n), Where T is called the sampling interval.

Nyquist Sampling Theorm explains, the minimum sampling rate to avoid the Aliasing Effect,
should be equal to twice the highest frequency component of the signal.
Matlab Code
% Illustration of the Sampling Process

Reconstruction of Analog Signal


The Analog signal can be reconstructed from the samples, provided that the sampling rate is
sufficiently high to avoid the Aliasing Effect.
Matlab Code to Explain the Aliasing Effect
tmin = -1;
tmax = 1;
t=tmin: 0.001: tmax; % Analog signal
xa=cos(2*pi*13*t)
Fs = 50 % Sampling rate (sample/second)
Ts = 1/Fs % Sample period

Department of Telecommunication Engineering (IUB)


DSP Lab Manual

n = tmin*Fs:tmax*Fs; % Discrete time signal


x=cos(2*pi*13*n*Ts)
figure(1) %Display signals in time domain
subplot(211)
plot(t,xa)
title('Analog and discrete time signals')
xlabel('time (sec)')
ylabel('Analog signal x(t)')
subplot(212)
stem(n,x)
xlabel('n')
ylabel('Discrete time signal x(n)')
figure(2)
clf
subplot(211)
hold on
stem(n*Ts,x,'r')
for i = 1:size(x,2)
xsinc(i,:) = x(i)*sinc(Fs*(t -(i+min(n)-1)*Ts));
plot(t,xsinc(i,:))
end
title('Signal reconstruction')
xlabel('time (second)')
ylabel('x(n)*Sinc(Fs*(t-nTs))')
hold off
xar = sum(xsinc);
subplot(212)
plot(t,xar,'b-',t,xa,'r:')
legend('Reconstructed signal','Original signal')
ylabel('Reconstructed signal xa(t)')
xlabel('time (second)')
% reconstruction error
maxerror = max(abs(xa - xar))

Department of Telecommunication Engineering (IUB)


DSP Lab Manual

Department of Telecommunication Engineering (IUB)


DSP Lab Manual

Experiment No #6
Objective
Implement the Given Block Diagram in MATLAB.

Plot the following figures: Figure 1

 Original Signal (Time and Frequency Domain) in Figure#1


 Decimated Signal (Time and Frequency Domain) in Figure#2
 Interpolated Signal (Time and Frequency Domain) in Figure#3
 Recovered Signal (Time and Frequency Domain) in Figure#4
Note:

 No parameters other than M and L are taken from User.


 LPF Filter (4 KHz) must adjust; Such that no aliasing occurs at Decimation stage and no
images comes at interpolation stage.
 Don’t Use MATLAB function for decimation and interpolation
 Input signal (Speech_dft_8khz.wav) is uploading to Google groups.

Department of Telecommunication Engineering (IUB)


DSP Lab Manual

(QUESTION N0.1)

0.5

-0.5

-1
0 0.5 1 1.5 2 2.5 3 3.5 4
4
x 10
800

600

400

200

0
0 0.5 1 1.5 2 2.5 3 3.5 4
4
x 10
Figure 01: Input Signal

Department of Telecommunication Engineering (IUB)


DSP Lab Manual

0.5

-0.5

-1
0 0.5 1 1.5 2 2.5 3 3.5 4
4
x 10
800

600

400

200

0
0 0.5 1 1.5 2 2.5 3 3.5 4
4
x 10
Figure 02: Input Signal after Low pass filter

Department of Telecommunication Engineering (IUB)


DSP Lab Manual

Output Sequence downsampled by 2


1

0.5
Amplitude

-0.5

-1
0 0.2 0.4 0.6 0.8 1 1.2 1.4 1.6 1.8 2
Time index n 4
x 10
400

300

200

100

0
0 0.2 0.4 0.6 0.8 1 1.2 1.4 1.6 1.8 2
4
x 10
Figure 03: Input Signal after Down Sapling

Department of Telecommunication Engineering (IUB)


DSP Lab Manual

Output Sequence upsampled by2


1

0.5
Amplitude

-0.5

-1
0 0.5 1 1.5 2 2.5 3 3.5 4
time index n 4
x 10
400

300

200

100

0
0 0.5 1 1.5 2 2.5 3 3.5 4
4
x 10

Figure 04: Input Signal after Up-Sapling

Department of Telecommunication Engineering (IUB)


DSP Lab Manual

0.5

-0.5

-1
0 0.5 1 1.5 2 2.5 3 3.5 4
4
x 10
800

600

400

200

0
0 1 2 3 4 5 6 7 8
4
x 10
Figure 05: Output Signal after Low Pass filter

Department of Telecommunication Engineering (IUB)


DSP Lab Manual

Experiment No #7
Objective
To become familiar with creating Filters in MATLAB

 Implementation of IIR Lowpass filter using ‘fdatool ’


o fc=4KHz Using Butterworth
o fc=4KHz Using Chebyshev 1
o fc= 4KHz Using Elliptic
Solution
Impulse response of IIR Low pass filter using Butterworth, Fc=4 KHz

Department of Telecommunication Engineering (IUB)


DSP Lab Manual

Impulse response of IIR Low pass filter using Chebyshev 1, Fc=4 KHz

Department of Telecommunication Engineering (IUB)


DSP Lab Manual

Impulse response of IIR Low pass filter using Elliptic, Fc=4 KHz

Department of Telecommunication Engineering (IUB)


DSP Lab Manual

Experiment No 8
Objective: To become familiar with creating Filters in MATLAB

 Implementation of FIR Low pass filter using ‘fdatool ’


o fc=4KHz Using Windowing Method
o fc=4KHz Using Complex Equiripple Method
o fc= 4KHz Using Least Square Method
Note: Plot the impulse response of following filters and comment about their response.

Solution
Impulse response of FIR Low pass filter using windowing method, Fc=4 KHz

Department of Telecommunication Engineering (IUB)


DSP Lab Manual

Impulse response of FIR Low pass filter using Complex Equiripple, Fc=4 KHz

Department of Telecommunication Engineering (IUB)


DSP Lab Manual

Impulse response of FIR Low pass filter using Least Square Method, Fc=4 KHz

Department of Telecommunication Engineering (IUB)

Вам также может понравиться