Professional Documents
Culture Documents
prepared by
and
January 2009
Preface
This DSP Lab Manual is designed for the 7th semester students of Department of Elec-
trical Engineering, session 2009. Following are the prerequisites for the labs.
• DSP First
• C/C++ Programming
The lab manual is an extension to the labs attended in DSP First course of the 5th
semester. Here, it is assumed that the student following these labs is good at DSP First and
has knowledge of basic MATLAB and Simulink operations. C/C++ programming techniques
are required for programming the ADSP-BF5xx Blackfin Processors in VisualDSP++. The
students are advised to obtain a copy of the following.
• MATLAB 7 or higher
• VisualDSP++ 4.5
• C/C++ (optional)
The labs will be carried out by first simulating the objective in MATLAB and/or
Simulink and then implementing the same procedures in the DSP kit. The code for the
labs is not given in the manual but the students are guided to perform the procedures, in
order to encourage them using their own thoughts and ideas in implementing the labs. Stu-
dents will observe strict discipline in following all the labs and will submit a DSP related
project at the end of the semester. The details of the projects will be decided during the
labs.
The textbooks used in this lab are [GK07, Opp, She06].
Contents
1 Introduction to Matlab-1 1
2 Introduction to Matlab-2 2
2
7.2 Practicals . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19
7.3 Hints . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20
7.4 Questions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20
I
Abbreviations
II
Chapter 1
Introduction to Matlab-1
1
Chapter 2
Introduction to Matlab-2
2
Chapter 3
3
Chapter 4
4.1 Introduction
In this lab manual, we will learn how to save and load data in MATLAB environment.
The saving of data to disk and loading of data from the disk becomes handy during a
number of scenarios, e.g.
• When a lot of processes are going on and the output data that is generated has not
enough space in the memory, so at some intermediate data can be stored and processed
again
• When we want to use data in some other application on the same machine
• When we do not want to generate the same data again and again
• When we want the data generation and data manipulation sections seperate
Keeping the above mentioned scenarios in mind, it becomes necessary to get a grasp of
saving and loading data.
The MATLAB environment is very versatile in generating data and signals. The procedure
to save and load the data is also very efficient and easy in MATLAB.
The commands to save an array or arrays are given by the keyword save. For example,
to save a matrix A to a file called f ilename in ascii format we type the expression
4
Chapter 4 Saving and Loading Data
To store all the workspace variable in a file f ilename in *.mat format, we use the
expression
save(0 f ilename0 ) (4.2)
To save some of the variable in MATLAB to a file f ilename, we use the format like:
The same procedure is applied when we save the data in ascii format.
In order to load data from a file to the workspace, we use the command load. To load
data from a file called f ilename, we use the command
If the extension of the file is other than *.mat, MATLAB treats the file as an ascii file.
To load specific variables from a *.mat file only, use the following command.
The command
val = load(...) (4.7)
loads the contents of the file in a variable val.
If the file is made in some other software and the data must be given to MATLAB
for further processing, the commands f open() is first used to open the file to MATLAB’s
environment. To read or write data to the file, we use the commands f read() and f write().
When the editing is done, we close the file using f close function.
Simulink environment can also load and save data from and to files. A simulation of storing
a sine wave as a vector data in a *.mat file and to MATLAB’s workspace is shown in Fig. 4.1.
To load data from a file or MATLAB’s workspace, we can perform a similer simulation
in Simulink.
4.2 Practical
1. Generate a sinusoid of 10 kHz in MATLAB. Store the data in an ascii and *.mat file
with the name sinedata.
2. Load the same file data in some variable and plot the data.
5
Chapter 4 Saving and Loading Data
4.3 Hints
Use the MATLAB’s help during the procedure. The C function to generate random numbers
is rand().
4.4 Questions
• Import an integer array stored in a disk file into MATLAB and perform its plotting.
6
Chapter 5
5.1 Introduction
The sampling of an analog signal is done in order to convert the analog signal into a digital
representation of the signal. The sampling of analog signal is the first step in performing any
digital processes to the signal.
Sampling is performed by multiplying an analog signal with a comb function, which
ideally consists of impulses at specific intervals. The impulses are separated by time Ts and
thus the frequency of the impulses is fs = 1/Ts . The output of a sampler is a digitized signal
consisting of individual samples of the analog signal at discrete time intervals. The question
that arises is what are the limits of fs ? The answer is given by the Nyquist criterion which
denotes that the sampling frequency must be atleast twice the maximum frequency present
in the analog signal. A value of fs lower than this will contribute to aliasing, where we cannot
get the original signal back from the digitized signal.
Figure 5.1: This figure shows how sampling is done. (a) An analog signal is multiplied with
a comb signal (b) of magnitude one to obtain its sampled (digitized) version
(c)
7
Chapter 5 Sampling an Analog Signal
Unfortunately, MATLAB cannot work with analog signals, because after all, MATLAB
is run by a digital machine! But we can represent analog and digital signals separately.
In MATLAB, we can generate a random sequence between 0 and 1 using the function
rand(). To generate a random sequence between 0 and 1 with mean 0, variance 1 and standard
deviation 1, we use the randn() function. This sequence is now called normally distributed
random numbers.
In MATLAB, we can view a signal and its properties using the sptool. For this purpose,
type sptool in MATLAB. The Fig. 5.2 will appear.
We see that this GUI has many capabilities. But for this lab, we will be focusing on
only viewing the signals. The signals can be imported to the sptool via clicking File and
then Import. Then we can view the signal by clicking the view button at the end of Signal
window. A window as shown in Fig. 5.3 will appear.
We can zoom in and out and perform other functions using this Signal Browser.
5.2 Practical
Generate various waveforms like sinusoidal, triangular, damped oscillations and unit step
using different sampling frequencies. Plot the waveforms on time axis. Increase and decrease
the sampling frequency and note the effect on the representation of waveforms in digital
domain.
8
Chapter 5 Sampling an Analog Signal
5.3 Hints
Represent the analog waveform using the plot command and the digitized waveform using
stem command. Remember that total number of samples N equals total time of the analog
signal To multiplied with the sampling frequency fs . i.e.
N = To fs (5.1)
5.4 Pseudocode
This section discusses the coding technique that can be utilized for performing the above lab.
9
Chapter 5 Sampling an Analog Signal
5.5 Questions
• Dose the increase in sampling frequency fs makes the digitized waveform a better rep-
resentation of the analog waveform? If so, why in practice we keep fs just above twice
the maximum frequency?
• Obtain the above results using your own script file. Generate analog and comb functions
separately. Multiply the generated analog signal with the comb function, and display
the results.
• Using MATLAB, generate a sinusoid and then simulate the effect of noise by adding
normally distributed random numbers. Save the the sinusoid and the noisy output to
*.mat files. View the sinusoid and the noisy output via sptool. Hear the two signals
and get a grasp of the difference.
10
Chapter 6
6.1 Introduction
x = 1 (6.1)
y = 2 (6.2)
z = 3 (6.3)
x = Σ(x + y) (6.4)
Discrete time systems work on digital signals. They are the counterparts of analog
systems. The input and output to these systems are digital. Thus, an analog signal that
is to be processed with digital signal processors must be converted to digital representation
using sampling. Like analog systems, digital systems are linear and non-linear, causal and
anti-causal, time variant and in-variant, stable and unstable etc.
Digital systems also have an impulse response like analog systems, which is basically
the output of the digital system for an input impulse to the system. The output to any other
type of input can be calculated with the help of this response.
A system is time invariant if for every input x[n] it satisfies the following relationship (see
Fig. 6.1)
y[n] = w[n] (6.5)
11
Chapter 6 Simulation of Discrete Time Systems
Figure 6.1: Test to check weather the system is time invariant or not. If y[n] equals w[n],
system is time invariant
Figure 6.2: Test to check weather the system is linear or not. If u[n] and v[n] are equal,
then the system is a linear system
To test weather a system is linear or not, we perform the following test (shown in Fig. 6.2)
u[n] = v[n] (6.6)
An LTI discrete-time system is ”Bounded Input : Bounded Output” (BIBO) stable if its
impulse response is absolutely sumable. It therefore follows that a necessary condition for
12
Chapter 6 Simulation of Discrete Time Systems
an IIR LTI system to be stable is that its impulse response decays to zero as the sample
index gets larger. An alternate procedure to find the stability of a digital system is to check
weather there is any pole of H(z) whose magnitude is greater than 1. If thats so, the system
is unstable.
Here we present an example of a discrete system that will be utilized in the coming labs. A
Moving Average Filter is a filter that is based on the principle of averaging the waveform’s
adjacent points. The equation of the running (moving) average filter is given by:
PM −1
k=0 in[n − k]
out[n] = (6.7)
M
x[n] − x[n − M ]
out[n] = out[n − 1] + (6.8)
M
We can see that all the coefficients of a moving-average filter are 1/M .
6.2 Practical
1. Simulate a Moving average System using in[n] equal to a sum of two sinusoid of fre-
quency 10 Hz and 200 Hz, sampled at 8000 Hz, and vary M from 5 to 10. Plot out[n].
The screen shot of the expected results is shown in Fig. 6.3.
Find whether the system given by the above equation is stable, time variant or linear
using the first 50 samples of the output. Take x[n] the sum of two sinusoids of frequency
10 and 20 Hz. Plot y[n] in MATLAB. The screen shots are expected to be as given in
Fig. 6.4 and 6.5.
6.3 Hints
To calculate the response of the moving average filter, use the MATLAB’s f ilter() function.
See MATLAB’s Help for reference. Take the Z-transform of the equation for calculating the
impulse response. Use the function impz() to calculate the impulse response. Set all initial
conditions equal to zero. To determine the stability, take the sum of the impulse response in
time domain and find whether the sum is getting stable or increasing. Or use the MATLAB’s
root() function.
13
Chapter 6 Simulation of Discrete Time Systems
Figure 6.4: The screen shot of results obtained for testing linearity
6.4 Questions
14
Chapter 6 Simulation of Discrete Time Systems
Figure 6.5: The screen shot of the impulse response of the system under test
• What is the value of M which must not be taken for a moving average in the above
question?
• Change x[n] to sum of three sinusoids with the third of frequency 30 Hz and repeat the
procedure. Dose the properties of the system change?
• Generate a unit ramp function for 0.2 sec sampled at 4000 Hz in MATLAB. Using
convolution, obtain the output of a system with time domain system response:
h[n] = 2δ[n] + 3δ[n − 3]
15
Chapter 7
7.1 Introduction
∞
X
X(z) = x[n]z −n (7.1)
n=−∞
The output of a system, y[n] in Z-domain is given by Y (z). The system function h[n] is given
by H(z), and the input x[n] is given by X(z). We can define the output as
Y (z)
H(z) = (7.3)
X(z)
16
Chapter 7 Frequency Domain Analysis
b0 (z − z1 )(z − z2 )...(z − zW −1 )
H(z) = (7.4)
(z − p1 )(z − p2 )...(z − pW )
where zi represent the zeros and pm represent the poles of the system function.
To find the zeros and poles of a system, we can use the MATLAB’s roots() function.
For a causal system, the system is stable if and only if the transfer function has all its poles
inside the unit circle. i.e.
|pm | < 1, m = 1, 2, ..., W (7.5)
The poles can be viewed via the MATLAB’s zplane() command. The screen shot of
location of poles and zeros for a moving-average filter is shown in Fig. 7.1. The unfilled circles
represent zeros and the crosses represent the poles of the system.
The frequency response of a system can be determined from its system function by replacing
z with ejw and then converting H(z) to polar form.
17
Chapter 7 Frequency Domain Analysis
The frequency response is then subdivided into magnitude and phase response. The
frequency response of a digital system can be computed by the MATLAB’s function f reqz().
Example of a moving-average filter of length 8 is shown by Fig. 7.2.
The MATLAB’s fvtool can also be used to compute the response of a digital filter. Not only
the magnitude and phase responses are provided to the user, but quantities like group delay
and phase delay can also be dealt with easily using this GUI. The Fig. 7.3 shows the screen
shot of the fvtool.
We see that the quantities that fvtool can provide us are:
18
Chapter 7 Frequency Domain Analysis
Thus, we can see that the fvtool is a powerful tool for analyzing the digital filters.
7.2 Practicals
1. Simulate the zplane() of a moving-average filter of lengths 5 and 8. Also determine the
magnitude and phase response using the f reqz() command.
Is the system stable? Find the magnitude and phase response of the system. Also
display the pole-zero plot and the impulse response of the current system.
19
Chapter 7 Frequency Domain Analysis
7.3 Hints
To use fvtool for the digital filters, find the coefficients of the numerator and denominator of
the filter function. Then invoke the fvtool by typing:
f vtool(< nuemerator >, < denominator >)
7.4 Questions
• Evaluate the stability of system H(z) = z/(z − a) for direct values of coefficients a.
Plot the values of a for stability and instability.
• What is the relationship of zeros with their locations in the Fig. 7.1?
• What is the value plotted on the horizontal axis of the Fig. 7.3? For what value of M
does the first notch occur in the question 1 of the practical? What happens if we apply
a sinusoid referring to the same notch to the filter?
20
Chapter 8
8.1 Introduction
In the previous lab, we saw that the frequency response of a system is calculated on the
basis of Z-transform. The frequency response was a continuous function of z. Although the
continuous function is a good candidate for visualization purposes, it does not stand well
from computational point of view in digital hardware.
The DFT is a procedure to obtain a sampled frequency domain of a digital signal. The
sampled version of frequency response is useful because it can be stored in memory of a digital
system and can be utilized if we perform calculations in frequency domain. The DFT, X(k),
of a signal x[n] with N samples is given by the following relation.
N
X −1
X(k) = x[n]e−j(2π/N )kn , k = 0, 1, ..., N − 1 (8.1)
n=0
where the frequency resolution w0 is given by:
2π
w0 = (8.2)
N
The opposite of DFT is IDFT which is used to obtain the time domain signal from the
frequency domain data.
The DFT given in (8.1) involves the computation of N complex multiplications and additions.
So to compute the N outputs, we need N 2 complex multiplications and additions. This clearly
shows that computing a DFT can become a daunting task for a processor.
A fast algorithm, FFT is used to compute the DFT of the time domain data of a signal.
The ratio of computing cost (in terms of multiplication) in both the cases is approximately
FFT log2 N
= (8.3)
DF T 2N
The number of samples for computation of FFT and IFFT must be some power of 2 for
speedy calculation. To make the samples equal to some power of 2, we need to add trailing
zeros to the input signals.
21
Chapter 8 DFT and IDFT Computations
MATLAB also utilizes FFT to obtain the frequency domain of the signals. Same is the case
for IDFT, where IFFT is utilized. To calculate the magnitude and phase of the FFT, we can
use the MATLAB’s abs and angle commands.
The frequency of a digital signal is represented in the limits from 0 to 2π rad, shown
by fs in Fig. 8.1. A digital signal cannot exist outside this frequency. So all the frequency
domain plots in MATLAB are from 0 to 2π and it’s the responsibility of the user to mark
the axis correctly. Many of the times, input to an FFT block is a real signal and the real
signal satisfy Hermition redundancy property, which states that the real output of the FFT
is even and imaginary output of FFT is an odd function.
Figure 8.1: A digitized time domain signal and its DFT. Only magnitude of DFT is shown.
Sptool can also be utilized to view the spectrum of the signals generated either in workspace
or from the *.mat files. For this procedure, we open the sptool, import the signal into the
tool. Then we click the Creat button under the Spectra window. The Spectrum Viewer
window is created. We give the method as FFT and specify N , and then we click the Apply
button to display the frequency-domain of the imported signal. See the Fig. 8.2 for reference.
22
Chapter 8 DFT and IDFT Computations
Figure 8.2: The use of sptool to generate the frequency domain plots
8.1.4 Simulink
Simulink is a powerful tool for viewing and simulating different systems. This tool can plot
frequency domain signals as well. For plotting the spectrum, we need a spectrum analyzer.
A screen shot of the simulation is shown in Figs 8.3 and 8.4.
8.2 Practical
Generate 1024 samples of a signal containing two sinusoids of frequency 200 and 300 Hz,
sampled at 1000 Hz. Obtain the frequency response of the resultant signal. Add some noise
in the resultant signal and again compute the frequency response. Compare the two plots.
Take IFFT of the contaminated signal and compare it to the original signal. Match your
figure to the one given by Fig. 8.5.
8.3 Hints
The functions f f t() and if f t() are used in MATLAB to calculate the frequency and time
domain representations respectively. To contaminate a signal with noise, either use the
function awgn() or randn(). The digital frequency w in rad is related to analog frequency f
in Hz in the following manner.
f (Hz)
w(rad) = 2π (8.4)
fs (Hz)
where fs is the sampling frequency. Every index k on the frequency axis corresponds to the
frequency kfs /N (Hz). Also use MATLAB’s help for f f tshif t() function.
23
Chapter 8 DFT and IDFT Computations
8.4 Questions
• Reduce the number of samples to 512. What happens to the signals? Why?
• Using IFFT, generate 512 samples of a 1000 Hz sinusoid sampled at 4000 Hz.
• Generate a signal containing two sinusoids of frequencies 400 Hz and 850 Hz, sampled
at 4000 Hz. Plot its FFT for N = 100, 128, 200, 512
• Use f f tshif t() to represent the frequency in the range of -π to π. Use MATLAB’s Help
for this purpose.
• Generate a contaminated sinusoid of frequency 100 Hz. Apply this signal to a moving-
average filter. Plot the FFT of input to the filter and output of the filter.
• If the time-domain signal is real, how can you reduce the computational cost of the
f f t() algorithm?
24
Chapter 8 DFT and IDFT Computations
25
Chapter 8 DFT and IDFT Computations
26
Chapter 9
9.1 Introduction
FIR filters are the type of digital filters having a finite impulse response, i.e. the response
of the filter (system) decays after some finite time interval. This means that the impulse
response sequence of FIR filters have a finite number of non-zero terms. In other words, if
the impulse response of a digital filter is determined for some finite number of sample points,
then these filters are known as FIR filters.
Let us consider an ideal low pass filter whose frequency response is shown by the figure.
The flat frequency response of the system insures equal gain/attenuation to all the frequency
components. A sharp cutoff is seen at the cutoff frequencies. The time domain of such a
filter is shown by the accompanying Fig. 9.1.
There are two problems in the time domain impulse response of the filter.
1. It is infinite.
Problem 1 is tackled by limiting the time domain impulse response of the system. This
is done by multiplying the time domain response by another function that exists between
some range round zero. This other function is called a window.
Problem 2 is handled by shifting the restricted time domain impulse response such that
the first term of the time domain impulse response occur at time zero.
By introducing such remedies to the problems, frequency response of the system is
no more ideal. The windows are of different types and each of them contributes a specific
advantage to the frequency response. For example, some window function produce sharp
cutoff, but at the same time the stop band attenuation decreases.
27
Chapter 9 Designing FIR Filters
Figure 9.1: Design procedure of an FIR filter. The ideal response is changed
MATLAB’s sptool can be used to perform the necessary signal processing and filtering func-
tions. The sptool window has a Filters sub-window. We can either edit the current prototype
filter or we can create a new filter. First, we import a contaminated signal in the Signals sub-
window. For creating a new filter, click New button. The Filter Designer window will open.
We set the different parameters of the filter and then click the apply button (see Fig. 9.2).
The filter’s name will appear in the sptool’s Filters window.
Now we click the Apply button to apply the contaminated signal to the filter and
examine the output via signal browser.
28
Chapter 9 Designing FIR Filters
MATLAB’s fdatool is specifically designed for filter design and its analysis. Using this tool,
we can do anything from making digital FIR, IIR filters to realizing the models. The filter
coefficients can be exported to MATLAB’s workspace, to scripts or to Simulink models. As
shown in Fig. 9.3, we see that there are different variations of FIR and IIR filters from which
we can chose our design like equiripple, window based, maximally flat etc.
9.2 Practical
Using the FDATool of MATLAB, obtain the coefficients of 3rd order, 7th order and 10th
order FIR low pass filter with a cutoff frequency of 4000 Hz, sampled at 8000 Hz. The
simulation of a filter is shown in Fig. 9.4. Perform the procedure for rectangular, hamming,
hann, Barlett, Flat Top and Kaiser Windows. Generate a signal composed of three sinusoids
of 10, 20 and 50 Hz and contaminate the signal with noise. Using the above filters, eliminate
the noise. Draw time and frequency domain plots of the signals. Repeat the procedure in
Simulink. Take reference from Fig. 9.5 and 9.6.
9.3 Hints
Invoke the FDATool by typing fdatool in MATLAB. Use the function sos2tf (). Save the
filters with different names for future reference.
29
Chapter 9 Designing FIR Filters
9.4 Questions
• Which type of the above windows produces the sharpest cutoff in frequency domain in
a 10th order FIR filter?
• What is the significance of Kaiser Window upon the other window functions?
• What is the value of denominator of filter impulse response obtained for all the windows?
Why?
• Do the numerator coefficients of filter impulse response show any type of periodicity?
30
Chapter 9 Designing FIR Filters
• What is the effect on frequency domain filter coefficients upon shifting of the time
domain impulse response? How can you eliminate this effect?
• Design a linear-phase lowpass FIR filter with the following specifications: passband edge
= 2 kHz and sampling rate of 10 kHz. Compare its performance to a moving-average
filer.
31
Chapter 10
10.1 Introduction
If infinite number of sample points are used to determine the unit-sample response of a digital
filter, then these types of filters are known as IIR filters.
It may be noted that IIR filters design procedure are extensions of those originally
developed for analog filters. In fact, IIR filters are commonly used to replace existing analog
filters.
Normally, the design of IIR filter is started from specifications of analog filter. System
function of the analog filter is then obtained. The system function of the digital filter is then
obtained through some transformations.
The most well known analog filters are the Butterworth, Chebyshev and Elliptical.
These filters can be bandpass, band stop, low pass and high pass filters. The specifications
required for designing such filters are the normalized passband edge frequency wp , the nor-
malized stop band edge frequency ws , the passband ripple rp in dB and the minimum stop
band attenuation rs in dB. These quantities are elaborated in Fig. 10.1. The order of the
filter is given by N and the band stop frequency is given by wn .
There are different methods and transformations available to obtain the digital filter
from the corresponding analog filters, each with some specific properties.
A notch filter is a filter that contains a deep notch in its magnitude response, i.e. it severely
attenuates a very small bandwidth of the magnitude response.
To create a notch filter that attenuates a frequency w0 , we can put a pair of complex
conjugate zeros at the unit circle for that frequency, so for a zero at w0 ,
z = e±(jw0 ) (10.1)
32
Chapter 10 IIR Filter Design
For narrower band width of the notch filter, we add poles to the transfer function at
some distance r, such that r is less than 1.
The notch filter can be designed by the MATLAB’s sptool. We invoke the sptool, and
click create under the Filters. Then change the algorithm to Pole Zero Editor. Here we
can place the poles and zeros according to our liking and view the magnitude and phase
responses. See Fig. 10.2 and 10.3.
10.2 Practical
Using the FDATool, design a 5th and 15th order Butterworth, Chebyshev and Elliptical
filter. Perform the procedure for bandpass, bandstop, low pass and high pass filters. Instead
of using the FDATool, obtain the order of the filter and also the filter coefficients for the
above practical.
33
Chapter 10 IIR Filter Design
34
Chapter 10 IIR Filter Design
10.3 Hints
The FDATool is invoked by typing FDATool in MATLAB command prompt. The order and
cutoff frequency can be determined by the using the buttord(), cheb1ord(), cheb2ord() and
ellipord() functions. Use MATLAB help for reference.
10.4 Questions
• What is the shape of the phase response of the IIR filter? How do you compare it to
the phase response of the FIR filter? Which phase response is better? Why?
• Using MATLAB determine the lowest order of a digital IIR lowpass filter of all four
types. The specifications are as follows: sampling rate of 40 kHz, passband edge fre-
quency of 4 kHz, stopband edge frequency of 8 kHz, passband ripple of 0.5 dB, and a
minimum stopband attenuation of 40 dB. Comment on your results.
• Using MATLAB determine the lowest order of a digital IIR highpass filter of all four
types. The specifications are as follows: sampling rate of 3,500 Hz, passband edge
frequency of 1,050 Hz, stopband edge frequency of 600 Hz, passband ripple of 1 dB,
and a minimum stopband attenuation of 50 dB.
• Using FDATool, filter high frequency noise components from low frequency signal con-
taining 2 sinusoids at frequencies 20 and 50 Hz. Use an IIR filter.
• Derive equation (10.5). What is the effect of adding another pole pair?
• Using a notch filter, eliminate the 50 Hz sinusoidal that contaminates a 300 Hz sinusoid.
Keep the sampling frequency at 8000 Hz.
• What is a peak filter? Design a peak filter using the same method discussed for designing
a notch filter in MATLAB. Give a practical application.
35
Chapter 11
11.1 Introduction
For designing a digital filter, the system function H(z) or the corresponding impulse response
h[n] should be specified. After that, we can implement or synthesize the digital filter structure
in hardware or software from the help of its difference equation which is obtained directly
from the system function H(z) or the impulse response h[n].
For implementing the specified difference equation of a system (i.e. filter), the required
basic operations are addition, delay and multiplication by a constant. A particular chosen
structure determines a computational algorithm. Usually, various structures provide various
results. However, the most common methods to realize digital linear systems are direct,
cascade and parallel forms, and also state variable realization.
11.2 Practical
Using FDATool, design the FIR and IIR filters given in Lab 9 and 10. Realize the models
in Simulink and provide each filter some sinusoids, contaminated with noise. Generate the
block diagram representations of the filters. Perform the procedure for cascade and parallel
realization for both the filters. Also generate the residues of the parallel form of realization.
11.3 Hints
Use MATLAB help and FDATool command for performing the procedure. Use the functions
eqtf length(), tf 2zp() and residuez() to generate the required results.
11.4 Questions
• Referring to filters of Lab 9 and 10, generate the sketches of the filters.
• Referring to Fig. 11.1 and 11.2, how can you suggest the order of the filters by looking
at the realization?
36
Chapter 11 Realization of Digital Filters
Figure 11.1: The figure shows an example of 3rd order FIR filter. As seen, there are no
feedback paths
Figure 11.2: The figure shows an example of a 1st order IIR filter. Feedback paths can be
seen
37
Chapter 12
Simulation of Synchronous AM
Transceiver System
12.1 Introduction
This lab and the next is based on simulation of a practical communication system. These
labs are presented in order to give the students an insight of the simulation of such systems.
An AM signal is the one in which the intelligence (information) lye in the time varying
amplitude of the signal. A high frequency carrier of frequency fc is modulated by the message
signal m(t) to generate AM signal.
At the receiver, the received signal is again multiplied with the carrier of frequency fc .
The signal is then passed through a low-pass filter that eliminates the term carrying the
frequency 2fc and we get the signal m(t)/2. The whole scheme is given by Fig. 12.1.
12.2 Practical
Perform AM using a message signal that consists of two low frequency sinusoids. Use this
signal to modulate a carrier of frequency 5000 Hz. Transmit the signal and add noise.
Demodulate the signal using the synchronous demodulation technique discussed above. Plot
the outputs as shown in Fig. 12.2.
38
Chapter 12 Simulation of Synchronous AM Transceiver System
12.3 Hints
Do not use the MATLAB function ammod(), instead follow the above procedure for mod-
ulation and demodulation. Use FDATool to construct the coefficients of the low pass FIR
filter. Demonstrate every signal along with its Fourier Transform. Use subplot and bring all
the figures together
12.4 Questions
• Are the demodulated and message signal identical? If not, explain why.
• Why do we filter m(t) before passing it to the multiplier? What happens if we re-
move this step? Explain your answer with the help of a simulation, not involving the
mentioned filter.
39
Chapter 12 Simulation of Synchronous AM Transceiver System
40
Chapter 13
13.1 Introduction
In this practical, we deal with the modulation of digital data using MATLAB. Digital data
must be converted to analog signals before it can be transmitted. For radio interface, we
convert the digital data into composite analog signals containing sinusoids. These sinusoids
represent the data symbols and occupy much lesser bandwidth than the digital signals.
13.1.1 QPSK-QAM
One of the most important way of modulating a data stream is using the QPSK-QAM mod-
ulation. In this method of modulation, we do not perform any error correction coding.
Data symbols are represented by the sinusoids in these modulation schemes, and different
aspects of these sinusoids are changed to represent faithfully the data. The points on the
cartesian coordinate system representing the real and imaginary parts of these sinusoids
constitute a constellation diagram.
13.2 Practical
Generate random data in MATLAB. Modulate the data using the in-built commands of
MATLAB. Observe the signal constellations of the modulated data. Insert noise in the
modulated data. Obtain the digital data from the contaminated signal and calculate the
total number of errors that occurred during the transmission. Increase and decrease the
effect of noise and calculate the total errors that occurred for each increase and decrease.
Plot the errors encountered with the intensity of noise. Perform the above procedure for
QPSK, 8 QAM, 16 QAM and 64 QAM.
41
Chapter 13 Modulation of Digital Data using QPSK-QAM
(a) (b)
Figure 13.1: The constellation of a signal modulated with QPSK. The first figure is for no
noise presence and the second one is obtained with noise present
13.3 Hint
Use MATLAB help to generate random numbers in a certain interval. Using the inbuilt
commands for modulation, modulate the random numbers. The function scatterplot() is used
to observe the signal constellations. Find the indices where the demodulated and original
data are not the same. The number of such indices gives us the total number of errors.
13.4 Questions
• Which one of the modulations techniques (QPSK-QAM) is the most robust technique
and resistant to noise? Why?
• Use a band pass FIR filter to remove the noise that is added. What happens to the
error? Why?
• Instead of using random numbers create your own function which accepts input as bits
and generates the modulated output in terms of real and imaginary components.
• Generate the random numbers in VisualDSP++ 4.5. Modulate them via QPSK-QAM.
View the constellation of the signal using the plot command. See Fig. 13.4 for reference.
• Implement the above procedure in Simulink. Use QPSK modulation. Keep the sampling
frequency 8000 Hz and the simulation time 0.5 sec. Use an AWGN channel of SNR 10.
Take reference from the Figs. 13.2 and 13.3
42
Chapter 13 Modulation of Digital Data using QPSK-QAM
43
Chapter 13 Modulation of Digital Data using QPSK-QAM
44
Bibliography
[GK07] Gan, Woon-Sing ; Kuo, Sen M.: Embedded Signal Processing with Micro Signal
Architecture. Wily Interscience, 2007. – ISBN 978–0–471–73841–1 1
[She06] Shenoi, B.A.: Introduction to Digital Signal Processing and Filter Design. Wily
Interscience, 2006. – ISBN 978–0–471–46482–2 1
45