DSP Lab 7 To 12
DSP Lab 7 To 12
DSP Lab 7 To 12
Lab # 07 to 12
Registration
FA18-BEE-002
Number
Class BEE-6A
Objective:
By the end of this lab students will be able to model and simulate any type of
communications/control / DSP model on Simulink and analyze its performance.
Introduction:
Simulink, developed by MathWorks©, is a commercial tool for modeling, simulating and
analyzing multi-domain dynamic systems. Its primary interface is a graphical block
diagramming tool and a customizable set of block libraries. It offers tight integration with the
rest of the MATLAB environment and can either drive MATLAB or be scripted from it.
Simulink is widely used in control theory and digital signal processing for multi-domain
simulation and Model-Based Design.
Running SIMULINK:
Click on the new file icon shown at the top left corner of the above figure and set the
configuration parameters of your simulation as shown below:
Library Browser:
A toolbox is a collection of tools designated to perform a specific task or set of tasks. All the
toolboxes are in this window. However, we are concerned with Digital Signal Processing so we
will use the ‘Signal Processing Toolbox’. Navigate inside the blocks and right click on any
component and click on “add to <filename>” where filename is the name of your simulink model
file.
Following are some of the important toolboxes we will use in our labs:
SIMULINK
o Commonly Used Blocks
o Discontinuities
o Discrete
o Math Operations, Signal Attributes, Signal Routing, Sources, Sinks etc
Signal Processing Blockset
Embedded Target for TI C6000 DSP (for DSKs)
o DSK DSP Starter Kits (6414, 6711, 6713 etc)
Acquaint yourselves with these toolboxes as they will be used in your subsequent labs. Consult
Google and ask your instructor in case of any queries. Build the following example model in
SIMULINK:
In-Lab Task :
In this lab non R-T model for the AM transmitter/receiver is to be developed to demonstrate the
features of Amplitude Modulation (AM) transmission and reception. Amplitude Modulation is a
process where the amplitude of a carrier signal (high frequency sinusoid) is altered according to
information in a message signal. The model runs in SIMULINK and enables the user to select:
1. The AM algorithm
2. The transmission and reception parameters (modulation index and carrier frequency).
Simulation
The Environment
Figure 1 shows the data flow for the AM modulation simulation. The AM modulation model
receives an input signal from an external signal generator, modulates it and displays the
modulation on the scope.
Information
Signal
The Procedure
y(t) [1 m(t)]cos(2 f c t)
Where:
2. Open the Simulink library browser and add the DSP sine-wave to your model. This
blocks will represent the information signal m(t).
3. Configure the Sine Wave Generator Block (Double click on the DSP sine object). Set the
sine frequency to 1000 Hz, sample time to 1/96000, samples per frame to 64 and close
the box, and change ts label to “in
4. Use the same block to create the carrier signal. You may copy the block already created
or select it form the Simulink library. Set the carrier frequency to 15,000 Hz. The
remaining parameters are identical to the ones of the information signal. Change its label
to “carrier”
6. Double-click on the constant object and set its constant value to 1.5:
Figure 7- Adder
8. Add a new multiplexer from the same directory as the adder (choose “product”).
9. Add a new scope object:
Figure 8 - Scope
10. Set the number of frames parameter to 5. This parameter determines the horizontal scaling of
the presented signal.
12. Run the model, pause the simulation and activate the scope window. The modulated
signal should be displayed as follows:
In this section you will create the model for an AM receiver based on Square Root (SQRT)
demodulation. The principle of operation is shown Figure 1.
13. Add the new math function block to your model. This block can be configured to
implement various mathematical functions.
15. Use the math function block to create the Square root function. You may retrieve it
from the library or copy the “square” block.
16. Add a digital filter design block. This block enables you to design filters using the
MATLAB® FDATool.
17. Configure the filter to be Low-Pass Filter. Since the carrier frequency (fc) is 15 KHz
and the maximal frequency of the information is 1 KHz, the filter will be designed to
pass frequencies below 5 KHz, and rejects frequencies higher than 10 KHz (please refer
to Figure 16).
20. Add the matrices concatenation object. This object will enable the modulated and the
de-modulated signals to be displayed simultaneously in the scope:
22. Run the simulation (push the “play” button). Double click on the scope. Scale the display
to fit the scope window (Choose from the menus: Axes=>Autoscale). Choose a different
color for each signal (Please refer to Figure 19).
Try to change the modulation index to 50%, 100% and 150% and comment on the
influence of changing ‘mu’ on the modulated and demodulated signals. Keep the
carrier signal frequency same as before
In Lab Tasks:
Task 1:
Generate a sinusoid containing 5 frequency components and display these components in the
FFT-scope.
OUTPUT GRAPH:
Task 2:
Generate DSB SC and use coherent detection to recover the message signal. Analyze the
spectra of AM and DSB-SC signals and comment on the bandwidth and transmission of both
schemes.
OUTPUT GRAPH:
Lab Assessment
Pre Lab /5
Performance /5
Results /5 /25
Viva /5
Critical Analysis /5
Objective:
By the end of this lab students will be able to design different types of filters using
FDA tool and implementing it on DSK 6713.
1. Low-pass filters
2. High-pass filters
3. Band-pass filters
4. Band-stop filters
The typical responses of these filters are shown below:
Low Pass Filter (Cutoff = 4kHz)
Alternatively, filters may also be classified according to their response type as:
FDA tool is the filter design and analysis tool in MATLAB which is used for the design and
analysis of FIR or IIR filters. It may be opened by simply typing the following command in
MATLAB command window:
>>fdatool
1. Go to MATLAB ‘Start’
2. Point to Toolboxes
3. Point to Filter Design in the sub menu
4. Click on Filter Design & Analysis Tool (fdatool)
Following are some of the parameters considered during filter design process in FDA tool:
Think of order as the measure of how much processing power our digital filter will require to be
implemented. Hence,
FV tool is the Filter Visualization tool in MATLAB and you can use it to analyze your filter
response in details. It may be opened from FDA tool by first designing a filter and then opening
this tool from ‘ViewFilter Visualization Tool’. The interface of this tool is shown below:
FV Tool – Interface
In Lab Tasks:
Task 1:
Design a “minimum order” low pass filter to suppress all frequencies above 4kHz. Mention
the application of such a filter. Send this model to DSP kit and show the results in CCS.
Task 2:
Design a “minimum order” high pass filter to pass all frequencies above 6kHz. Mention the application of such a filter.
Send this model to DSP kit and show the results in CCS.
Task 3:
For a frequency range of ‘24kHz – 28kHz’, design band pass and band stop filters. Send
this model to DSP kit and show the results in CCS.
Part b:
Task 4:
Observe that there is a guard band of 2kHz between 4kHz and 6kHz. Exploit it.
In this lab we learnt that how we can design different types of filters using FDA tool.
We have come to know about different kinds of filters and their applications. Filters
we studied in this lab include band pass, band stop, high pass and low pass filters and
lastly we studied guard band to get familiarized with its purpose and its applications.
A low pass filter that passes frequency below 4 kHz and stops the frequency above 4
kHz, the model was made using Simulink. A high pass filter that passes frequency
above 6 kHz and stops the frequency below 6 kHz, the model was made using
Simulink.
DSK
Objective
In this lab DSK6713 and DSK6416 will be used to demonstrate the features of Amplitude Modulation
(AM) transmission and reception. The model run is in real-time and enables the user to select:
The AM algorithm
The transmission and reception parameters (modulation index and carrier frequency). The
process comprises:
Pre-Lab Task
1. Real Time Implementation
1.1. The Environment
The real-time implementation model will be created upon the simulation model, after the following
changes:
The signal generator block will be replaced by the CODEC of the DSK6713
The virtual scope will be replaced also by the CODEC A
target definition block (DSK6713) will be added.
Figure 21 shows the block-diagram for the real time implementation.
DSK6713/DSK6416
Dual Channel Oscilloscope
Signal Generator
Modulated
Signal Demodulated
Signal
Information
Demodulated- the signal that the receiver outputs after the demodulation process.
In-Lab Task
Lab Task
1. Open the model created in the previous lab
2. Remove the scope and the “information” signal (the 1,000 Hz).
3. Open the Simulink library browser and add the "C6713DSK" as shown in Figure 2.
4. Add the “Analog to Digital” and “Digital to Analog” converters (ADC and DAC) to your model
as shown in Figure 3.
5. Add the multi-port selector, in order to split the stereo input, as shown in Figure 4.
6. After placing the selector, double-click to open the dialog box and choose “columns” in the
“select” label and “{1,2}” in the “indices to output label.
7. Configure the ADC and DAC blocks to a sampling rate to 96 KHZ and 16-bit samples.
9. You should configure the DSP constants as shown in Figure . The frame period for all constants
should be -1
10. Build the project and load the program to the DSK memory using ctrl+B.
11. Make sure that the signals generator amplitude is set to 1 Volt and frequency of [0.1,5] kHz.
Model Extensions
In this section following extensions to the model are introduced. Adding two more features:
2. Replace the constant modulation index by an RTDX input (Please refer to Figure ), and name it
Input Modulation.
4. Replace the sine wave block used for the carrier by the configurable carrier blocks and create a
subsystem for the carrier generator as shown in Figure
6. Open the “AM_Coherent.mdl” file, and repeat step 0 for this file.
You now have two load files each one corresponding to a different AM scheme.
cos ct Re e j ct
fc
fc j2 n
fs
cos cnTs cos2 n Re e
fs
The following model implements the last equation. Please note that a
feedback path was included for phase continuity
TASK: 01
CODE:
/*
* File: task1.c
*
* Real-Time Workshop code generated for Simulink model task1.
*
* Model version : 1.2
* Real-Time Workshop file version : 6.5 (R2006b) 03-Aug-2006
* Real-Time Workshop file generated on : Sun Dec 02 23:02:51 2018
* TLC version : 6.5 (Aug 3 2006)
* C source code generated on : Sun Dec 02 23:02:53 2018
*/
#include "task1.h"
#include "task1_private.h"
#pragma DATA_ALIGN(task1_B,8)
BlockIO_task1 task1_B;
D_Work_task1 task1_DWork;
/* Real-time model */
RT_MODEL_task1 task1_M_;
RT_MODEL_task1 *task1_M = &task1_M_;
/* Right */
task1_B.ADC[i + 64] = (real32_T)*(blkAdcBuffPtr+1) * ADCScaleFactor;
blkAdcBuffPtr += 2;
}
}
[0];
byte_T *outPortAddr[2]; /* Local array of pointers to the output port locations */
int_T outIdx;
outPortAddr[0] = (byte_T *)rtb_MultiportSelector_o1;
outPortAddr[1] = (byte_T *)rtb_MathFunction1;
{
int32_T i;
for (i = 0; i < 64; i++) {
/* Sum: '<Root>/Add2' incorporates:
* Constant: '<S2>/Constant'
*/
rtb_Add2[i] = (real_T)rtb_MultiportSelector_o1[i] + task1_P.Constant_Value;
}
}
{
int32_T i;
for (i = 0; i < 64; i++) {
/* Product: '<Root>/Product' */
task1_B.MatrixConcatenate[i] = rtb_Add2[i] * rtb_Add1[i];
{
int32_T i;
for (i = 0; i < 64; i++) {
/* Math: '<Root>/Math Function1' */
if (task1_B.DigitalFilter[i] < 0.0F) {
rtb_MathFunction1[i] = (real32_T)-sqrt(-task1_B.DigitalFilter[i]);
} else {
rtb_MathFunction1[i] = (real32_T)sqrt(task1_B.DigitalFilter[i]);
}
/* Right */
*(outPtr+1) = (int16_T)(task1_B.MatrixConcatenate[i + 64] * DACScaleFactor);
outPtr += 2;
}
/* Registration code */
/* block I/O */
{
int_T i;
void *pVoidBlockIORegion;
pVoidBlockIORegion = (void *)(&task1_B.MatrixConcatenate[0]);
for (i = 0; i < 128; i++) {
((real_T*)pVoidBlockIORegion)[i] = 0.0;
}
/* states (dwork) */
(void) memset((char_T *) &task1_DWork,0,
sizeof(D_Work_task1));
task1_DWork.SineWave_AccFreqNorm = 0.0;
{
int_T i;
real32_T *dwork_ptr = (real32_T *) &task1_DWork.DigitalFilter_FILT_STATES[0];
for (i = 0; i < 49; i++) {
dwork_ptr[i] = 0.0F;
}
}
codec_init();
*statePtr++ = 0.0F;
}
}
BLOCK DIAGRAM:
TASK: 02
CODE:
/*
* File: task2.c
*
* Real-Time Workshop code generated for Simulink model task2.
*
* Model version : 1.8
* Real-Time Workshop file version : 6.5 (R2006b) 03-Aug-2006
* Real-Time Workshop file generated on : Mon Dec 03 00:15:27 2018
* TLC version : 6.5 (Aug 3 2006)
* C source code generated on : Mon Dec 03 00:15:28 2018
*/
#include "task2.h"
#include "task2_private.h"
BlockIO_task2 task2_B;
D_Work_task2 task2_DWork;
/* Real-time model */
RT_MODEL_task2 task2_M_;
RT_MODEL_task2 *task2_M = &task2_M_;
/* Right */
{
int32_T i;
for (i = 0; i < 64; i++) {
/* Sum: '<Root>/Add2' */
rtb_Add2[i] = (real_T)rtb_MultiportSelector_o1[i] + rtb_Product2;
}
}
}
}
}
{
int32_T i;
for (i = 0; i < 64; i++) {
/* Product: '<Root>/Product' incorporates:
* Gain: '<Root>/Gain'
*/
task2_B.MatrixConcatenate[i] = rtb_SineWave[i] * task2_P.Gain_Gain *
rtb_Add2[i];
/* Product: '<Root>/Product1' */
task2_B.Product1[i] = (real_T)rtb_MultiportSelector_o2[i] * rtb_SineWave[i];
}
}
{
int32_T i;
for (i = 0; i < 64; i++) {
/* Sum: '<Root>/Subtract' incorporates:
* Constant: '<S3>/Constant'
* Gain: '<Root>/Gain1'
*/
task2_B.MatrixConcatenate[i+64] = task2_B.DigitalFilter[i] *
task2_P.Gain1_Gain - task2_P.Constant_Value_m;
}
}
/* Right */
*(outPtr+1) = (int16_T)(task2_B.MatrixConcatenate[i + 64] * DACScaleFactor);
outPtr += 2;
}
/* Registration code */
/* block I/O */
{
int_T i;
void *pVoidBlockIORegion;
pVoidBlockIORegion = (void *)(&task2_B.Product1[0]);
for (i = 0; i < 256; i++) {
((real_T*)pVoidBlockIORegion)[i] = 0.0;
}
/* states (dwork) */
{
real_T *dwork_ptr = (real_T *) &task2_DWork.SineWave_AccFreqNorm;
dwork_ptr[0] = 0.0;
dwork_ptr[1] = 0.0;
dwork_ptr[2] = 0.0;
}
codec_init();
BLOCK DIGRAM:
Conclusion:
In this lab DSK6713 and DSK6416 we used to demonstrate the features of Amplitude
Modulation (AM) transmission and reception. The model run is in real-time and enables the
user to select:
The AM algorithm
The transmission and reception parameters (modulation index and carrier frequency).
The process comprises:
Creating a simulation model (not R-T) for the AM transmitter/receiver
Migration to Real-time of the Simulation Model
Lab Assessment
Pre Lab /5
Performance /5 /25
Results /5
Viva /5
Critical Analysis /5
Objective:
In this lab we will learn how to implement FIR and IIR filters on different DSP kits. The basics of
FIR and IIR filters and the design and analysis of FIR and IIR filter(s) in FDA tool will also be carried
out.
Pre-Lab
In-Lab Task
Chebyshev type II
Elliptic
Butterworth filter:
The Butterworth filter is a type of signal processing filter designed to have as flat a frequency response
as possible in the passband. It is also referred to as a maximally flat magnitude filter. It was first
described in 1930 by the British engineer Stephen Butterworth in his paper entitled "On the Theory of
Filter Amplifiers"
Butterworth had a reputation for solving "impossible" mathematical problems. At the time,
filter design required a considerable amount of designer experience due to limitations of the
theory then in use. The filter was not in common use for over 30 years after its publication.
Butterworth stated that:
"An ideal electrical filter should not only completely reject the unwanted frequencies but should also
have uniform sensitivity for the wanted frequencies".
Such an ideal filter cannot be achieved but Butterworth showed that successively closer
approximations were obtained with increasing numbers of filter elements of the right values.
At the time, filters generated substantial ripple in the passband, and the choice of component
values was highly interactive. Butterworth showed that a low pass filter could be designed
whose cutoff frequency was normalized to 1 radian per second and whose frequency response
(gain) was
Where ω is the angular frequency in radians per second and n is the number of reactive elements
(poles) in the filter. If ω = 1, the amplitude response of this type of filter in the passband is 1/√2
≈ 0.707, which is half power or −3 db. Butterworth only dealt with filters with an even number
of poles in his paper
Chebyshev filter:
Chebyshev filters are analog or digital filters having a steeper roll-off and more passband ripple (type
I) or stopband ripple (type II) than Butterworth filters. Chebyshev filters have the property that they
minimize the error between the idealized and the actual filter characteristic over the range of the filter,
but with ripples in the passband. This type of filter is named in honor of Pafnuty Chebyshev because its
mathematical characteristics are derived from Chebyshev polynomials.
These are the most common Chebyshev filters. The gain (or amplitude) response as a function
of angular frequency of the nth-order low-pass filter is
Where is the ripple factor, is the cutoff frequency and is a Chebyshev polynomial of
the th order.
The passband exhibits equiripple behavior, with the ripple determined by the ripple factor . In
the passband, the Chebyshev polynomial alternates between 0 and 1 so the filter gain will
alternate between maxima at G = 1 and minima at . At the cutoff frequency
the gain again has the value but continues to drop into the stop band as the
frequency increases. This behavior is shown in the diagram on the right. The common practice
of defining the cutoff frequency at −3 dB is usually not applied to Chebyshev filters; instead
the cutoff is taken as the point at which the gain falls to the value of the ripple for the final
time.
The order of a Chebyshev filter is equal to the number of reactive components (for example,
inductors) needed to realize the filter using analog electronics.
The ripple is often given in dB:
Ripple in dB =
stop band. The result is called an elliptic filter, also known as Cauer filter.
Also known as inverse Chebyshev, this type is less common because it does not roll off as fast
as type I, and requires more components. It has no ripple in the passband, but does have
equiripple in the stopband. The gain is:
In the stopband, the Chebyshev polynomial will oscillate between 0 and 1 so that the gain will
oscillate between zero and
and the smallest frequency at which this maximum is attained will be the cutoff frequency
. The parameter ε is thus related to the stopband attenuation γ in decibels by:
For a stopband attenuation of 5dB, ε = 0.6801; for an attenuation of 10dB, ε = 0.3333. The
frequency fC = ωC/2π is the cutoff frequency. The 3dB frequency fH is related to fC by:
Elliptic filter:
An elliptic filter (also known as a Cauer filter, named after Wilhelm Cauer) is a signal
processing filter with equalized ripple (equiripple) behavior in both the passband and the
stopband. The amount of ripple in each band is independently adjustable, and no other filter of
equal order can have a faster transition in gain between the passband and the stopband, for the
given values of ripple (whether the ripple is equalized or not). Alternatively, one may give up
the ability to independently adjust the passband and stopband ripple, and instead design a filter
which is maximally insensitive to component variations.
As the ripple in the stopband approaches zero, the filter becomes a type I Chebyshev filter. As
the ripple in the passband approaches zero, the filter becomes a type II Chebyshev filter and
finally, as both ripple values approach zero, the filter becomes a Butterworth filter.
The gain of a lowpass elliptic filter as a function of angular frequency ω is given by:
where Rn is the nth-order elliptic rational function (sometimes known as a Chebyshev rational
function) and
is the cutoff frequency
is the ripple factor
The value of the ripple factor specifies the passband ripple, while the combination of the ripple
factor and the selectivity factor specify the stopband ripple
Lab Tasks
Task-1: Make a filter using following specifications:
Figure 1
1. Kaiser Window
2. Butterworth
3. Chebyshev Type-I
4. Chebyshev Type-II
5. Elliptic
C6713 DSK
DAC
Filter DAC
freq 8e3
C6713DSK
TABLE:
Filter working
Kaiser No
Butterworth Yes
Chebyshev- I Yes
Chebyshev- II Yes
Elliptic Yes
Conclusion:
In this lab the following things were observed:
The Butterworth filter is a type of signal processing filter designed to have as flat as
frequency response as possible in the passband.
Chebyshev filters are analog or digital filters having a steeper roll-off and more passband
ripple (type I) or stopband ripple (type II) than Butterworth filters.
An Elliptic filter is a signal processing filter with equalized ripple behavior in both the
passband and the stopband.
THE END