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

Location: ____________________ Time: ________________

Semester: Spring 2011 Section: BICSE-6ABC___

Department of Electrical Engineering

CSE-304 Digital Signal Processing

Course Instructor: ________________________

LAB MANUAL

CSE-304 DSP. Page 1


List of Experiments

Contents

Lab1: Introduction to Matlab (Part I)...........................................................................5


Lab2: Introduction to Matlab (Part II)..........................................................................7
Lab3: Basic Signals and System.................................................................................9
Lab4: FREQUENCY DOMAIN VIEW OF SAMPLING......................................................12
Lab5: DISCRETE FOURIER TRANSFORM....................................................................18
Lab6: FAST FOURIER TRANSFORM............................................................................22
Lab7: Z Transform................................................................................................... 33
Lab8: IIR DIGITA: FILTER DESIGN...............................................................................40
Lab9: FILTER DESIGN USING ANALOG PROTOTYPING................................................44
Lab10: LINEAR PHASE FIR FILTER DESIGN BASED ON WINDOWS........................49
Lab11: INTERPOLATION AND DECIMATION...............................................................55
Lab12: THE POLYPHASE DECOMPOSITION................................................................61
Lab13: PERIODIC WAVE GENERATORS......................................................................68
Lab14: NOISE REDUCTION AND SIGNAL ENHANCMENT............................................73
Lab15: ADAPTIVE FILTERING..................................................................................... 77
Lab16: DEMONSTRATION OF REAL-TIME SIGNAL PROCESSING.................................83

CSE-304 DSP. Page 2


SemesterSpring 2011
DSP/ Communication Lab

S.N Faculty Subject Course Duration


O
01 MrAamirjelani DSP
02 DrSaadQaisar DSP
03 MsShahidaJabeen DSP

CSE-304 DSP. Page 3


Faculty Member:____________________ Dated: ________________

Semester:_____________ Section: ________________

Department of Electrical Engineering

CSE-304 Digital Signal Processing


LABORATORY EXERCISE 1
Lab1: Introduction to Matlab (Part I)

Name Reg. no. Report Viva Total/15


Marks / 10 Marks / 5

CSE-304 DSP. Page 4


Lab1: Introduction to Matlab (Part I)

Official Matlab Getting Started with Matlab Guide available in Digital Format

Chapters 1,2,3 covered in this Lab

CSE-304 DSP. Page 5


Faculty Member:____________________ Dated: ________________

Semester:_____________ Section: ________________

Department of Electrical Engineering

CSE-304 Digital Signal Processing


LABORATORY EXERCISE 2
Lab2: Introduction to Matlab (Part II)

Name Reg. no. Report Viva Total/15


Marks / 10 Marks / 5

CSE-304 DSP. Page 6


Lab2: Introduction to Matlab (Part II)

Official Matlab Getting Started with Matlab Guide available in Digital Format

Chapters 4,5 covered in this Lab

Faculty Member:____________________ Dated: ________________

Semester:_____________ Section: ________________

Department of Electrical Engineering

CSE-304 Digital Signal Processing


LABORATORY EXERCISE 3
Lab3: Basic Signals and System

Name Reg. no. Report Viva Total/15


Marks / 10 Marks / 5

CSE-304 DSP. Page 7


Lab3: Basic Signals and System

What is Impulse?
S [n]= 1, if n=0
0, otherwise
S[n-n0] = 1, if n=0
0, otherwise

Impulse signal for length L = 31:


L = 31
nn=0: L-l
imp = zeros(L,l)
imp(l)= 1 ;

Problem 1:
(a) Implement a function for generating and plotting
x[n] = m[n n0] for a < n < b
Try it for
(i) n0= 5, m = 0.9, a = 1, b = 20
(ii) n0= 0. m = 0.8, a = -15, b = 15
(iii) n0= 333, m = 1.5, a= 300, b = 350

CSE-304 DSP. Page 8


(iv) n0= -7, m = 4.5, a=-10 b=0
(b) Generate and implement the function
M 1
[ n] A [n lP ]
l 0
i

(Al = weights vector; P= period)


E.g., for M= 5 and P = 3;
4

A [n 3l ]
l 0
l

Problem 2:
(a) A cosine wave is
x[n] = A cos(0 n +)
generate and plot
x1 [n] = sin ( n 1 7 ) 0n25
x2 [n] = sin ( n 1 7 ) -1 5 n 25
x3 [n] = sin ( 3 n + 2 ) -10n10

Express x3[n] using a function other than trigonometric functions.


(b) Implement a function for
x[n] = A cos( 0 n +)
for a n b
A=2 = 11; =0; a=-20; b=20

CSE-304 DSP. Page 9


Faculty Member:____________________ Dated: ________________

Semester:_____________ Section: ________________

Department of Electrical Engineering

CSE-304 Digital Signal Processing


LABORATORY EXERCISE 4
Lab4: FREQUENCY DOMAIN VIEW OF SAMPLING

Name Reg. no. Report Viva Total/15


Marks / 10 Marks / 5

Lab4: FREQUENCY DOMAIN VIEW OF SAMPLING

CSE-304 DSP. Page 10


Sampling:
Under certain conditions, a continuous-time signal can be completely represented its values or
samples at points equally spaced in time. Consider the continuous time signal x(t). This signal can
be represented as a discrete time signal using values of x(t) at 'n' number of intervals spaced by a
time interval Ts.
X=sin(10t)
Sampled Signal (100 Hz)

Nyquist Criterion

If the greater the number of samples the greater the accuracy, then why don't we sample at a very
high rate? There are two reasons for it. First of all high number of samples require a lot of
manipulation on behalf of the machine/software that we are using which results in more time.
Secondly most of the vital data that we need can easily be obtained from low sampling rates.
Therefore we need some criteria to define the rate at which the signals should be sampled. This
criteria is called as 'Nyquist Criteria'. According to it, the sampling frequency must (at least) be
twice the signal frequency. Consider the following figures

CSE-304 DSP. Page 11


Sampled Signal (5 Hz)

Sampled Signal (10 Hz)

We can see that when the sampling rate doesnt satisfy the N.C, we dont get correct information
about the signal.

Effect of Sampling in Frequency Domain

In time domain sampling can be represented by multiplication of the analogue signal with
impulse train, in which each impulse is separated by sampling time. Since Fourier transform of
an impulse train is an impulse train, in frequency domain it is equivalent of convolution of the
Fourier transform of the signal with another impulse train, which results in multiple copies of the
spectrum of the original signal. This process is shown in the figures (sampling frequency = 100
radians/sec):

CSE-304 DSP. Page 12


Original signal

Sampled Signal

It is clear from the figure that when sampling frequency is less than Nyquist rate, the repeating
spectrum of the sampled signals will overlap and aliasing will occurs. Therefore it is necessary to
band limit the signal before converting it to digital signal in order to avoid aliasing.
In order to reconstruct the signal we need to pass it through a low pass filter with cutoff
frequency fs/2. The results are shown in the following figure:

CSE-304 DSP. Page 13


Reconstructed Signal

Simulation of Analogue Signals in MATLAB


We can't have a pure analogue signal in MATLAB. So we use a simulation frequency, which is
much higher than sampling rate
In order to estimate frequency spectrum of the signal in analogue frequency domain, we can
make use of digital techniques. The following function gives the same functionality:
function fplot(xa,fsim)
L = length(xa);
Nfft = 2* round (log 2(5 * L));
Xa=fft(xa,Nffi);
range = 0: Nfft / 2
frequency = (range/Nffi)* fsim
plot(ff/1000, abs(Xa(range +1)))

Lab Exercises:
Problem 1:
For all simulations take fsim = 80kHz
i) Generate a signal

CSE-304 DSP. Page 14


x(t) = cos (2f0t) 0tT;
Choose T so that you have exactly 1000 samples e.g. T = 1000/fsim
ii) plot x against t.
iii) plot its Fourier transform using 'fplot'

Problem 2:
Convert the analogue signal to digital so that the samples are spaced by Ts. The ratio of fsim /fs =
1 (an integer).
i) Plot the resulting discrete time-signal with fs = 8 kHz
ii) Take its DTFT and plot it.

Problem 3:
Design a reconstruction filter
[b, a] = cheby2(9,60, fwt)
where
fwt= 2*(fs/2)* 1/fsim
use freqz to view its frequency response.
Problem 4:
Convert the digital signal to analogue signal using D/A conversion.
Insert zeros in between the digital signal to obtain an analogue output. Then apply chebyshev
filter to this output. Plot the resulting recovered signal and its Fourier transform.
Problem 5:
Try the entire procedure for fs = 8 kHz and f0= 2 kHz, 6 kHz, 7 kHz and 15 kHz.

CSE-304 DSP. Page 15


Faculty Member:____________________ Dated: ________________

Semester:_____________ Section: ________________

Department of Electrical Engineering

CSE-304 Digital Signal Processing


LABORATORY EXERCISE 5
Lab5: DISCRETE FOURIER TRANSFORM

Name Reg. no. Report Viva Total/15


Marks / 10 Marks / 5

CSE-304 DSP. Page 16


Lab5: DISCRETE FOURIER TRANSFORM

Discrete Time Fourier Transform (DTFT)


DTFT of a signal x[n] can be defined as:
N-1
X() = x[n] e-jwn
n=0
It gives frequency spectrum of the signal. Since co is continuous, its range is continuous. So it is
impossible to get a vector in MATLAB which covers entire range of the DTFT.
Discrete Forurier Transform (DFT)
N point DFT of a signal x[n] is defined as:
N-1
X (K) = x[n] e-j(2/N)kn
n=0
and IDFT can be obtained by the relation:
N-1
x (n) = 1 x[n] e-j(2/N)kn
N n=0
N point DFT means taking N equidistant samples (Sampling in frequency domain). DFT is a
sampled version of DTFT.
Now you are dividing 2n in N samples.
Width = 2
N
In order to estimate DTFT of the signal, we may take DFT of the signal, while taking large
number of DFT points.

CSE-304 DSP. Page 17


FFT

FFT is an efficient algorithm of calculation of DFT. It requires much less computation, but it
requires the number of samples to be an integer power of 2. MATLAB provides FFT command
to compute DFT using FFT algorithm
Lab Exercises:
Problem 1:
i) Find 8 point DFT for the signal
xi= [10000000]
ii) xi=[11111111]
iii) Shifted impulse
xshift = [00010000]
iv) 3-point boxcar
xb = [11100000]
v) Symmetric boxcar
xbsy= [11000001]

Problem 2:
s[n] = A cos(27f0n + )
A=2 , = /4
i) Compute the 21-point DFT of s[n], Choose f0so that you have exactly 1 cycle Plot the
magnitude and phase,
ii) Repeat for a sine wave,
iii) Choose f0such that you have exactly3 cycles, (21-point DFT)

f0 1
8
iv) Choose and N=21 . What is the result ? if there is phase, why?
Problem 3:

CSE-304 DSP. Page 18


s[ n] e j0n

6
0
N
i) and N=16 Compute DFT.

5
0
N
ii) and N=16 Compute DFT
Problem 5:

Repeat above problems using FFT and IFFT ( Choose number of samples accordingly)

Faculty Member:____________________ Dated: ________________

Semester:_____________ Section: ________________

CSE-304 DSP. Page 19


Department of Electrical Engineering

CSE-304 Digital Signal Processing


LABORATORY EXERCISE 6
Lab6: FAST FOURIER TRANSFORM

Name Reg. no. Report Viva Total/15


Marks / 10 Marks / 5

CSE-304 DSP. Page 20


Lab6: FAST FOURIER TRANSFORM

Introduction

DFT

The FFT reduces considerably the computational requirements of the DFT. The DFT
of a discrete-time signal x(nT) is

where the sampling period T is implied in x(n) and N is the frame length. The
constants W are referred to as twiddle constants or factors, which represent the
phase, or and are a function of the length N.

DFT Equation can be written for k = 0, 1, . . . ,N - 1, as

Since this equation is in terms of a complex exponential, for each specific k there
are (N - 1) complex additions and N complex multiplications. This results in a total
of (N2 - N) complex additions and N2 complex multiplications. Hence, the
computational requirements of the DFT can be very intensive, especially for large
values of N. FFT reduces computational complexity from N2 to N logN.

The FFT algorithm takes advantage of the periodicity and symmetry of the twiddle
constants to reduce the computational requirements of the FFT.

CSE-304 DSP. Page 21


From the periodicity of W,

and from the symmetry of W,

For example, let k = 2, and note that W10 = W2, and from W6 = -W2.

DECIMATION-IN-FREQUENCY FFT ALGORITHM WITH RADIX-2

Let a time-domain input sequence x(n) be separated into two halves:

Taking the DFT of each set of the sequence gives us

Let n = n + N/2 in the second summation ; X(k) becomes

CSE-304 DSP. Page 22


where WkN/2 is taken out of the second summation because it is not a function of
n. Using

X(k) becomes

Because (-1)k = 1 for even k and -1 for odd k ,above equation can be separated for
even and odd k, or

Substituting k = 2k for even k, and k = 2k + 1 for odd k, even and odd parts can
be written for k = 0, 1, . . . , (N/2) - 1 as

CSE-304 DSP. Page 23


Because the twiddle constant W is a function of the length N, it can be represented
as WN. Then W2N can be written as WN/2. Let

Above Equation can be written more clearly as two (N/2)-point DFTs,

Figure 1 shows the decomposition of an N-point DFT into two (N/2)-point DFTs for
N = 8. As a result of the decomposition process, the Xs in Figure 1 are even in the
upper half and odd in the lower half. The decomposition process can now be
repeated such that each of the (N/2)-point DFTs is further decomposed into two
(N/4)-point DFTs, as shown in Figure 2, again using N = 8 to illustrate. The upper
section of the output sequence in Figure 1 yields the sequence X(0) and X(4) in
Figure 2, ordered as even. X(2) and X(6) from Figure 2 representthe odd values.
Similarly, the lower section of the output sequence in Figure 1 yields X(1) and X(5),
ordered as the even values, and X(3) and X(7) as the odd values. This scrambling is

CSE-304 DSP. Page 24


due to the decomposition process. The final order of the output sequence X(0),
X(4), . . . in Figure 2 is shown to be scrambled.

Figure1 Decomposition of an N-point DFT into two (N/2)-point DFTs for N = 8

Figure 2 Decomposition of a N Point DFT into four N/4 Point DFTs N=8.

CSE-304 DSP. Page 25


The output sequence X(k) represents the DFT of the time sequence x(n). This is the
last decomposition, since we now have a set of (N/2) two-point DFTs, the lowest
decomposition for a radix-2. For the two-point DFT, X(k) in FFT be written as

since W1 = e-j2pi/2 = -1.Above equations can be represented by the flow graph in


Figure 3, usually referred to as a butterfly.

Figure 3 Two Point FFT Butterfly

This algorithm is referred to as decimation-in-frequency (DIF) because the output


sequence X(k) is decomposed (decimated) into smaller subsequences, and this
process continues through M stages or iterations, where N = 2M. The output X(k) is
complex with both real and imaginary components, and the FFT algorithm can
accommodate either complex or real input values.

CSE-304 DSP. Page 26


The FFT is not an approximation of the DFT. It yields the same result as the DFT
with fewer computations required. This reduction becomes more and more
important with higher-order FFT.

DECIMATION-IN-TIME FFT ALGORITHM WITH RADIX-2

Whereas the DIF process decomposes an output sequence into smaller


subsequences, decimation-in-time (DIT) is a process that decomposes the input
sequence into smaller subsequences. Let the input sequence be decomposed into
an even sequence and an odd sequence, or

and

We can apply DFT equation to these two sequences

Using W2N = WN/2 above equation can be expressed as two N/2 point DFTs.

Let

CSE-304 DSP. Page 27


X(k) can be written as

Equation needs to be interpreted for k > (N/2) - 1. Using the symmetry property of
the twiddle constant, W k+N/2 = -W k,

example, for N = 8, FFT via Decimation in time is given by

Figure 4 shows the decomposition of an eight-point DFT into two four-point DFTs
with the DIT procedure. This decomposition or decimation process is repeated so
that each four-point DFT is further decomposed into two two-point DFTs, as shown
in Figure 5. Since the last decomposition is (N/2) two-point DFTs, this is as far as
this process goes.

CSE-304 DSP. Page 28


Figure 4 Decomposition of eight-point DFT into four-point DFTs using DIT.

Figure 5 Decomposition of two four-point DFTs into four two-point DFTs using DIT.

INVERSE FAST FOURIER TRANSFORM

The inverse discrete Fourier transform (IDFT) converts a frequency-domain


sequence X(k) into an equivalent sequence x(n) in the time domain. It is defined as

CSE-304 DSP. Page 29


Comparing IFFT equation with the DFT equation definition, it can be seen that the
FFT algorithm (forward) described previously can be used to find the inverse FFT
(IFFT) with the two following changes:

1. Adding a scaling factor of 1/N

2. Replacing Wnkby its complex conjugate W nk

With the changes, the same FFT flow graphs can be used for the IFFT.

Lab Exercises

Exercise 8.1: Implement a 128-point radix-2 FFT of a real-time input sinusoid with
a frequency of 3 kHz and an approximate amplitude of 2V p-p. Use a sampling
frequency of 16kHz. Obtain a plot of the output and explain the results. What is the
output frequency when the input signal frequency is 6kHz and 10kHz? Explain.

Exercise 8.2: Implement a 256-point radix FFT on real time audio input. Use TIs
optimized FFT function.

CSE-304 DSP. Page 30


Faculty Member:____________________ Dated: ________________

Semester:_____________ Section: ________________

Department of Electrical Engineering

CSE-304 Digital Signal Processing


LABORATORY EXERCISE 7
Lab7: Z Transform

Name Reg. no. Report Viva Total/15


Marks / 10 Marks / 5

Lab7: Z Transform

Theory:

CSE-304 DSP. Page 31


We will start our investigation of the Z-Transform by looking at the mapping from the s-plane to
the z-plane which is developed during the derivation of the Z-Transform. We will look at the
properties of the transform itself in a separate example.
To aid in our study of this mapping from the s-plane to the z-plane, we will consider two specific
sinusoidal signals, X(t) and X2(t). The signals are given by
x1(t) = cos (2t)
x2(t) = cos (22t)
These two signals will be sampled with an ideal impulse sampler operating with a sampling
period T = pi/10 seconds. This corresponds to a sampling frequency ws = 20 r/s. One-half of the
sampling frequency is obviously Ws/2 = 10 r/s. You should recall that with ideal impulse
sampling, the value of the sampled signal x*(t) exactly equals the continuous-time signal x(t) at
sampling instants, t = nT, where n is an integer.
When we work with continuous-time signals & systems in the transform domain, we use the
Laplace Transform. This transform is a function of the complex variable s, which has a real part
(sigma) and an imaginary part (omega). The imaginary part, omega, is the variable which is the
frequency of sinusoidal signals, such as x1(t) and x2(t). The real part, sigma, is the variable
associated with the rate of decay of exponential signals.
When we work with discrete-time signals, we use a different transform, called the Z-Transform
(after LoftiZadeh). This transform is a function of the complex variable z, which also has real
and imaginary parts. However, with the Z-Transform, we generally are interested in the
magnitude and phase of z, rather than its real and imaginary parts. The z-plane is the complex
plane associated with the Z-Transform, just as the s-plane is the complex plane associated with
the Laplace Transform. When the Z-Transform is derived by sampling a continuous-time signal,
the complex variable z is defined in terms of the complex variable s by the following
expressions.
s = + j
z = esT = e( + j)T = e T . e jT
=|z| z

| z | = e T , z =T

With the definition of z = exp(sT), it can be easily seen that the magnitude of the complex
variable z is related to the real part of s (multiplied by T), and the phase of z is related to the
imaginary part of s (multiplied by T).

CSE-304 DSP. Page 32


We will begin our study of the mapping from s to z by looking at the s-plane. In the Figure 1,
note that the frequencies of the two signals x1(t) and x2(t) are shown, and that horizontal lines
corresponding to w = + Ws/2 and w = -ws/2 are also shown. When sampling a continuous-time
signal, that part of the s-plane between +ws/2 and -ws/2 is called the primary strip. Note the
distances from - ws/2 up to w1 and from + ws/2 up to w2.
When the real part of s is negative, the magnitude of z is less than 1. Therefore, the left-half of
the s-plane maps into the interior of a circle centered at the origin with radius = 1. When the real
part of s is positive, the magnitude of z is greater than 1. Therefore, the right-half of the s-plane
maps into the exterior of that same circle. When the real part of s is equal to zero (jw axis), the
magnitude of z equals 1. Therefore, the jw axis maps into the boundary of the circle. This circle
centered at the origin with radius= l is called the unit circle.
Thus, the definition of z in terms of s gives us a complex plane where the unit circle is the
important thing, and issues such as stability and frequency response will be dealt with in terms of
the unit circle rather than the jw axis. But there is even more to this mapping from s to z.
Realizing that T = 2*pi/ws, if we let frequency w in the s-plane be equal to -ws/2, we get a phase
angle for z of -pi radians. If we let w = +ws/2, we get a phase angle for z of +pi radians. If we let
sigma = 0, and let omega go from -ws/2 to +ws/2 in the s-plane, we get one complete revolution
in the z-plane from -pi to +pi radians, with unit magnitude. That is, we get the complete unit
circle. If sigma < 0, we get the complete interior of the unit circle as omega goes from -ws/2 to
+ws/2. The shame thing happens for sigma > 1 and the exterior of the unit circle.

Therefore, the primary strip in the s-plane maps into the entire z-plane. The same complete
mapping occurs for any horizontal strip in the s-plane which has a Height of ws r/s. Therefore,
the s-plane maps into the z-plane an infinite number of times. Unique points in the s-plane will
map into the same point in the z-plane due to this relationship between s and z.
Now we will look at the z-plane. In the next figure, the unit circle is shown. The interior of that
circle corresponds to the left-half of the s-plane, the exterior corresponds to the right-half of the
s-plane, and the circle itself corresponds to the jw axis. Note that the two distinct frequencies in
the s-plane, \v\ and w2, have mapped into the same point in the z-plane, namely their phase
angles are equal and their magnitudes are both equal to 1. The mapping of the two frequencies
into the z-plane is shown in the equations.
z = esT=> e jT= e j2/s
z1 = ej0.2 = 0.8090+j0.5878
z1 = ej2.2 = 0.8090+j0.5878
| z 1| = | z 2| =1 , <z1 = <z2 = 36

CSE-304 DSP. Page 33


From the figure of the s-plane (Figure 1), you could see that w1 and w2 have identical positions
relative to the bottom (or top or middle) of a strip in the s-plane which maps into the entire z-
plane. That is, the frequency w1 = 2 r/s is 12 r/s above the bottom of the primary strip, which
starts at ws/2 = -10 r/s, and the frequency w2 = 22 r/s is 12 r/s above the bottom of the next
strip, which starts at + ws/2 = +10 r/s. (An alternate view is: w1 is 2 r/s above 0 r/s, and w2 is 2 r/s
above ws = 20 r/s.) From the definition of z in terms of s, this means that the frequencies w1 and
w2 map into the same point in the z-plane. If the sampling frequency had been a different value,
the frequencies w1 and w2 would have mapped into distinct points in the z-plane. Therefore, the
value of the sampling period T (or sampling frequency ws) determines where on the unit circle
frequencies from the jw axis will end up.
What is the significance of the two continuous-time frequencies w1 and w2 mapping into the same
point in the z-plane? The answer is the two signals, x1(t) and x(t) have exactly the same values at
all sample times when the sampling period T - pi/10 seconds. That is, xi*(t) = x2*(t) at every
discrete point in time defined by nT. There is no way to tell one signal from the other based on
their samples. There is also no way to go back from the discrete-time samples to the continuous-
time signals.
Remember that the Fourier Transform of a sampled signal contains all the frequencies of the
continuous-time signal plus copies of those frequencies displaced by all integer multiples of the
sampling frequency ws, as shown in the following equation.

X*(j)= 1 X [ j(-ns)] = 1 X [ j(-ns)]
T n=- T n=-
The first few frequencies which appear in X1*(jw) (w1 = 2 r/s) when T = pi/10 s are:
[-42 -38 -22 -18 -2 2 18 22 38 42] r/s in the primary strip, -10 r/s to +10 r/s. Theoretically, the
signal x1 * (t) could be reconstructed from the sampled signal X]*(t) by using an ideal low-pass
filter.
The original frequencies +/- 2 r/s are there, and they are the only terms which appear
The first few frequencies which appear in X2*(j'w) (w2 = 22 r/s) when T = pi/10 s are:
[-62 -42 -22 -18 -2 -2 18 22 42 62] r/s
Here we see that the original frequencies +/- 22 r/s show up, but they are not in the primary strip.
The only frequencies which do appear in the primary strip are +/- 2 r/s, the frequencies of Xi(t)
not of X2(t). Therefore, if the discrete-time signal X2*(t) was passed through an ideal low-pass
filter with a bandwidth of \vs/2 = 10 r/s, the signal that would be reconstructed would be x1 (t)
instead of x2 (t).

CSE-304 DSP. Page 34


Points in the s-plane from outside the primary strip become indistinguishable from points in the
primary strip when mapped into the z-plane. This is the reason why a continuous-time signal
must be sampled at a frequency greater than twice the highest frequency in the signal if it is to be
recoverable from its samples. The next figure (Figure 3) shows the two continuous-time signals
with their sampled values with T = pi/10 seconds.

Figure 1

Figure 2

CSE-304 DSP. Page 35


Figure 3

Equivalency between Z-transform and the DTFT



X(z) = x[n] z-n and

n=-

X() = x[n] e-jn
n=-
Simply replace Z with ejw in Z-transform to get the frequency response.

CSE-304 DSP. Page 36


Putting z = ejo} (i.e. evaluating Z transform along a unit circle) we can find DTFT. For a system
to be stable and causal all poles should lie inside the unit circle.

MATLAB Commands Related with Z Transform


[H , ] = freqz (B, A, N);
[H,T] = impz(B,A,N)
zplane(z,p);
[z, P, k] = tf2zp(B,A);
[B,A] = zp2tf(z,P,k);
[R,P,K]= residuez(B,A);

Lab Exercises:
Problem 1:
i) H(z) = z-1
3-4z-1 + z -2
ii) ) H(z) = 1 + 0.42 z-1
1 0.8 2z-1 + 0.64z -2
a) Evaluate and plot the z-transform on unit circle, i.e. find H(ej) 0 2.

b) Locate and plot the zeros and poles


c) Determine the inverse z-transform of H(z) .i.e. find impulse response.
d) Find the partial fraction expansion.
e) Find the radii of all poles and zeros.

CSE-304 DSP. Page 37


Faculty Member:____________________ Dated: ________________

Semester:_____________ Section: ________________

Department of Electrical Engineering

CSE-304 Digital Signal Processing


LABORATORY EXERCISE 8
Lab8: IIR DIGITA: FILTER DESIGN

Name Reg. no. Report Viva Total/15


Marks / 10 Marks / 5

Lab8: IIR DIGITA: FILTER DESIGN

First Order LowPass IIR Filter

H(z) = b(1+ z-1) / (1 - az-1)

CSE-304 DSP. Page 38


c= (fc / fs) 2

Gc= 10 Ac/20

= (Gc/ 1- Gc2 )tan(c/ 2)

a= ( 1- ) (1+ ); b= /(1+ )

Problem 1:

Given fs, fc and Ac , design first order IIR filter,

fs= 10000

(i) fc= 1000, Ac =3dE


(ii) fc = 1000, Ac =0.46db

(Plot frequency response of (i) and (ii) in the same figure)

(iii) fc =3500, ^c-3dB


(iv) fc =500, Ac=OA6dB

(Plot frequency response of (iii) and (iv) in the same figure)

First Order HP Filter

Problem 2:

H(z) = b (1 - z-1 )
1 - az-1

Gc= 10 Ac/20

= (Gc/ 1- Gc2 )tan(c/ 2)

a= ( 1- ) (1+ ); b= /(1+ )

(i) fc = 1000, Ac =3dB


(ii) fc = 1000, Ac =0.46dB

(Plot frequency response of (i) and (ii) in the same figure)

(iii) fe = 3500 , A c=3dB

CSE-304 DSP. Page 39


(iv) fc = 3500 , Ac = 0.46 dB

(Plot frequency response of (iii) and (iv) in the same figure)

Complementary Nature Of LP and HP Filter

Problem 3:
For fs 10000 , fc = 1 kHz, Ac = 3 dB
i. Design a lowpass filter and plot frequency response,
ii. Design highpass filter and plot frequency response,
iii. Find and plot the sum of frequency responses of LP and HP filters.

(All plots should be in the same figure)

Notch IIR Filter Design


Problem 4:

H(z) = b (1 - 2cos0 z-1 + z-2 )


1-2cos0 z-1 + (2b-1) z-2

= (1-GB2 / GB tan(/2)

GB = 10-AB/ 20

b= 1
1+
Find H(z) and plot its frequency response.

fs = 10kHz

i. f0 = 1.75 kHz; f =500 Hz f0=3dB


ii. f0 =1.75 kHz; f =500 Hz AB =10dB

iii. f0= 1.75 kHz; f = 100 Hz AB = 3 dB


iv. f0=1.75 kHz; f = 100 Hz AB = 10dB

Peaking / Resonator IIR Filter Design


H(z) = (1- b) (1 - z-2 )
1-2cos0 z (2b-1) z-2
-1 +

= (1-GB2 / GB tan(/2)

b= 1

CSE-304 DSP. Page 40


1+

Problem 5:
Find H(z) and plot its frequency response.

fs = 10kHz

i. f0 = 1.75 kHz; f =500 Hz f0=3dB


ii. f0 =1.75 kHz; f =500 Hz f0 =10dB
iii. f0= 1.75 kHz; f = 100 Hz f0 = 3 dB
iv. f0=1.75 kHz; f = 100 Hz f0 = 10dB

Complementary Nature Of Peaking And Notch

Problem 6:
For fs = 10kHz , f0 = 1.75kHz, f = 500 kHz, AB =3dB

a) Design a notch filter for above parameters and plot the frequency response.
b) Design a resonator filter for above parameters and plot the frequency response.
c) Add the frequency response of notch and resonator and plot it.

(All three plots should be in the same figure)

CSE-304 DSP. Page 41


Faculty Member:____________________ Dated: ________________

Semester:_____________ Section: ________________

Department of Electrical Engineering


CSE-304 Digital Signal Processing
LABORATORY EXERCISE 9
Lab9: FILTER DESIGN USING ANALOG PROTOTYPING

Name Reg. no. Report Viva Total/15


Marks / 10 Marks / 5

Lab9: FILTER DESIGN USING ANALOG PROTOTYPING

CSE-304 DSP. Page 42


Introduction
The traditional approach to design IIR digital filters involves the transformation of an analog
filter into a digital filter meeting prescribed specification because
1. The art of analog filter design is highly advanced and since useful results can be achieved,
it is advantageous to utilize the design procedures already developed for analog filters
2. Many useful analog design methods have relatively simple closed-form design formulas.
Therefore digital filter design methods based on such analog design formulas are rather
simple to implement.
3. In many applications it is of interest to use a digital filter to simulate the
performance of an analog linear filter

Methods of Analog-digital transformation


1. Impulse Invariance
One method of transforming an analog filter design to a digital filter design corresponds to
choosing the unit sample response of the digital filter as equally spaced samples of impulse
response of the analog filter. That is

h(n) ha (nT )

2. Bilinear Transform
The bilinear transformation is a mathematical mapping of variables. In digital filtering, it is a
standard method of mapping the s or analog plane into the z or digital plane. It transforms analog
filters, designed using classical filter design techniques, into their discrete equivalents.
The bilinear transformation maps the s-plane into the z-plane by

21 z 1
s
T 1 z 1

Butterworth Filter

CSE-304 DSP. Page 43


Butterworth filters are defined by the property that the magnitude response is maximally flat in
the passband. Another property is that the approximation is monotonic in the passband and the
stopband.
The squared magnitude of Butterworth filters is of the form:
The squared magnitude of Butterworth filters is of the form:

The squared magnitude of Butterworth filters is of the form:


2 1
H a ( j)
1 ( j / j c ) 2 N

Chebyshev Type I Filter


The Chebyshev type I filter minimizes the absolute difference between the ideal and actual
frequency response over the entire passband by incorporating an equal ripple of Rp dB in the
passband. Stopband response is maximally flat. The transition from passband to stopband is more
rapid than for the Butterworth filter.

CSE-304 DSP. Page 44


Chebyshev Type II Filter

The Chebyshev type II filter minimizes the absolute difference between the ideal and actual
frequency response over the entire stopband, by incorporating an equal ripple of Rs dB in the
stopband. Passband response is maximally flat. The stopband does not approach zero as
quickly as the type I filter (and does not approach zero at all for even-valued n).
The absence of ripple in the passband, however, is often an important advantage.

Elliptic Filter
Elliptic filters are equiripple in both the passband and stopband. They generally meet filter
requirements with the lowest order of any supported filter type. Given a filter order n, passband
ripple Rp in decibels, and stopband ripple Rs in decibels, elliptic filters minimize
transition width.

Squared magnitude of elliptic filters can be estimated by the following equation:

2 1
H a ( j )
1 U N 2 ()
2

where UN( ) is a Jacobian elliptic function.


Lab Exercises:

CSE-304 DSP. Page 45


Problem 1:

Use help command to learn the use of following commands:

butter, buttord, chebyl, cheblord, cheby2, cheb2ord, ellip, ellipord

Problem 2:

(i) Generate 100 samples of the following signal


x(t) = cos (
1 1
2 10t cos( 2 30t ) cos( 2 50t )
3 5

(fs=200)
Plot the DTFT of above signal
(ii) Remove the lowest frequency component of signal using all above mentioned filters. Use
freqz to plot the frequency response of filters used. Plot input and output signals.
(iii) Repeat part (ii) to remove intermediate frequency component
(iv) Repeat part (ii) to remove the highest frequency component
(Save the result as fig files, as u will be needing these results in next lab for comparison
(purpose)
Problem 3
Comment on the results obtained by using different filters(phase-linearity, transition bandwidth,
filter order requirement for achieving the same performance)

CSE-304 DSP. Page 46


Faculty Member:____________________ Dated: ________________

Semester:_____________ Section: ________________

Department of Electrical Engineering

CSE-304 Digital Signal Processing


LABORATORY EXERCISE 10
Lab10: LINEAR PHASE FIR FILTER DESIGN BASED ON
WINDOWS

Name Reg. no. Report Viva Total/15


Marks / 10 Marks / 5

CSE-304 DSP. Page 47


Lab10: LINEAR PHASE FIR FILTER DESIGN BASED ON
WINDOWS

Theory
Frequency of an ideal low-pass filter is

H ( ) c c
= 1,
0, otherwise
Its impulse response is given by

h (n) c
= , k=0

sin( c k ) k
, otherwise
Causal FIR Filters can be obtained by
Truncating the impulse response of the ideal filter to make its length finite.
And shifting the truncated response to make it causal.
The process introduces phase delay (linear with frequency) and ripples in passband and
stopband. The reason behind this phenomenon can be explained by considering the truncation
operation as multiplication by a finite-length window sequence w [n] and by examining the
windowing process in the frequency domain. Thus, the FIR filter obtained by truncation can be
alternatively expressed as

h1 [n] hd [n].w[n]

From the modulation theorem, the Fourier transform of the above equation is given by

H t (e ) 1 / 2 H d (e j ) (e w ) d
jw

CSE-304 DSP. Page 48


jw jw
1 [ n]
where Ht (e ) and (e ) are the Fourier transforms of h and w[n], respectively. The
jw
1
above equation implies that H (e ) is obtained by a periodic continuous convolution of the
d
jw jw

desired frequency response H (e ) with the Fourier transform. (e ) of the window. The

process is illustrated in the following figure with al! Fourier transforms shown as real functions
for convenience.

jw

From the last equation, it follows that if (e ) is a very narrow pulse centered at ~M<n<M
jw
d
(ideally a delta function) compared to variations in H (e ), then
jw jw

Ht (e ) will approximate Hd (e ),very closely. This implies that the length 2M + 1 of the
window function co[n] should be very large. On the other hand, the length 2M + 1 of ht[n] , and
hence that of w[n] , should be as small as possible to make the computational complexity of the
filtering process small.

CSE-304 DSP. Page 49


In order to impart desired properties to the filter response, we will discuss some commonly used
tapered windows of length 2M + 1, which are
(a) Hanning

1 2n
w[n] 1 cos
2 N 1 0 n N 1

b Hamming

2n
w[n] 0.54 0.46 cos
N 1 0 n N 1

c Blackman
2n 4n
w[n] 0.42 0.5 cos 0.08 cos
N 1 N 1 0 n N 1

d Kaiser


2 2
N 1 N 1
I a n


2 2
w[ n]
N 1
I a
2

Where
2
1 x k
I ( x) 1
k 1 k! 2

CSE-304 DSP. Page 50


To understand the effect of the window function on FIR filter design, we show in the following
figure a typical relation among the frequency responses of the windowed lowpass filter, the
window function, and the desired ideal lowpass filter, respectively.

Relations among the frequency responses of an Ideal lowpass filter, a typical window, and
the windowed filter.
Since the corresponding impulse responses are symmetric with respect to n = 0, the frequency
responses are of zero-phase. From this figure, we observe that for the windowed filter,
H t (e jwc ) H t (e jwc ) 1 c H t (e jwc ) 0.5
, around the cutoff frequency w . As a result, .
Moreover, the passband and stopband ripples are the same. In addition, the distance between
locations of the maximum passband deviation and minimum stopband value is approximately
ML c
equal to the width of the main lobe of the window, with the center at w . The width of the
w wx w p ML
transition band, defined by , is less than . Therefore, to ensure a fast
transition from the passband to the stopband, the window should have a very small main lobe

width. On the other hand, to reduce the passband and stopband ripple , the area under the side
lobes should be very small. Unfortunately, these two requirements are contradictory
In the case of the window functions of above equations (Hann, Hamming, Blackman), the

value of the ripple does not depend on the filter length, or the cutoff frequency wc, and is
essentially constant. In addition, the transition bandwidth is approximately given by

w c
M

where c is a constant for most practical purposes.


The following table summarizes the essential properties of some of the above window functions.

CSE-304 DSP. Page 51


Type of Main Relative Min. Transition
window Sidelobe Stopband Bandwidth
Lobe Width Level attenuation

ML Asl

Rect. 4 (2 M 1) 13.3 dB 20.9 dB 0.92 M

Hann. 8 (2M 1) 31.5 dB 43.9 dB 3.11 M

Hamm. 8 (2M 1) 42.7 dB 54.5 dB 3.32 M

Blackman 12 (2 M 1) 58.1 dB 75.3 dB 5.56 M

c
(Values shown in the table are for w =0.4 and M=128)

Faculty Member:____________________ Dated: ________________

Semester:_____________ Section: ________________

Department of Electrical Engineering

CSE-304 Digital Signal Processing


LABORATORY EXERCISE 11
Lab11: INTERPOLATION AND DECIMATION

CSE-304 DSP. Page 52


Name Reg. no. Report Viva Total/15
Marks / 10 Marks / 5

Lab11: INTERPOLATION AND DECIMATION


Theory

Decimation
Decimation is the process of reducing the sampling rate by an integer factor, M. In the discrete
time domain, decimation of a signal x by M is performed by discarding all but every M-th
sample of x. If we denote the decimated signal by xj, it follows that

x d ( K ) x( MK )

In other words only every M-th sample of the original signal is retained.

Suppose we have a sampled version of an analog signal which has a sampling rate which is too
high. This can arise for a number of reasons. For instance, the data may have been sampled by a
data acquisition system which has a fixed sampling rate. For reasons of data storage or real time
bandwidth requirements, it may be necessary to lower the sampling rate of the system. On
solution is to convert the signal back to analog and then resample at the new rate. Another
solution, which is much more practical, is to perform the sampling rate conversion in the
discrete time domain.

CSE-304 DSP. Page 53


The spectrum of the decimated signal consists of a sum of frequency- scaled and shifted copies
of X(co), as shown in figure:

It is clear from the figure that frequency spectrum is expanded by M. Since effectively we are
reducing sampling rate, it is necessary to filter the signal before decimation with a cutoff
frequency of 7T/M, because the frequency components with frequency greater than 7T/M will cause
aliasing.

So process of decimation can be summarized by the following block diagram:

Interpolation

Interpolation is the inverse operation of decimation. By interpolation, we are trying to generate


intermediate samples of a discrete time signal, x(k). This corresponds to increasing the
sampling rate. One approach to interpolation would be to reconstruct the analog signal and then
convert it into digital with the new sampling rate. This does not need to done, however.
Interpolation can be performed entirely in the discrete time domain.

e
Given an interpolation rate which is an integer M, define the signal x (k) by

CSE-304 DSP. Page 54


e
x (k)= k = 0,1,2,... otherwise

The resultant signal is derived from x(k) by zero-filling, which is also known as sampling rate
expanding.

The impact of zero-filling in frequency domain is compression of DTFT and filtering is required
to remove the high frequency components introduced due to compression of the spectrum, as
evident from the figure given below,

So the process of interpolation can be described by the following block


diagram:

CSE-304 DSP. Page 55


Non-Integer Sampling Rate Changes
We have already seen how to increase or decrease the sampling rate of a discrete time signal by
in integer factor. There are situations where it is necessary to change the sampling rate by a non-
integer factor. For instance, compact disc (CD) and digital audio tape (DAT) are based on
different sampling rates. If we wish to perform a CD to DAT transfer, the record companies
would prefer that it be done by CD-to-analog followed by analog-to-DAT, resulting in a loss of
audio fidelity. Instead, we will show the sampling rate conversion can be performed entirely in
discrete time domain.
Because the ratio of two sampling rates will always be rational, it is not restrictive to consider
only the case where the sampling rate must be changed by a rational number. Thus, suppose we
wish to change the sampling rate from T to T(M/L) this can be accomplished in two steps. First
the sampling rate is converted from T to T/L by interpolation. This consists of expanding the

signal by L followed by filtering with a low pass filter with cutoff frequency of /L. Next, the
signal with sample rate T/L is decimated by M. This is performed by first filtering the signal

through a low pass filter with cutoff frequency /M and then retaining
only every M-th sample. The net result will be a signal whose sampling rate is T(M/L). The
procedure is shown in
figure:

Clearly we can replace the two filters with a single filter, as shown in figure:

CSE-304 DSP. Page 56


Lab Exercises:

Problem 1:

a. Generate 32 samples of following


signals

1 (t ) 1
i. x

x 2 (t ) sin( 2 * 50 * t ) s 100
ii. (f )
b. Plot the signal and their DFTs. (use FFT and scale the x axis from 0 to 2)

c. Interpolate the signals (N=2). Repeat part b for the interpolated signals. Observe and
comment on the impact of interpolation in time domain and frequency domain

d. Construct filter for the interpolated signals. Filter the signals and observe the filtered
signals in both time and frequency domains

e. Comment on effect of filtering on the interpolated signals.

Problem 2:

a. Generate 32 samples of following signals

i. xl (t) =square wave of frequency 25

Hz. (fs = 100) (do not use antialiasing filter)

b. Plot the signal and their DFTs. (use FFT and scale the x axis from 0 to 2)

c. Decimate the signals (N-2). Repeat part b for the decimated signals. Observe and comment
on the impact of decimation in time domain and frequency domain

d. Indicate the signal for which it is necessary to filter the signal before decimation

e. Design filter which should be used before decimation in this case.

f. Repeat part c after filtering the original signals.

CSE-304 DSP. Page 57


g. Comment on results obtained in part c and part f.

Problem 3:

Change the sampling rates of signals given in Problem 2 to 75 Hz.

CSE-304 DSP. Page 58


Faculty Member:____________________ Dated: ________________

Semester:_____________ Section: ________________

Department of Electrical Engineering

CSE-304 Digital Signal Processing


LABORATORY EXERCISE 12
Lab12: THE POLYPHASE DECOMPOSITION

Name Reg. no. Report Viva Total/15


Marks / 10 Marks / 5

CSE-304 DSP. Page 59


Lab12: THE POLYPHASE DECOMPOSITION
The M-component polyphase decomposition provides a convenient representation of X(z) which
will be very useful when discussing decimation, interpolation, and changing the sampling rate by
non-integer ratio.
Suppose x is a signal with Z-transform

X (z )

x( k ) z
k
k

Our end goal is to find a convenient expression for the Z-transform of 'x' when the sampling rate
is either increased or decreased by a factor of M. As a first step, we can break the signal into a
disjoint collection of elements whose indices are separated by M. To this end, rewrite X(z) as
X(z) =
x(0) x( M ) z M x(2M ) z 2 M

z 1 ( x (1) x ( M 1) z M x( 2 M 1) z 2 M )

z 2 ( x( 2) x ( M 2) z M x( 2 M 2) z 2 M )

z ( M 1) ( x( M 1) x(2 M 1) z 2 M x(3M 1) z 3 M )

We next proceed by factoring z~' from the i-th row of the above set of equations, which gives

X(z) =
x(0) x( M ) z M x(2M ) z 2 M

z 1 ( x (1) x ( M 1) z M x( 2 M 1) z 2 M )

z 2 ( x( 2) x ( M 2) z M x( 2 M 2) z 2 M )

CSE-304 DSP. Page 60


z ( M 1) ( x ( M 1) x (2 M 1) z 2 M x(3M 1) z 3 M ) (1)

The i-th row of this expression can be written as


z-i

x(kM i)( z
k
M
) k

The summation in the above equation is simply the Z-transform of the elements of 'x' which are
separated by M. If we define the polyphase component Pi(z)by
Pi(z) =

x(kM i)( z
k
M
) k

and substitute into the last equation, we have


z-i = z-iPiZM)

x(kM i)( z
k
M
) k

Finally, from equation (1), we have


X(z)= P0(zM) + z-1P1(zM) + z-2P2(zM) + . + z-(M-1)PM-1(zM)
Which gives the M-component polyphase decomposition
X(z) =

Z
k
-1
Pi (Z M )

Implementation of the equation can be described by the following figure:

CSE-304 DSP. Page 61


Polyphase Structures for Decimation
Consider the FIR decimation system shown in following figure.

This system consists of an FIR of length N followed by a decimator of rate M. the system only
needs to compute the output samples y(kM). Because the FIR precedes the decimator, however,
we require that N multiplications be performed during the clock cycle when y(kM) is being
computed in order to maintain real-time data flow. During the other clock cycles, the system is
idle. This is clearly a waste of computational resources. This problem can be rectified in and
elegant and simple manner using the polyphase decomposition.
Let H(z) be a rational transfer function. Consider the two systems in the following figure.

The first of these systems consists of s decimator of rate M followed by H(z). The second system
consists of H(zM) followed by a decimator of rate M. We can prove that these systems are
equivalent.

Clearly, the first system in the above figure is more efficient than the second. The transfer
function H(zM), although of higher degree than H(z), will have the same number of nonzero
coefficients as H(z). Thus, H(zM) requires the same number of multiplications per cycle as H(z).
Notice, however, that the data rate is much higher for the configuration in which filtering is
performed before decimation. If the filter is preceded by the decimator, the data arrives at the
filter at a data rate which is M times slower.

To see how this result can be used to derive an efficient structure for decimation, assume we wish
to filter by H(z) and then decimate by M. Hence, H(z) has a polyphase decomposition given by

CSE-304 DSP. Page 62


M 1
H ( z) z
i 0
1
H i (z M )

Thus, one possible structure for the decimation/filtering system is given in the following
figure.

An equivalent structure can be built using the identity we just mentioned: filtering by HJ(ZM) then
decimating by M is equivalent to decimating by M then filtering by H i(z). Therefore, we can
replace the polyphase filters Hi (ZM) with the filters Hi (Z) and decimate after the filters, as shown in
figure shown below:

When H(z) is FIR of length N, the polyphase components will each have at most N/M nonzero
multiplications so that the new architecture will require total of (N/M)M = N multiplications per
output sample. However, the input to the filters arrives at 1/M the clock speed. Thus, the
computational complexity has been reduced by a factor of M.

Polyphase Structures for Interpolation

CSE-304 DSP. Page 63


Just as with decimation, the polyphase representation may be used to reduce the computational
complexity of interpolation. It is simple to show that the systems in the following figure have the
same input output behavior.

(Fig. equivalent systems for interpolation)

According to the equation Xe(ej )=^X(ejM ), if the input to the sample-rate expander of the first

system is {x(k)}, the output of the expander has Z-transform X(z M). Thus, the output of the first
system has the Z-transform H(zM)X(zM). Examining the second system, the output of the filter is
H(z)X(z), and again according to the above equation, the output of the expander is given by
H(zM)X(zM). Therefore, the two systems are equivalent.
Consider the problem of implementing interpolation in practice. Our theoretical model was to
first expand the signal by M by zero-filling and then lowpass filtering at the increased sampling
rate T/M. If the lowpass filter is an FIR of length N, each output sample of the filter requires N
multiplications per T/M units of time. For even modest interpolation rates and FIR lengths, this
may not be possible using affordable (or even existing) hardware. Fortunately, the polyphase
representation can be used to lessen the computational complexity of the interpolator.

CSE-304 DSP. Page 64


This time, the transposed polyphasedecomposition can be used to realize an efficient structure for
interpolation. The following figure shows the sampling rate expander prior to the transposed
polyphase network:

This model requires N multiplications per T/M seconds. Instead, the sampling rate expander can
be moved to the right of the polyphase. This is shown in the following figure:

In this network, each polyphase filter requires N/M multiplications per T seconds, for a total of N
multiplications per T seconds. This represents a reduction in complexity by a factor of M.
Lab Exercise
Repeat the problems of previous lab using polyphase filters.

CSE-304 DSP. Page 65


Faculty Member:____________________ Dated: ________________

Semester:_____________ Section: ________________

Department of Electrical Engineering

CSE- 304 Digital Signal Processing


LABORATORY EXERCISE 13
Lab13: PERIODIC WAVE GENERATORS

Name Reg. no. Report Viva Total/15


Marks / 10 Marks / 5

CSE-304 DSP. Page 66


Lab13: PERIODIC WAVE GENERATORS

Introduction

It is often desired to generate various types of waveforms, such as periodic square waves,
sawtooth signals, sinusoids, and so on. A filtering approach to generating such waveforms is to
design a filter H(z) whose impulse response h(n) is the waveform one wishes to generate. Then,
sending an impulse as input will generate the desired waveform at the output.

Sinusoidal &Cosinusoidal Generators

The above filtering approach can be used to generate a (causal) sinusoidal signal of frequency fo
and sampled at a rate fs. Denoting the digital frequency by

0 2f 0 fs

We have the z transform pair


h(n) = Rnsin(
0 n )u ( n )

R sin 0 z 1
H ( z)
1 2 R cos o z 1 R 2 z 1

And,

h(n) = Rncos(
0 n )u ( n )

1 R cos 0 z 1
H ( z)
1 2 R cos o z 1 R 2 z 2

Dual Tone Multi Frequency n Generator

CSE-304 DSP. Page 67


A common application of sinusoidal generators is the all-digital touch-tone phone, known as
Dual-Tone Multi-frequency (DTMF) transmitter/receiver. Each key-pressed on the key pad
generates the sum of two audible sinusoidal tones, that is. the signal

y(n) = cos ( n) +cos( n)


L H

where the two frequencies uniquely define the key that was pressed. Following figure shows the
pairs of frequencies associated with each key.

1209 1336 U77 1633

The particular values of the 8 keypad frequencies have been chosen carefully so that they do not
interfere with speech. At the receiving end, the dual-tone signal y(n) must be processed to
determine which pair of frequencies is present. This can be accomplished either by filtering y(n)
through a bank of band pass filters tuned at the 8 possible DTMF frequencies or by computing the
DFT of y(n) and determining which pairs of frequency bins contain substantial energy.
Periodic Generators

Suppose we have to generate a repeating sequence


{b0, b1,, bD-1, b0, b1,', , bD-1, b0, b1, , bD-1,..}
Using the filtering approach just described above we can accomplish this task. Such a
filter must have the impulse response:
h= {b0, b1,, bD-1, b0, b1,', , bD-1, b0, b1, , bD-1,..}
The required impulse response is shown in the following figure:

CSE-304 DSP. Page 68


The following filter has the required impulse response:

b0 b1 z 1 b2 z 2 ... bD 1 z 1( D 1)
H ( z)
1 z D

Lab Exercises:
Problem 1:
i) Plot the impulse response of a sinusoidal generator with fo = 400 and fs= 8 kHz.
(length =400 samples)
ii) Cosinusoidal generator with f0 =800 and fs= 8 kHz (length = 400 samples)

Problem 2:

Implement a function dtmf-gen which should generate a DTMF for the digits 1-9
(length=2000 samples).

function[result, n] = dtmf(key);

Problem3:
Given the dtmf, write a function which should decode the dtmf to an appropriate key.
(Hint: Use dtft to detect ranges)
Range of f-30 Hz to f+30 Hz.

CSE-304 DSP. Page 69


function detect (dtmf, n)

Problem4:
(i)
1 2 z 1 3z 2 4 z 3
H ( z)
1 z 4

Plot the impulse response for this function. (12 samples)


(ii) Evaluate the T.F of the following impulse response.

Implement a filter to produce the waveform.


Plot the impulse response of the following T.F.

1 2 z 1 3 z 2 4 z 3
H ( z)
1 0 .5 z 4

(iv) Plot the impulse response of the following T.F.

1 0.5 z 1 2 z 2 3z 3
H ( z)
1 z 3

CSE-304 DSP. Page 70


Faculty Member:____________________ Dated: ________________

Semester:_____________ Section: ________________

Department of Electrical Engineering

CSE- 304 Digital Signal Processing


LABORATORY EXERCISE 14
Lab14: NOISE REDUCTION AND SIGNAL ENHANCMENT

Name Reg. no. Report Viva Total/15


Marks / 10 Marks / 5

CSE-304 DSP. Page 71


Lab14: NOISE REDUCTION AND SIGNAL ENHANCMENT
Introduction

This lab concerns with removing the additive noise out of the signal. If the noise is additive, then
the noised signal can be represented as;

x[n] = s[n]+ v[n]

where s[n] is signal and v[n] is noise. There are two possibilities:

i) When the frequency spectrum of the desired signal and noise do not overlap.

It is easy to extract the desired signal using filtering, as shown in figures:

noise .spectrum
Signal
spectrum

Spectrum of noised signal before filtering

CSE-304 DSP. Page 72


ii) When the frequency spectrum of the desired signal and noise overlap.
In this case we could either block the noise to the maximum but get a distorted desired signal or
get an undistorted desired signal at the expense of added noise.
In practice, ideal filters with such sharp edges are not realizable.
Two parameters are in practice
i) Transient Response
ii) Delay
As the pole approaches 1, the transition becomes sharper but introduces a delay in the output.

ln E
eff
ln a a 1
as
First Order IIR Smoother (Low Pass)
b
H ( z)
1 az 1

1 a
NRR NRR aNRR 1 a
1 a

1 NRR
a
1 NRR

NRR<1 since 0<<1

H ( z ) | w0 1 b 1 a
For

CSE-304 DSP. Page 73


Hish Pass TIR Smoother
b
H ( z)
1 az 1

H ( z ) | w H ( 1) 1 b 1 a
for

1 a
NRR
1 a

IIR Smoother with Prescribed Cutoff Frequency

b(1 z 1 )
H (z)
1 az 1

1 a 1 sin wc
b a
2 cos wc
and
Lab Exercises
Problem 1:

Generate s[n]= 5 (400 samples)

v[n]=0.2*randn(1,400)

Design a low pass IIR smoother. Input parameters are NRR. Apply this filter to x[n] to get y[] .
Plot y[n] , x[n]

Plot on the same figure

i) NRR-0.05 ii) NRR-0.01


Problem 2:
Generate a high frequency signal
^

s[n] = (-1) 5
x[n] = s[n] + v[n]

CSE-304 DSP. Page 74


Design a high pass IIR smoother
i) NRR=0.05 ii) NRR=0.01


Wc
8
Problem 3:Use IIR smoother with cutoff frequency and x(n) same as Problem 1. Plot
y(n)

Faculty Member:____________________ Dated: ________________

Semester:_____________ Section: ________________

Department of Electrical Engineering

CSE- 304 Digital Signal Processing


LABORATORY EXERCISE 15

Lab15: ADAPTIVE FILTERING

Name Reg. no. Report Viva Total/15


Marks / 10 Marks / 5

CSE-304 DSP. Page 75


CSE-304 DSP. Page 76
Lab15: ADAPTIVE FILTERING

The Widrow-Hoff LMS Adaptive Algorithm

If the filter is h, then


h(n+1) = h(n) + 2
e n y n

for the simplest case: 'h' has a single coefficient.

error

Algorithm
1) At time n, h(n) is available
2) Compute the filter output =h(n)yn

xn

3) Compute the estimated error



en x n x n

CSE-304 DSP. Page 77


4) Compute the weight h(n+1) = h(n) + 2
e n y n

5) Go to next time instant n > n + 1


Will have to use for-loop

Problem 1:

y = 0.1 * randn(1,200)
x=-0.8yn + yn

(a) = 0.3

(b) =0.1

(i) Implement the LMS ALGORITHM for a single co-efficient of h'. function [e,h] =
LMS(x8,y,mu)

(ii) Plot the error and the vector corresponding to the value of 'h' at every iteration.

Adaptive Linear Combiner

CSE-304 DSP. Page 78


Algorithm

1) = h0 (n)y0 (n) + .. hm(n)ym(n)



xn

2)

en xn x n

3) hm(n+1) = hm(n) + 2 (n)


en y m

0mM

Problem 2:
You are given _y0[n]..y2 [n] Generate while Gaussian noises y0, y1 ,y2
x=-0.8y0 + 0.1y1 - 0.2y2

Implement the function for linear combiner function

[e, h0, h1, h2 ] = lc(x, y0,yly2, mu)

mu = 0.1

CSE-304 DSP. Page 79


i) plot error and h0 , h1, h2

Code

Function [e, h0, h1, h2 ] = lc(x, y0,yly2, mu)

h0 = zeros ( 1, length ( y0 +1))

h1 = zeros ( 1, length ( y1 +1))

h2 = zeros ( 1, length ( y2 +1))

e = zeros ( 1, length ( y0 ))
for i=0:length (yo)
x - hat = hQ(i)yo(i) + h1(i) y1 (i) + h2(i) y2 (i)
e(i) = x(i) x- hat
h0(i + 1) = h0 (i) +2 *
* e(i ) * y o (i )

h1(i + 1) = h1 (i) +2 *
* e(i ) * y1 (i )

h2(i + 1) = h2 (i) +2 *
* e(i ) * y 2 (i )

Adaptive Fir Wiener Filter

CSE-304 DSP. Page 80


for this case
hm(n + 1) = hm(n) + 2 (n - m)
en y

Vector Form
H(n+1) H(n) + 2 Y(n)
en

where Y(n) is the vector of the delay line.


Implement this delay line
Y(n) = [y(n) * y(n-1) * y(n-2) * y(n-3) ..]
h-un = rand(1256);
y=randn(1,1000,3);
x=filter (h-un,1,y);
then implement the function
function [e,h] = adaptive_fir(y,x,mu)
h=zeros(1,256);
e=zeros(1,length(y))
x-hat=zeros(1,length(y))
y-delay=zeros(1,256)
for i=1:length(y)
y-delay=[y(i)y delay(1:length(y-delay))]

x-hat(i)=h*y-delay
e(i) =x(i) x-hat(i)
h=h+2
* e(i ) * y delay

end

CSE-304 DSP. Page 81


Problem 1:

Implement the LMS adaptive algorithm on FIR filter of length 256.

h-un = rand(1,256)

y = randn(l,1000,3)

Plot the error signal for = 0.1


Faculty Member:____________________ Dated: ________________

Semester:_____________ Section: ________________

CSE-304 DSP. Page 82


Department of Electrical Engineering

CSE- 304 Digital Signal Processing


LABORATORY EXERCISE 16

Lab16: DEMONSTRATION OF REAL-TIME SIGNAL


PROCESSING

Name Reg. no. Report Viva Total/15


Marks / 10 Marks / 5

Lab16: DEMONSTRATION OF REAL-TIME SIGNAL


PROCESSING
Introduction

CSE-304 DSP. Page 83


So far we have designed and simulated different digital filters and some applications of digital
signal processing. Digital signal processing does not end here; rather the practical work begins
from here. These filters are implemented in DSP boards and computers (if application has
nominal computational burden) using programming languages like assembly and C++.

The purpose of this lab is to get the students acquainted with real time signal processing by
demonstrating implementation of different filters, by using custom-developed data acquisition
system and computer software.

The objectives of this lab are to demonstrate

occurrence of aliasing due to insufficient sampling rate

effect of placement of poles and zeros

implementation of notch filter, resonator, first order filters, second order filters

implementation of IIR filters based on classical analogue filters

implementation of linear phase FIR filters based on window

effect of phase non linearity and phase linearity on distortion ofthe filtered signal

application of smoothers for noise reduction

Acknowledgement
CSE-304 DSP. Page 84
References

1. Digital Signal Processing

CSE-304 DSP. Page 85


Alan V. Oppenheim , Ronald W. Schafer
2. Signals and Systems (2nd Edition)
Alan V. Oppenheim , Alan S. Willsky , with S. Hamid
3. Digital Signal Processing
SanjitMitra

CSE-304 DSP. Page 86

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