From MATLAB and Simulink to Real-Time with TI DSP’s

From MATLAB and Simulink to Real-Time
with TI DSP’s
By:
Jacob Fainguelernt
From MATLAB and Simulink to Real-Time
with TI DSP’s
By:
Jacob Fainguelernt
Online:
< http://cnx.org/content/col10713/1.1/ >
CONNEXIONS
Rice University, Houston, Texas
This selection and arrangement of content as a collection is copyrighted by Cathy Wicks. It is licensed under the
Creative Commons Attribution 2.0 license (http://creativecommons.org/licenses/by/2.0/).
Collection structure revised: June 8, 2009
PDF generated: October 26, 2012
For copyright and attribution information for the modules contained in this collection, see p. 523.
Table of Contents
1 Control
1.1 Vehicle Dynamics . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1
1.2 DC Motor Control . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 34
1.3 A DSP Based Class D Audio Amplier . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 62
1.4 Permanent Magnet Synchronous Motor Control . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 85
2 Signal Processing and Communication
2.1
2.2
2.3
2.4
2.5
2.6
2.7
2.8
Acoustic Noise Cancellation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 109
Amplitude Modulation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 148
Audio Conference Bridge . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 191
DTMF Detection . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 223
Echo and Reverberation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 244
Signal to Noise Measurement . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 274
Spectrum Estimation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 300
Wavelet Denoising . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 332
3 Video and Imaging
3.1
3.2
3.3
3.4
3.5
A Framework for Image Processing with the DSK6416 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 375
A Framework for Video Processing with the DM6437 DVDP . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 397
Finding Shapes in Images . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 424
Edge Detection . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 475
Video Surveillance . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 486
4 From MATLAB and SIMULINK to Real-time Using TI DSPs . . . . . . . . . . . . . . . . . . . . . . . . . . . . 521
Index . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 522
Attributions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 523
iv
Available for free at Connexions <http://cnx.org/content/col10713/1.1>
Chapter 1
Control
1.1 Vehicle Dynamics1
1.1.1 Introduction
The Texas Instruments C28x family of processors has been designed to implement control applications,
for example digital motor control and un-interruptible power supplies.
We shall start here with a simple
application. In this Laboratory, you will build a simulation model of a vehicle dynamics using Simulink, and
then emulate it using the eZDSP-F2812 board.
1.1.1.1 Related Files
•
•
•
•
2
Powerpoint Presentation - VehicleDynamics.ppt
3
Simulink Model for PC Simulation - VehicleDynamics.mdl
4
Simulink Model for Simulation with DSKF2812 - VehicleDynamicsF2812Simulation.mdl
Simulink Model for Real-Time - VehicleDynamicsDSKF2812.mdl
5
1.1.1.2 Objectives
•
•
•
•
Design a Simulink model of the motion of a vehicle.
Run the model using Simulink on a PC.
Modify the model for use with the Texas Instruments C28x Digital Signal Processor.
Run the modied model on the Texas Instruments F2812 ezDSP.
1.1.1.3 Level
Beginner; This is intended as the rst complete project using Matlab and Simulink.
It is suitable for students who have only limited exposure to Texas Instruments DSPs before.
1.1.1.4 Requirements
In developing this Laboratory, the following hardware and software were used:
1 This content is available online at <http://cnx.org/content/m22943/1.1/>.
2 See the le at <http://cnx.org/content/m22943/latest/VehicleDynamics.ppt>
3 See the le at <http://cnx.org/content/m22943/latest/VehicleDynamics.mdl>
4 See the le at <http://cnx.org/content/m22943/latest/VehicleDynamicsF2812Simulation.mdl>
5 See the le at <http://cnx.org/content/m22943/latest/VehicleDynamicsDSKF2812.mdl>
Available for free at Connexions <http://cnx.org/content/col10713/1.1>
1
2
CHAPTER 1.
•
•
•
•
Matlab R2006b with Embedded Target for TI C2000.
Code Composer Studio (CCS) 3.1.
Spectrum Digital ezDSP F2812 Hardware
Some external electronic components costing about $2.
1.1.2 Simulation
1.1.2.1 Running the Vehicle Dynamics Simulation
6
Open VehicleDynamics.mdl .
Figure 1.1: Engine Management Subsystem
6 See
the le at <http://cnx.org/content/m22943/latest/VehicleDynamics.mdl>
Available for free at Connexions <http://cnx.org/content/col10713/1.1>
CONTROL
3
Run the Model.
The input to the model is a ramp generator, which simulates smooth acceleration.
You will see the graphs of Horsepower and Vehicle Speed.
1.1.2.1.1 Changing the Vehicle Mass
Double click on the Vehicle Dynamics block. This models the equation of motion using Simulink Blocks.
Figure 1.2: Vehicle Dynamics
At present, the vehicle mass is 8000 kg.
We will now simulate a small compact car. Change the 1/m gain block to 1/1000 and change the b/m
block to 2/1000.
Run the model again and notice the eect on maximum vehicle speed and how long it takes to reach
maximum vehicle speed
You might also like to simulate a 35,000 kg lorry. Change the 1/m block to 1/35000 and b/m to 10/35000.
1.1.2.1.2 Changing the Engine Power Prole
Double click on the Engine Management block. This models the gas in horsepower out function of the
engine.
Available for free at Connexions <http://cnx.org/content/col10713/1.1>
4
CHAPTER 1.
Figure 1.3: Engine Management Subsystem
Double-click on the Power Transfer Function
Available for free at Connexions <http://cnx.org/content/col10713/1.1>
CONTROL
5
Figure 1.4: Engine Power Transfer Function
Change the shape of the Power Transfer Function. You may wish to change the gradient or make the
plateau wider. Run the model.
1.1.2.1.3 Other Modications to the Model
Go to the Website of an automobile manufacture, and obtain the actual engine power transfer function for
a real car. Run this in the model.
Replace the ramp generator input with a step function. This simulates someone stamping on the gas!
Available for free at Connexions <http://cnx.org/content/col10713/1.1>
6
CHAPTER 1.
CONTROL
1.1.3 Reference Simulation for F2812
1.1.3.1 Running the Vehicle Dynamics Simulation
7
Open VehicleDynamicsF2812Simulation.mdl .
Figure 1.5: Modied Model for F2812
Run this model. This is the behavior that should be seen when the real-time model is run on the ezDSP
for F2812.
7 See
the le at <http://cnx.org/content/m22943/latest/VehicleDynamicsF2812Simulation.mdl>
Available for free at Connexions <http://cnx.org/content/col10713/1.1>
7
1.1.4 Creating Your Own Models
1.1.4.1 Creating a new Matlab Model
Start Matlab 7.3.0 R2006b
In the top left hand corner of the Matlab screen, select: File -> New -> Model.
Figure 1.6: A New MatLab Model
The following screen will appear.
Available for free at Connexions <http://cnx.org/content/col10713/1.1>
8
CHAPTER 1.
Figure 1.7: An Empty MatLab Model
1.1.4.1.1 Saving the New Model
Save the model as vehicle_dynamics.mdl.
Available for free at Connexions <http://cnx.org/content/col10713/1.1>
CONTROL
9
Figure 1.8: Saving the new model
1.1.4.1.2 Opening the Library Browser
Select View-> Library Browser
Available for free at Connexions <http://cnx.org/content/col10713/1.1>
10
CHAPTER 1.
CONTROL
Figure 1.9: Selecting the Library Browser
1.1.4.1.3 Selecting the Subsystems
A list of available blocks will appear. Select Commonly used blocks. Highlight Subsystems. Drag-anddrop two copies of this block into the model.
Available for free at Connexions <http://cnx.org/content/col10713/1.1>
11
Available for free at Connexions <http://cnx.org/content/col10713/1.1>
Figure 1.10: The Simulink Library Browser
12
CHAPTER 1.
CONTROL
1.1.4.1.4 Subsystems Added
Rename the Subsystems to Engine Management and Vehicle Dynamics.
Figure 1.11: Subsystems Added
Drag-and-drop a saturation block onto the model.
1.1.4.1.5 Adding a Ramp Generator
From the Simulink Library Browser, select Sources. Drag-and-drop the Ramp block onto the model.
Available for free at Connexions <http://cnx.org/content/col10713/1.1>
13
Available for free at Connexions <http://cnx.org/content/col10713/1.1>
Figure 1.12: Adding a Ramp Generator
14
CHAPTER 1.
1.1.4.1.6 Adding Scope Blocks
From the Simulink Library Browser, select Sinks.
Drag-and-drop the Scope block onto the model twice.
Drag-and-drop the Display block onto the model twice.
Available for free at Connexions <http://cnx.org/content/col10713/1.1>
CONTROL
15
Figure 1.13: Adding a Scope
Available for free at Connexions <http://cnx.org/content/col10713/1.1>
16
CHAPTER 1.
1.1.4.1.7 Joining and Renaming the Blocks
Join the blocks as shown in the gure below. Change the names and add a title.
Figure 1.14: First Blocks Added
1.1.4.1.8 Setting the Solver
The ode45 solver is not suitable for use with DSP. Fixed Point Discrete is required.
Available for free at Connexions <http://cnx.org/content/col10713/1.1>
CONTROL
17
Figure 1.15: Conguring the Solver
1.1.4.2 The Engine Management Subsystem
1.1.4.2.1 Overview of the Engine Management Subsystem
The rst stage of the Engine Management Subsystem is a Gain block, which converts the Gas Pedal input
(0-100%) to 0-4000 rpm.
The second stage is a lookup table. This converts from rpm to hp.
Available for free at Connexions <http://cnx.org/content/col10713/1.1>
18
CHAPTER 1.
Figure 1.16: The Engine Management Subsystem
1.1.4.2.2 Adding a Lookup Table
From the Simulink Lookup Tables, drag-and-drop the Lookup Table block onto the model.
Available for free at Connexions <http://cnx.org/content/col10713/1.1>
CONTROL
19
Figure 1.17: Adding a Lookup Table
Double click on the Lookup Table block.
Available for free at Connexions <http://cnx.org/content/col10713/1.1>
20
CHAPTER 1.
Figure 1.18: Lookup Table Block Parameters
The values for the table can also be inserted as a table. Click on the Edit box.
Available for free at Connexions <http://cnx.org/content/col10713/1.1>
CONTROL
21
Figure 1.19: Lookup Table Values
Click on "Plot" as shown above, and you will see:
Available for free at Connexions <http://cnx.org/content/col10713/1.1>
22
CHAPTER 1.
CONTROL
Figure 1.20: Adjusting the Lookup Table
1.1.4.3 The Vehicle Dynamics Subsystem
1.1.4.3.1 Overview of Vehicle Dynamics Subsystem
The C28x operates in discrete-time; therefore the continuous integrator must be replaced by a Discrete
Time Integrator for DSP model implementation.
Available for free at Connexions <http://cnx.org/content/col10713/1.1>
23
Figure 1.21: Vehicle Dynamics Subsystem
Select the Main tab. Change the Constant value to 0. Click on OK.
1.1.4.3.2 Running the Simulation
The ramp generator gently changes the Gas Pedal from 0% to 100%. This simulates smooth acceleration.
The Horsepower and Vehicle Speed are shown on the graphs.
Available for free at Connexions <http://cnx.org/content/col10713/1.1>
24
CHAPTER 1.
CONTROL
Figure 1.22: Running the Simulation
1.1.5 Modications for ezDSP F2812
In order to run the model on the ezDSP F2812, some additional blocks need to be added to the project:
•
•
•
An Analog-to-Digital Converter (ADC) to allow a potentiometer input.
A block to scale the ADC input to the range 0 to 100%.
A Digital-to-Analog Converter (DAC) to convert the Vehicle Speed to an analog output in the range
0 to 3.3V
Available for free at Connexions <http://cnx.org/content/col10713/1.1>
25
1.1.5.1 Connecting the F2812 ezDSP
For Matlab and Simulink to run correctly, you need to run the F2812 ezDSP.
Connect the F2812 hardware to the parallel port of the computer and turn on the supply to the board.
When the board is powered, the two green LED lights on the board will come on during self-test.
Start Code Composer Studio for F2812 ezDSP and use Debug -> Connect
Figure 1.23: Startup Screen for Code Composer Studio (CCS)
1.1.5.2 Opening the Library Browser
Select View-> Library Browser
Available for free at Connexions <http://cnx.org/content/col10713/1.1>
26
CHAPTER 1.
CONTROL
Figure 1.24: Selecting the Library Browser
1.1.5.3 The Simulink Library Browser
A list of available blocks will appear. We are particularly interested in the Embedded Target for TI C2000
DSP. Click on this selection.
In the following sections we will select the building blocks for the DSP model shown in Figure 30.
Available for free at Connexions <http://cnx.org/content/col10713/1.1>
27
Available for free at Connexions <http://cnx.org/content/col10713/1.1>
Figure 1.25: The Simulink Library Browser
28
CHAPTER 1.
CONTROL
1.1.5.4 Selecting Target Preferences
From the C2000 Target Preferences, select F2812 ezDSP. Drag-and-drop the icon onto the new model.
Figure 1.26
Figure 26 Selecting Target Preferences
When the following screen appears, it is important to select Yes.
Available for free at Connexions <http://cnx.org/content/col10713/1.1>
29
Figure 1.27: Initializing Simulation Parameters
1.1.5.5 Scaling the ADC Readings
To scale the ADC reading to the Gas Pedal 0 to 100% we will multiply the ADC input by 800 then divide
by 32768.
Available for free at Connexions <http://cnx.org/content/col10713/1.1>
30
CHAPTER 1.
CONTROL
Figure 1.28
Figure 28 Scaling the ADC
1.1.5.6 Scaling the DAC Output
To scale the kph to the DAC output, we will multiply the kph input by 312.5. The Saturation block limits
the output to 200 kph.
Available for free at Connexions <http://cnx.org/content/col10713/1.1>
31
Figure 1.29: Scaling the DAC
1.1.5.7 The Finished Model
To scale the kph to the DAC output, we will multiply the kph input by 312.5.
Available for free at Connexions <http://cnx.org/content/col10713/1.1>
32
CHAPTER 1.
Figure 1.30: The Final Model
1.1.5.8 Building the Model
Select Tools -> Real-Time Workshop -> Build Model.
Available for free at Connexions <http://cnx.org/content/col10713/1.1>
CONTROL
33
Figure 1.31: Building the Model
8
You may nd the nal model here .
1.1.5.9 Comparing Performance
The real-time model running on the ezDSP F2812 should now be behaving in the same way as the Simulation.
1.1.6 References
1. Spectrum Digital Incorporated, "eZdspTM F2812 Technical Reference" Rev.
9
(http://c2000.spectrumdigital.com/ezf2812/docs/ezf2812_techref.pdf
)
8 See the le at <http://cnx.org/content/m22943/latest/VehicleDynamicsDSKF2812.mdl>
9 http://c2000.spectrumdigital.com/ezf2812/docs/ezf2812_techref.pdf
Available for free at Connexions <http://cnx.org/content/col10713/1.1>
F, September 2003.
34
CHAPTER 1.
CONTROL
1.2 DC Motor Control10
1.2.1 Introduction
This chapter demonstrates the use of the c28x peripherals and DMC library blocks to control the speed of
a DC motor in a closed-loop fashion. This example is based on the "DC Motor Speed Control via RTDX"
SIMULINK demo.
The target speed of the motor is set by the user in the MATLAB GUI. This value is fed to the Controller
(based on the eZDSP-F2812) to change the motor speed. The loop is closed by a tachometer. The controller
constantly adjusts the value of the DC voltage applied to the motor to maintain the desired speed.
The
control loop is shown in the following gure:
Figure 1.32: DC Motor Control Loop
The Speed controller comprises two blocks (please refer to Figure 2):
1. This block compares the desired speed with the measured speed and generates a digital value proportional to the DC value to be applied to the motor.
10 This
content is available online at <http://cnx.org/content/m22189/1.1/>.
Available for free at Connexions <http://cnx.org/content/col10713/1.1>
35
Figure 1.33: The Speed Controller
2. This block is implemented using a PWM signal generator and a Low Pass Filter as shown in Figure 3.
This method is described in . The output voltage, generated at the LPF output will be:
V = D · Vss
Where:
V
- Generated Voltage
D
- PWM Duty Cycle
Vss
- Supply Voltage (3.3 V)
Table 1.1
Available for free at Connexions <http://cnx.org/content/col10713/1.1>
(1.1)
36
CHAPTER 1.
Figure 1.34: Digital to Analog Converter Implementation
Figure 4 shows the loop control implementation, based on three components:
1. eZDSP-F2812 (Please refer to )
2. Interface circuit (Please refer to Section )
3. DC Motor Kit (Please refer to Section )
Available for free at Connexions <http://cnx.org/content/col10713/1.1>
CONTROL
37
Figure 1.35: DC Motor Control Loop Implementation
1.2.1.1 Setup
This demo is based on the Spectrum Digital eZdsp-F2812 that is connected to a DC Motor Kit through a
dedicated interface circuit. The setup is shown in Figure 5.
Available for free at Connexions <http://cnx.org/content/col10713/1.1>
38
CHAPTER 1.
CONTROL
Figure 1.36: Setup
1.2.1.1.1 The DC Motor Kit
Servo amplier [SA150D]:
This unit operates the motor from signals applied to the input sockets 1 or 2, enabling control of the motor
speed and reversing its rotation. This example shows speed control only, and will make use input socket 1
only. The servo amplier is connected to the servo motor by an 8-pin plug and able. Terminals for
±
15
volts and ground (common) are available on this unit.
Servo motor with Tachometer [MT150F]:
This unit is a DC motor that produces a torque of the order of 8 oz-in (600 gm-cm) at 2A input current.
The inertia is about 3x10−5 Kg
−m2.
The output shaft may be tted with a brake disc and/or an inertia
disc to load the motor. A second shaft on the side of the motor is coupled to the main shaft by 30:1 gears
(the smaller shaft rotates slower than the main shaft). The tachometer with terminals +, - and common
(ground) is attached to the motor.
Power supply [PS150E]:
This unit provides the various voltages supplies required for the servo components. There are terminals for
±15
volts, and common (ground). An ammeter is also included. The maximum current is 2 A. An 8-pin
Available for free at Connexions <http://cnx.org/content/col10713/1.1>
39
socket and cable connects this unit to the servo amplier.
1.2.1.1.2 I/F Circuit
This circuit was designed as part of the demo that will be described in detail in chapter .
1.2.1.2 Measurement Equipment
1. Signal Generator
2. Voltmeter
3. Oscilloscope.
4. Stroboscope
1.2.1.3 Related Files
•
•
•
Simulink Model for Simulation - DCMotorControl.mdl
11
MATLAB script for Real-Time - speedControlDCLoop.m
12
13
Simulink Model for Real-Time - DCMotorControlc2812.mdl
1.2.2 System Identication
The transfer function of a DC motor can be approximated by a rst order model with unknown constants.
These constants can be identied experimentally.
The tachometer provides the feedback signal for speed control systems.
A schematic diagram of the
tachometer is given in Figure 6.
11 See
12 See
13 See
the le at <http://cnx.org/content/m22189/latest/DCMotorControl.mdl>
the le at <http://cnx.org/content/m22189/latest/speedControlDCLoop.m>
the le at <http://cnx.org/content/m22189/latest/DCMotorControlc2812.mdl>
Available for free at Connexions <http://cnx.org/content/col10713/1.1>
40
CHAPTER 1.
CONTROL
Figure 1.37: DC Motor with Tachometer
In this section we will identify the constants in the mathematical models of a DC motor and the tachometer experimentally. The process consists of consists of two parts:
1. Measurement of the tachometer coecient and the motor constant
2. Measurement of the motor time constant.
Measurement Equipment
•
•
•
•
Signal Generator
Voltmeter
Oscilloscope.
Stroboscope
1.2.2.1 Measurement of Tachometer Coecient and Motor Constant
The tachometer coecient and motor constant can be measured by generating a control voltage, using the
PWM block of the DSP, and measuring:
Available for free at Connexions <http://cnx.org/content/col10713/1.1>
41
1. The motor speed using a stroboscope
2. The tachometer output using a voltmeter
The setup is shown in Figure 7.
Figure 1.38: Calibration of the Motor and Tachometer
Figure 8 shows the model that will be used to generate the control voltage.
Available for free at Connexions <http://cnx.org/content/col10713/1.1>
42
CHAPTER 1.
CONTROL
Figure 1.39: System Identication Model
The PWM block will be congured to generate a PWM signal with a period of 4096 clock cycles of 75
MHz (please refer to Figure 9).
Available for free at Connexions <http://cnx.org/content/col10713/1.1>
43
Figure 1.40: PWM Conguration
Measurement Procedure:
1. Connect the circuit shown in Figure 7.
2. Generate a 0 V input to the DC Motor Kit (Compile Build and Run the model with Duty Cycle=0)
3. Measure the motor speed using the stroboscope and the tachometer voltage using a voltmeter.
4. Repeat step 3 for input voltages in the range 0-15 V. Change the Duty Cycle from 0 to 100% in steps
of 10 %.
5. Obtain a plot of tachometer voltage vs. servo amplier input voltage.
The ADC input voltage of the DSP should be in the range 0-3V, the therefore the tachometer output voltage
must be inverted and scaled down. This is done with the circuit shown in Figure 19. The gain of this circuit
is G = - 100/270 = - 0.37, i.e., inverting and attenuating approximately 1/3. The results obtained are shown
in Figure 10.
Available for free at Connexions <http://cnx.org/content/col10713/1.1>
44
CHAPTER 1.
CONTROL
Figure 1.41: Speed Measurement
1.2.2.2 Measurement of the motor time constant
The measurement of the time constant will be obtained by generating a square pulse and measuring the
motor response to this stimulus. The principle of operation is shown in Figure 11; the experimental setup is
shown in Figure 12.
Available for free at Connexions <http://cnx.org/content/col10713/1.1>
45
Figure 1.42: Measurement of the motor time constant
Available for free at Connexions <http://cnx.org/content/col10713/1.1>
46
CHAPTER 1.
Figure 1.43: Measurement of the motor time constantMeasurement
The Function Generator generates pulses, as shown in Figure 13.
Available for free at Connexions <http://cnx.org/content/col10713/1.1>
CONTROL
47
Figure 1.44: Pulse Parameters
Measurement Procedure
1. Connect the circuit shown in Figure 12.
2. Generate the pulse shown in Figure 13.
3. Measure the rising and falling times of the motor response.
The DC motor was modeled as a rst-order linear system where
τrise = τfall ;
however, the actual motor is
not linear (due to friction, for example), therefore the measured values were:
τrise
= .13 secs
τfall
= .23 secs
Table 1.2
We used the average of these readings, i.e., (0.13+0.23)/2 = 0.18 and rounded to 0.2 sec.
Ω(s)
E(s)
1
= Km 1+sτ
m
⇔
Ω(s)
E(s)
= Km 1+1.2s
1.2.3 Real-Time System Design
The system design comprises two parts:
1. Simulation, to determine the parameters of the Speed Control Transfer Function
2. Hardware Design of the interface circuit.
Available for free at Connexions <http://cnx.org/content/col10713/1.1>
(1.2)
48
CHAPTER 1.
CONTROL
1.2.3.1 Simulation
The speed control is a PID controller. A DC motor model (Figure 14) was created. The complete control
loop model is shown in Figure 15. Figure 16 shows the parameters chosen for the PID controller.
Figure 1.45: DC Motor Model
Available for free at Connexions <http://cnx.org/content/col10713/1.1>
49
Figure 1.46: Loop Control Model
Available for free at Connexions <http://cnx.org/content/col10713/1.1>
50
CHAPTER 1.
CONTROL
Figure 1.47: PID Controller Parameters
1.2.3.2 Hardware Design
The connection between the eZDSP and the Motor Kit requires a dedicated interface circuit, implementing
the Low Pass Filter (used for the Digital to Analog conversion) and adapting the voltage levels at the eZDSP
(0 to 3V) to those of the DC Motor Kit (0-15V). The various signal types and their voltage range are shown
in .
Available for free at Connexions <http://cnx.org/content/col10713/1.1>
51
The interface circuit contains two blocks.
The rst is LPF with an amplier (shown in Figure 18),
connected between the PWM output and the servo amplier input.
The second block is an attenuator
(shown in Figure 19) connected between the tachometer output and the Analog to Digital Input of the
eZDSP.
Figure 1.48: Signal Types and Voltage Levels
Available for free at Connexions <http://cnx.org/content/col10713/1.1>
52
CHAPTER 1.
Figure 1.49: LPF + Amplier Circuit
Available for free at Connexions <http://cnx.org/content/col10713/1.1>
CONTROL
53
Figure 1.50: The Inverting Amplier with LPF
1.2.4 Real Time Implementation
The control loop was implemented in the eZDSP F2812 as shown in Figure 20. The PID controller obtained
in the previous chapter was implemented in the DSP. The environment is shown in Figure 21.
The real-time implementation model will be created from the "DC Motor Speed Control via RTDX"
SIMULINK demo. In the original demo model the loop is closed by QEP block, we will use a tachometer
connected to the Analog to Digital Converter module for speed measurement.
The Model and its subsystems are shown in Figures Figure 22, Figure 23 and Figure 24.
Available for free at Connexions <http://cnx.org/content/col10713/1.1>
54
CHAPTER 1.
CONTROL
Figure 1.51: LPF + Amplier Circuit>
Procedure:
1. Navigate into the following directory:
..\MATLAB\R2006b\toolbox\rtw\targets\tic2000\tic2000demos
1. Copy the following les into your working directory:
•
•
•
•
c2812speedcontrolDC.mdl
runc2812speedcontrolDC.m
runc2812speedcontrolDC.m
Open the c2812speedcontrolDC.mdl model and save it as "DCMotorControlc2812.mdl"(please
14
refer to Figure 21
14 The
).
model is shown here after deleting the Info box.
Available for free at Connexions <http://cnx.org/content/col10713/1.1>
55
Figure 1.52: Real-Time Implementation Model
2. Double-click the Speed Correction Block, and you will see:
Figure 1.53: Figure 22: Speed Control
3. Congure the C28x PWM block as follows:
Available for free at Connexions <http://cnx.org/content/col10713/1.1>
56
CHAPTER 1.
Figure 1.54: Figure 23: PWM Conguration
4. Congure the "PID Controller" block as follows:
Available for free at Connexions <http://cnx.org/content/col10713/1.1>
CONTROL
57
Figure 1.55: PID Conguration
5. Double-click the Speed Correction Block, and you will see:
Available for free at Connexions <http://cnx.org/content/col10713/1.1>
58
CHAPTER 1.
CONTROL
Figure 1.56: QEP Based Speed Measurement
6. Delete the selected blocks and replace them by the ADC block from Open the ADC block from the
C281x Chip support group from the C2000 Target Preferences, and connect is as follows:
Figure 1.57: ADC+Tachometer Based Speed Measurement
7. Now the model is ready for real-time, we need however to update the MATLAB script le. Open the
Model Properties from File menu. Change the PostLoadFcn callback to runc2812speedcontrolIDC,
Available for free at Connexions <http://cnx.org/content/col10713/1.1>
59
as shown:
Figure 1.58: Model Callback
8. The next step is to change the original PWM range (up to 64000) to the desired range (up to 4000).
Open the speddControlIDCLoop.m le with the MATLAB editor, an change on line 48 the command:
cycle = (double(pid).*100./64000);
to
cycle = (double(pid).*100./4000);
Please refer to the following picture:
Available for free at Connexions <http://cnx.org/content/col10713/1.1>
60
CHAPTER 1.
Figure 1.59: Changing the PWM range
9. Activate the motor
10. Activate CCS.
11. Click the Build/Reload&Run box, the following window should appear:
Available for free at Connexions <http://cnx.org/content/col10713/1.1>
CONTROL
61
Figure 1.60: Speed Control GUI
12. You may change the speed of the motor using the slider in the right hand side and the Apply button.
Available for free at Connexions <http://cnx.org/content/col10713/1.1>
62
CHAPTER 1.
CONTROL
1.2.5 References
1. "eZdspTM
F2812
Technical
Reference",
Spectrum
Digital,
2003
15
http://c2000.spectrumdigital.com/ezf2812/docs/ezf2812_techref.pdf
2. David M. Alter, " Using PWM Output as a Digital-to-Analog Converter on a TMS320F280x", TI
16
Application Report SPRAA88 , September 2008 http://www.ti.com/litv/pdf/spraa88a
1.3 A DSP Based Class D Audio Amplier17
1.3.1 Introduction
Class D ampliers have proven a higher power eciency performance against linear classes such as Class
A, B and AB. Power losses on Class D ampliers are mainly due to non-ideality of the output transistors,
operating as switches, controlled by Pulse Width Modulators.
This example describes a method for utilizing both the Enhanced Pulse Width Modulator (ePWM) and
—
the Analog-to-Digital Converter (ADC) of the TMS320F2808
digital signal controller as D-Class Audio
amplier. The method involves analog full bridge D-class power amplier and analog low-pass ltering the
amplied PWM signal to remove high frequency components, leaving only the audio-frequency content.
1.3.1.1 Hardware and Software Requirements
This example was originally developed using the following hardware and software:
•
•
•
MatLab R2008a
Code Composer Studio (CCS) v3.3
eZDSP-F2808 board.
1.3.1.2 Related Files
•
•
Powerpoint Presentation ClassD.ppt
18
19
Simulink Model for Real-Time - eZDSPF2808_ClassD.mdl
1.3.2 Principle of Operation
The amplier comprises three main blocks (shown in Figure 1):
15 http://c2000.spectrumdigital.com/ezf2812/docs/ezf2812_techref.pdf
16 http://www.ti.com/litv/pdf/spraa88a
17 This content is available online at <http://cnx.org/content/m22177/1.1/>.
18 See the le at <http://cnx.org/content/m22177/latest/ClassD.ppt>
19 See the le at <http://cnx.org/content/m22177/latest/eZDSPF2808_ClassD.mdl>
Available for free at Connexions <http://cnx.org/content/col10713/1.1>
63
Figure 1.61: The Class-D Audio Amplier
1.3.2.1 Input Circuit:
This block interfaces with the audio source, attenuates it DC component and limits the input voltage to the
ADC to the range 0 - 3.3V. The circuit contains also a DC-DC converter, for the DSP input buer.
Available for free at Connexions <http://cnx.org/content/col10713/1.1>
64
CHAPTER 1.
CONTROL
Figure 1.62: Input Circuit Schematics
1.3.2.2 Digital Signal Controller
The TMS320F2808, converts the analog signal to a pair of PWM signals that feed the output stage (Please
refer to section ). It operates with 100 MHz. The ADC samples the input signal at a 97.656.25 Ksps rate.
The ePWM, generates PWM signal with a period of 102.4
µs and duty cycle proportional to the input signal
level. The ePWM coupled with a D-Class output stage and a second order passive RLC lter, provides a
DAC equivalent.
1.3.2.2.1 Sampling the Analog Input
The analog signal is converted to PCM values as shown in . The conversion is performed as described in
Table 1. The ADC operates in a sampling rate of 97.656 KHz (100 MHz/1024).
Available for free at Connexions <http://cnx.org/content/col10713/1.1>
65
Figure 1.63: Analog to Digital (PCM) Conversion
Table 1: Analog to Digital Conversion
Input Voltage (Vin)
Digital Value(ADCRESULT)
Vin < 0V
0
0 ≤ Vin < 3V
4096
Vin ≥ 3V
4095
∗
Vin
3 ,
Table 1.3
1.3.2.2.2 PCM
→ PWM
The PCM values are converted to PWM as shown in Figure 4. A period of 102.4 msecs (1024 clock cycles)
was chosen. The relation PCM Value/Full Range is translated to the duty cycle of the PWM. A duty cycle
of 512 (50 %) corresponds to 50% of the full range, for example. In this example sample values in the range
0-4095 will be mapped to duty cycle values (CMPA) in the range 0-1023, by dividing by 4 (shift right 2 bits),
as shown in Figure 5.
Available for free at Connexions <http://cnx.org/content/col10713/1.1>
66
CHAPTER 1.
Figure 1.64: PWM based Digital to Analog Conversion
Available for free at Connexions <http://cnx.org/content/col10713/1.1>
CONTROL
67
Figure 1.65: PCM to Duty Cycle Conversion
1.3.2.2.3 The Interrupt Service Routine
The process described in the previous section is executed in the Interrupt Service Routine (ISR). The ADC
conversion is triggered by the ePWM block when the PWM period starts (every 102.4 msecs). The ADC
generates an interrupt at the end of conversion. The interrupt service routine updates the PWM duty cycle
(CMPA value) on the value of this sample. The new duty cycle will be loaded in the beginning of the next
PWM period. The process is described in Figure 6.
Available for free at Connexions <http://cnx.org/content/col10713/1.1>
68
CHAPTER 1.
CONTROL
Figure 1.66: Timing Diagram
1.3.2.3 Output Stage:
This module contains the H-bridge, and a Low Pass Filter to remove high frequency components, leaving
only the audio-frequency content. This module basically implements a Digital to Analog Converter using a
PWM signal generator and a Low Pass Filter as shown in . This method is described in .
Available for free at Connexions <http://cnx.org/content/col10713/1.1>
69
Figure 1.67: PWM based Digital to Analog Conversion
The basic conguration of a D-Class amplier is the Half-Bridge (H-Bridge) conguration. Two output
transistors operate as switches, driven by complementary PWM signals. One of the transistors is o (current
through it is close zero), while the remaining one is on (voltage across it is close to zero), keeping the power
dissipation very low.
Available for free at Connexions <http://cnx.org/content/col10713/1.1>
70
CHAPTER 1.
CONTROL
Figure 1.68: H-Bridge Power Topology
The full-bridge Class D amplier comprises two half bridges, driven by synchronized PWM signals, having
two alternate conduction paths through the load, each one having a pair of transistor conducting while the
remaining pair is o.
Available for free at Connexions <http://cnx.org/content/col10713/1.1>
71
Figure 1.69: Output Stage Schematics
1.3.3 Implementation
This section will describe the process of building a Simulink model for code generation according to description in chapter .
In the rst part the framework for interrupt handling will be created. The second section will describe
the creation of the Interrupt Service Routine.
1.3.3.1 Interrupt
1.
Available for free at Connexions <http://cnx.org/content/col10713/1.1>
72
CHAPTER 1.
2.
Figure 1.70: The "F2808 eZDSP" block
3.
Figure 1.71: The "Hardware Interrupt" Block
Available for free at Connexions <http://cnx.org/content/col10713/1.1>
CONTROL
73
The Interrupt should be generated at the end of conversion of group A, (CPU Values=1 and PIE
Values=1) as shown in Figure 12.
Figure 1.72: The "Hardware Interrupt" Selection Table
4.
Figure 1.73: The Hardware Interrupt Conguration
Available for free at Connexions <http://cnx.org/content/col10713/1.1>
74
CHAPTER 1.
5.
Figure 1.74: The "Function-Call Subsystem" Block
6.
20
20 You
may also change colors, and name the blocks as shown here.
Available for free at Connexions <http://cnx.org/content/col10713/1.1>
CONTROL
75
Figure 1.75: The Class-D Amplier Model
Available for free at Connexions <http://cnx.org/content/col10713/1.1>
76
CHAPTER 1.
1.3.3.2 PCM to PWM Conversion
1.
Figure 1.76
2.
Figure 1.77: The "ADC" Block
Available for free at Connexions <http://cnx.org/content/col10713/1.1>
CONTROL
77
The block should be congured to use channel 0 of module A, triggered by ePWMxA, and post an
interrupt at the end of conversion as shown:
(a)
(b)
Figure 1.78: The "ADC" Conguration
3.
Figure 1.79: The "ePWM" block
The blocks should be congured as shown in the following gures:
Available for free at Connexions <http://cnx.org/content/col10713/1.1>
78
CHAPTER 1.
(a)
Available for free at Connexions <http://cnx.org/content/col10713/1.1>
(b)
CONTROL
79
(a)
Available for free at Connexions <http://cnx.org/content/col10713/1.1>
(b)
80
CHAPTER 1.
4.
Figure 1.82: The "Shift Arithmetic" Block
Available for free at Connexions <http://cnx.org/content/col10713/1.1>
CONTROL
81
Figure 1.83: The "Shift Arithmetic" Block Conguration
Available for free at Connexions <http://cnx.org/content/col10713/1.1>
82
CHAPTER 1.
5.
Figure 1.84: The Class D Amplier Model
Available for free at Connexions <http://cnx.org/content/col10713/1.1>
CONTROL
83
1.3.3.3 Running the model:
1.
Figure 1.85: The System
2. Available for free at Connexions <http://cnx.org/content/col10713/1.1>
84
CHAPTER 1.
CONTROL
Figure 1.86: Voltage Supply
Build and run the model "CTRL-B".
3. The amplier should start working, connect your audio source, and enjoy the music.
1.3.4 Things to Try
This example's objective was to show the use of the F2808 blocks, it is certainly not the best implementation,
but it serves as the basis for additional features and enhancements like:
•
•
•
Use Oversampling
Use the High-Resolution PWM
Add Signal Processing (Filtering, Equalization, Gain Control) features to the amplier
1.3.5 References
1. "eZdspTM
F2808
Technical
Reference",
Spectrum
Digital,
21
http://c2000.spectrumdigital.com/ezf2808/docs/2808_ezdspusb_techref_c.pdf
21 http://c2000.spectrumdigital.com/ezf2808/docs/2808_ezdspusb_techref_c.pdf
Available for free at Connexions <http://cnx.org/content/col10713/1.1>
2005
85
2. David M. Alter, " Using PWM Output as a Digital-to-Analog Converter on a TMS320F280x", TI
22
Application Report SPRAA88 , September 2008 http://www.ti.com/litv/pdf/spraa88a
1.4 Permanent Magnet Synchronous Motor Control23
1.4.1 Introduction
The objective of this module is to use the Embedded Target for the C2000, and the Digital Motor Control
Library (DMClib) to control a Permanent Magnet Synchronous Motor (PMSM) with an encoder using the
Field Oriented Control Technique.
1.4.2 System Overview
The following gure shows the complete application that we will implement step by step during the laboratory.
Figure 1.87: PMSM Control Block Diagram
22 http://www.ti.com/litv/pdf/spraa88a
23 This content is available online at <http://cnx.org/content/m24360/1.2/>.
Available for free at Connexions <http://cnx.org/content/col10713/1.1>
86
CHAPTER 1.
CONTROL
Variables Description
ias = Phase-a stator current
ibs = Phase-b stator current
ias = Stationary a-axis stator current
ibs = Stationary b-axis stator current
ids = Synchronously rotating d-axis stator current
iqs = Synchronously rotating q-axis stator current
vas = Stationary a-axis stator voltage
vbs = Stationary b-axis stator voltage
vds = Synchronously rotating d-axis stator voltage
vqs = Synchronously rotating q-axis stator voltage
vdc = DC-bus voltage
qlr = Rotor flux angle
qm = Mechanical angle
dir = Rotor direction
wr = Rotor speed
Ta = Phase-a duty cycle ratio of PWM signal
Tb = Phase-b duty cycle ratio of PWM signal
Tc = Phase-c duty cycle ratio of PWM signal
1.4.2.1 Related Files
•
•
•
•
•
•
•
•
•
•
•
•
24
Powerpoint Presentation - PMSM_control.ppt
25
MATLAB script- PMS_Motor_data.m
26
Simulink Model for Space vector generation Simulation - PMS_Motor_level1.mdl
Simulink Model for Open Loop Simulation - PMS_Motor_level2.mdl
27
28
Simulink Model for current loop Simulation - PMS_Motor_level3.mdl
29
Simulink Model for Encoder Verication Simulation - PMS_Motor_level4.mdl
Simulink Model for Closed Loop Simulation - PMS_Motor_level5.mdl
30
31
Simulink Model for Space vector generation - Real Time PMS_Motor_level1eZDSPF2812.mdl
Simulink Model for Open Loop - Real Time - PMS_Motor_level2eZDSPF2812.mdl
32
33
Simulink Model for current loop - Real Time - PMS_Motor_level3eZDSPF2812.mdl
Simulink Model for Encoder Verication - Real Time - PMS_Motor_level4eZDSPF2812.mdl
Simulink Model for Closed Loop - Real Time PMS_Motor_level5eZDSPF2812.mdl
24 See
25 See
26 See
27 See
28 See
29 See
30 See
31 See
32 See
33 See
34 See
35 See
the le at <http://cnx.org/content/m24360/latest/PMSM_control.ppt>
the le at <http://cnx.org/content/m24360/latest/PMS_Motor_data.m>
the le at <http://cnx.org/content/m24360/latest/PMS_Motor_level1.mdl>
the le at <http://cnx.org/content/m24360/latest/PMS_Motor_level2.mdl>
the le at <http://cnx.org/content/m24360/latest/PMS_Motor_level3.mdl>
the le at <http://cnx.org/content/m24360/latest/PMS_Motor_level4.mdl>
the le at <http://cnx.org/content/m24360/latest/PMS_Motor_level5.mdl>
the le at <http://cnx.org/content/m24360/latest/PMS_Motor_level1eZDSPF2812.mdl>
the le at <http://cnx.org/content/m24360/latest/PMS_Motor_level2eZDSPF2812.mdl>
the le at <http://cnx.org/content/m24360/latest/PMS_Motor_level3eZDSPF2812.mdl>
the le at <http://cnx.org/content/m24360/latest/PMS_Motor_level4eZDSPF2812.mdl>
the le at <http://cnx.org/content/m24360/latest/PMS_Motor_level5eZDSPF2812.mdl>
Available for free at Connexions <http://cnx.org/content/col10713/1.1>
35
34
87
1.4.3 Simulation
The simulation process will be based on a simulation model for the PMS Motor.
Available for free at Connexions <http://cnx.org/content/col10713/1.1>
88
CHAPTER 1.
Available for free at Connexions <http://cnx.org/content/col10713/1.1>
Figure 1.88: Permanent Magnet Synchronous Motor (PMSM) Simulink Model
CONTROL
89
Based on this model, the simulation will comprise ve steps as follows:
1. Implementing the Forward Loop Space Vector Generation
2. Running the PMSM in open loop
3. Closing the current loop
4. The speed measurement-Encoder
5. The Speed Closed Loop
1.4.3.1 Space vector generation
The diagram below highlights the modules used in the rst step.
This rst incremental step conrms
operation of peripheral and target independent modules on forward control path and the code framework.
Figure 1.89: Space Vector Generation
At this very rst stage the goal is to generate a sawtooth waveform with a varying frequency.
This
waveform is an emulation of the rotor angle, which is then passed into the Park transformation allowing us
to check the correct computation of the Space Vector PWM needed for the Field Oriented Control.
Key Modules
Available for free at Connexions <http://cnx.org/content/col10713/1.1>
90
CHAPTER 1.
•
CONTROL
RMPCNTL (ramp control): this module used by the instantiation of the object rc1, structure for which
we can access each variable, controls the acceleration and deceleration rate of the speed command
speed_ref .This speed command is passed the input of the RMPCNTL module rc1.target_value. The
output of this module is called rc1.setpt_value which represents the frequency of the saw-tooth we
want to generate.This frequency information is then passed to the ramp generator module.
•
RAMPGEN (ramp generator): to use this module, we instantiate an object rg1.
The input of this
module is rg1.rmp_freq . The rotating angle we generate (saw-tooth waveform) is rg1.rmp_out. This
angle is then used for the Inverse PARK transformation.
•
IPARK (Inverse Park Transformation): instance ipark1. Computed rotating angle is passed into the
ipark1.ang variable.
The d and q inputs to the inverse Park transformation control the command
magnitude via the variables ipark1.de and ipark1.qe.
•
SVGENDQ (Space Vector Generation): instance svgen_dq1.
This module takes the output of the
IPARK module and calculates the modulation to be applied on the duty cycle of the three pairs of PWM
connected to the three phases inverter bridge (svgen_dq1.Ta, svgen_dq1.Tb and svgen_dq1.Tc).
•
PWMGEN (Pulse Width Modulation Generation driver): this modules is the only one linked to the
DSP peripherals. Duty-cycles previously calculated are passed into the DSP PWM registers via the
instant pw1. PWMGEN takes care of the DSP PWM initialization (timer set-up, PWM polarity and
so on).
36
1. Run the PMS_Motor_data
M-le. This le initializes the following variables:
%Mechanical system
%Electrical part
DC_voltage = 200;
encoder_resolution = 2000;
%PWM
freq_max=75e6;
%Controller
Ts=5e-5;
1. Open the PMS_Motor_level1
36 See
37 See
37
Simulink
® model.
the le at <http://cnx.org/content/m24360/latest/PMS_Motor_data.m>
the le at <http://cnx.org/content/m24360/latest/PMS_Motor_level1.mdl>
Available for free at Connexions <http://cnx.org/content/col10713/1.1>
91
Figure 1.90: Space vector generation model
Vd Testing
1. Run the model and double-click the Stator Current and Rotor Speed scopes.
Available for free at Connexions <http://cnx.org/content/col10713/1.1>
92
CHAPTER 1.
Figure 1.91: Stator Current
Available for free at Connexions <http://cnx.org/content/col10713/1.1>
CONTROL
93
Figure 1.92: Rotor Speed
1.4.3.2 Running the PMSM in open loop
The purpose of this step is to simulate openloop operation with power-stage and motor connected and to
check out current sensing and feedback path.
Available for free at Connexions <http://cnx.org/content/col10713/1.1>
94
CHAPTER 1.
CONTROL
Figure 1.93: Open Loop
Key Modules Used for this level
In addition to the modules used in the previous section, we now start to build the feedback loop using:
•
ILEG2DCBUSMEAS_VCON (current leg and DC bus measurement):
This module initializes the
ADC to start automatic conversions of channels selected by the user on timer 1 underow.
ADC
conversion results are automatically formatted and stored into dedicated variables.
•
CLARKE (Clarke transform module):
coordinates in the reference frame (α,
•
•
This module converts the measured current into CLARKE
β ).
PARK (Park Transformation): This module converts the (α,
Open the PMS_Motor_level2
38 See
38
β)
coordinates into two DC quantities.
Simulink model.
the le at <http://cnx.org/content/m24360/latest/PMS_Motor_level2.mdl>
Available for free at Connexions <http://cnx.org/content/col10713/1.1>
95
Figure 1.94
Vd Testing
Figure 8: Open Loop Model
1. Run the model and double-click the Stator Current and Rotor Speed (same as previous section)
and Vd/Vq scopes.
Available for free at Connexions <http://cnx.org/content/col10713/1.1>
96
CHAPTER 1.
CONTROL
Figure 1.95
Ramp GeneratorVq Testing
Figure 9: Current Sensing
1. Now you may change the values of Vd and Vq, and check how it inuences the graphs above.
1.4.3.3 Closing the current loop
The purpose of this step is to close the current loop and to set the PI regulators correctly to get a stable
system while the motor is still running in speed open-loop.
Available for free at Connexions <http://cnx.org/content/col10713/1.1>
97
Figure 1.96: Current Sensing
Key Modules:
In addition to the modules already used, we use the PI module:
•
PIDREG3 (Proportional Integrator Derivative regulator): This module regulates the two currents id
and iq, generated in the Park module.
•
Open the PMS_Motor_level3.mdl
39 See
39
Simulink model.
the le at <http://cnx.org/content/m24360/latest/PMS_Motor_level3.mdl>
Available for free at Connexions <http://cnx.org/content/col10713/1.1>
98
CHAPTER 1.
CONTROL
Figure 1.97: Figure 11: Closing the Loop with the PI
Vd Testing
1. Run the model and double-click the Stator Current and Rotor Speed (same as previous section)
and Vd/Vq scopes.
Available for free at Connexions <http://cnx.org/content/col10713/1.1>
99
Figure 1.98: Stator Current
Available for free at Connexions <http://cnx.org/content/col10713/1.1>
100
CHAPTER 1.
Figure 1.99: Rotor Speed
Ramp GeneratorVq Testing
Available for free at Connexions <http://cnx.org/content/col10713/1.1>
CONTROL
101
Figure 1.100: Vd/Vq
For ease of use, the default PID parameters are already tuned. You can still play with them and observe
the results.
Within the watch windows, the PID coecients are displayed for both iq and id.
Using the
following picture will help you to interpret the variables.
1.4.3.4 The Speed measurement-Encoder
During this step we will check the encoder feedback and we will align the calculated angle with the shaft
angle.
Available for free at Connexions <http://cnx.org/content/col10713/1.1>
102
CHAPTER 1.
CONTROL
Figure 1.101: The Speed Measurement Encoder
KEY MODULES:
In addition to the modules already used, we use:
•
QEP (Quadrature encoder pulse module): instance qep1. This module initializes the QEP DSP unit.
This involves the associted timer (T2) set-up, the QEP DSP pins set-up and so on.
Calling the
initialization routine of the QEP module, the dedicated DSP registers are automatically congured
with no waste of time for the user in reading through the documentation. This module outputs an
electrical angle stored into the qep1.theta_elec variable which is then passed into the speed calculator
module. The encoder mounted on the motor is a 2000 lines encoder. In addition to the traditional
QEP signals (QEP1 and QEP2), it provides an index pulse, which toggles every complete mechanical
round.
This index is connected to the capture interrupt 3 of the DSP. In the corresponding served
interrupt, we clear the timer 2 counter ensuring to keep it between 0 and 8000: this way we have
a precise information on the rotor position.
The QEP module also takes care of the capture unit
initialization.
•
SPEED_MEAS_QEP (Speed measurement based on QEP information):
instance speed1.
Based
on system information (number of poles pairs for instance), this module outputs the motor speed
information.
Available for free at Connexions <http://cnx.org/content/col10713/1.1>
103
•
Open the PMS_Motor_level4
40
Simulink model.
Figure 1.102: Figure 16: Using the QEP
1. Run the model and double-click the PWM dutycycles and Rotor Speed scopes.
40 See
the le at <http://cnx.org/content/m24360/latest/PMS_Motor_level4.mdl>
Available for free at Connexions <http://cnx.org/content/col10713/1.1>
104
CHAPTER 1.
Figure 1.103: PWM Duty Cycles
Available for free at Connexions <http://cnx.org/content/col10713/1.1>
CONTROL
105
Figure 1.104: Rotor Speed
1.4.3.4.1 Align the sensed angle we the motor shaft.
Until now, the magnetic eld in the motor was generated without taking care of the shaft position. Even if
our motor is a synchronous motor, with no load and at load speed, it was easy to expect the shaft to start
and to catch the magnetic eld without problem. Now, if we want to close the speed loop, we need to know
the shaft angle at every moment. The shaft position is given by the encoder but we still have to align the
initial sensed position with the shaft.
For this, we use the Data Log module to display in real time the rmp_out variable (angle we used until
now to create the magnetic eld) and theta_elec (sensed angle).
Available for free at Connexions <http://cnx.org/content/col10713/1.1>
106
CHAPTER 1.
CONTROL
1.4.3.5 Speed Closed Loop
Figure 1.105: Speed Closed Loop
The purpose of this step is to verify the speed regulator, close the speed loop and tune up the gains for the
speed regulator if necessary. All the modules previously described are used in this nal step.
1.4.4 Real Time
The real-time software will run in the following hardware:
•
•
•
eZdsp F2812 (DSP control board based on the F2812)
DMC 550 (power stage board for BLDC and PMSM from Spectrum Digital
PMSM from Applied Motion Product
®
®)
For safety reason it is mandatory that you strictly respect the following picture to connect the DMC 550.
Available for free at Connexions <http://cnx.org/content/col10713/1.1>
107
Figure 1.106: Hardware Setup
During this build, the speed reference will be given to the DSP through a potentiometer placed on the
DMC 550 (R66). To start with, please put the potentiometer around its midle position.
1. MAKE SURE that the potentiometer is around its midle position
2. Generate the code in Simulink
3. Turn ON the PSU and set the voltage to 10V.
The motor should have good response time now thanks to the speed closed loop. As usual the PID controller
is already tuned. Using the same graphical display we used during the lab 4 you can see the impact of the
PID parameters.
Since all the kits are dierent, the default settings for the current and speed PID may not be suitable
and the maximum command may be instable
Moving the speed potentiometer, you can appreciate the fast and smooth response time!
1.4.4.1 To Stop the system properly
1. Turn OFF the PSU
2. Halt the DSP: From the pull-down menu, Debug
→
Halt;
3. Close the Model
Available for free at Connexions <http://cnx.org/content/col10713/1.1>
108
CHAPTER 1.
Available for free at Connexions <http://cnx.org/content/col10713/1.1>
CONTROL
Chapter 2
Signal Processing and Communication
2.1 Acoustic Noise Cancellation1
2.1.1 Introduction
The Least Mean Squares (LMS) Algorithm can be used in a range of Digital Signal Processing applications
such as echo cancellation and acoustic noise reduction.
This laboratory shows how to design a model of LMS Noise Cancellation using Simulink and run it on a
Texas Instruments C6000 DSP.
2.1.1.1 Objectives
•
Design a model of LMS Noise Reduction for the Texas Instruments C6000 family of DSP devices using
® and Simulink®.
MATLAB
•
•
Modify an existing Simulink demonstration model for use as a template.
Run the project on the Texas Instruments DSK6713 with a microphone and computer loudspeakers /
headphones.
2.1.1.2 Level
Intermediate - Assumes prior knowledge of MATLAB and Simulink.
It also requires a theoretical under-
standing of matrices and the LMS algorithm.
2.1.1.3 Hardware and Software Requirements
This laboratory was originally developed using the following hardware and software:
•
•
•
•
MATLAB R2006b with Embedded Target for TI C6000 and the Signal Processing Toolbox.
Code Composer Studio (CCS) v3.1
Texas Instruments DSK6713 hardware.
Microphone and computer loudspeakers / headphones.
1 This
content is available online at <http://cnx.org/content/m22178/1.1/>.
Available for free at Connexions <http://cnx.org/content/col10713/1.1>
109
110
CHAPTER 2.
SIGNAL PROCESSING AND COMMUNICATION
2.1.1.4 Related Files
•
•
•
2
Powerpoint Presentation AcousticNoiseCancellation.ppt
Simulink Model for Simulation- AcousticNoiseCancellation.mdl
3
Simulink Model for Real-Time AcousticNoiseCancellationDSKC6713.mdl
4
2.1.2 Simulation
You will now start with a simple Simulink model and run it to see how it works.
2.1.2.1 Opening the Acoustic Noise Cancellation Model
5
Open the AcousticNoiseCancellation.mdl
Figure 2.1: Opening the AcousticNoiseCancellation Model
Run the model.
2 See
3 See
4 See
5 See
the le at <http://cnx.org/content/m22178/latest/AcousticNoiseCancellation.ppt>
the le at <http://cnx.org/content/m22178/latest/AcousticNoiseCancellation.mdl>
the le at <http://cnx.org/content/m22178/latest/AcousticNoiseCancellationDSKC6713.mdl>
the le at <http://cnx.org/content/m22178/latest/AcousticNoiseCancellation.mdl>
Available for free at Connexions <http://cnx.org/content/col10713/1.1>
111
2.1.2.2 Inputs and Outputs of LMS Filter
The output from the LMS Filter starts at zero and grows slowly. Initially, some of the sine wave information
is lost as LMS Error.
Figure 2.2: LMS Filter Inputs and Outputs
2.1.2.3 LMS Filter Weights (Coecients)
The LMS Filter Weights all start at zero and take several iterations to reach their nal values.
Available for free at Connexions <http://cnx.org/content/col10713/1.1>
112
CHAPTER 2.
SIGNAL PROCESSING AND COMMUNICATION
Figure 2.3: LMS Filter Weights (Coecients)
2.1.2.4 Tuning the Model
The critical variable in the LMS Filter is the Step size (mu). This sets the rate of convergence of the LMS
lter.
Available for free at Connexions <http://cnx.org/content/col10713/1.1>
113
Figure 2.4: Changing the Step size (mu) to 0.1
Double-click on the LMS Filter block and change the Step size (mu) to 0.1
Run the model.
Available for free at Connexions <http://cnx.org/content/col10713/1.1>
114
CHAPTER 2.
SIGNAL PROCESSING AND COMMUNICATION
2.1.2.5 Filter Outputs for Step size (mu) = 0.1
When the Step size (mu) is increased, LMS algorithm converges more quickly, but at the expense of
granularity the LMS Filter Output is not as smooth.
Figure 2.5: Input and LMS Filter Outputs for Step size (mu) = 0.1
2.1.2.6 Filter Weights for Step size (mu) = 0.1
Note that the lter weights (coecients) do not attain smooth values, as would be the case for smaller values
of Step size (mu).
Available for free at Connexions <http://cnx.org/content/col10713/1.1>
115
Figure 2.6: LMS Filter Weights for Step size (mu) = 0.1
2.1.2.7 Changing the Delay
Part of the Acoustic Noise Algorithm is the delay. The delay should ideally be at least half a wavelength so
the two inputs to the LMS Filter have dierent random noise.
Available for free at Connexions <http://cnx.org/content/col10713/1.1>
116
CHAPTER 2.
SIGNAL PROCESSING AND COMMUNICATION
Figure 2.7: Changing the Delay
Experiment with dierent values of delay to see how it eects the operation of the LMS Filter.
2.1.2.8 Changing the Number of Weights
Double-click on the LMS Block and change the Filter Size (number of Weights).
If the number of Weights is large, the algorithm will be slow to run.
If the number of Weights is too small, the lter will not remove the noise properly.
Available for free at Connexions <http://cnx.org/content/col10713/1.1>
117
Figure 2.8: Changing the Filter Length
Available for free at Connexions <http://cnx.org/content/col10713/1.1>
118
CHAPTER 2.
SIGNAL PROCESSING AND COMMUNICATION
2.1.2.9 Summary
From practical experience, you should now know how to use LMS algorithm and how you can adjust the
Step size (mu), the lter delay and the number of weights to obtain optimum performance.
You will now apply this to building a real-time model.
2.1.3 Real-Time Model
You have now run the simulation and understand the operation of the LMS Filter.
You will now implement the Real-Time Acoustic Noise Cancellation Model using the Texas Instrument
C6713.
2.1.3.1 Texas Instruments DSK6713 Setup
Figure 2.9: Texas Instruments DSK6713 Setup
Alternatively, you can use computer loudspeakers.
2.1.3.2 Starting up Code Composer Studio
2.1.3.2.1 Connecting the DSK6713
Start Code Composer Studio for DSK6713 and use Debug -> Connect
Available for free at Connexions <http://cnx.org/content/col10713/1.1>
119
Figure 2.10: Startup Screen for Code Composer Studio (CCS)
2.1.3.2.2 Opening an Existing Model
Start MATLAB 7.3.0 R2006b:
Available for free at Connexions <http://cnx.org/content/col10713/1.1>
120
CHAPTER 2.
SIGNAL PROCESSING AND COMMUNICATION
Figure 2.11: Opening an Existing Demo
Click on Demos. The following screen will appear:
Available for free at Connexions <http://cnx.org/content/col10713/1.1>
121
Figure 2.12: Selecting the Audio Demo Models
Highlight Embedded Target for TI C6000 DSP then Audio. Click on Wavelet Denoising. We are
going to use this as our template.
2.1.3.2.3 Viewing the Original Model
The Wavelet Denoising model is now displayed.
Available for free at Connexions <http://cnx.org/content/col10713/1.1>
122
CHAPTER 2.
SIGNAL PROCESSING AND COMMUNICATION
Figure 2.13: Wavelet Denoising Parent
2.1.3.2.4 Saving the Model
For convenience, save the model to the MATLAB Work directory, where most models are stored.
Available for free at Connexions <http://cnx.org/content/col10713/1.1>
123
Figure 2.14: Saving the Model to the MATLAB Work directory
2.1.3.2.5 Changing the Title
Delete the Info box. Change the title to LMS Noise Reduction. You may also wish to move the DSK6713
icon to the left hand side.
Available for free at Connexions <http://cnx.org/content/col10713/1.1>
124
CHAPTER 2.
SIGNAL PROCESSING AND COMMUNICATION
Figure 2.15: LMS Noise Reduction Parent
2.1.3.2.6 The Original Wavelet Noise Reduction Algorithm
Double-click on the function() box. The Wavelet Noise Reduction Algorithm model is now displayed.
Available for free at Connexions <http://cnx.org/content/col10713/1.1>
125
Figure 2.16: Wavelet Denoising Algorithm
2.1.3.2.7 Delete Blocks
Delete the blocks and connect the input directly to the output. Add a title.
Figure 2.17: LMS Denoising Algorithm Template
Available for free at Connexions <http://cnx.org/content/col10713/1.1>
126
CHAPTER 2.
SIGNAL PROCESSING AND COMMUNICATION
2.1.3.2.8 Overview of the LMS Model
We are going to implement the model shown below.
We will now update the empty model by dragging-and-dropping some library components onto the model.
Figure 2.18: Overview of the LMS Algorithm
2.1.3.2.9 Changing the Input to Microphone
Double-click on the blue box to the left marked DSK6713 ADC. The following screen will appear.
Available for free at Connexions <http://cnx.org/content/col10713/1.1>
127
Figure 2.19: Setting up the ADC for Mono Microphone Input
Change the ADC source to Mic In.
If you have a quiet microphone, select +20dB Mic gain boost.
Set the Sampling rate (Hz) to 48 kHz.
Set the Samples per frame to 64.
When done, click on OK.
Important: Make sure the Stereo box is empty.
Available for free at Connexions <http://cnx.org/content/col10713/1.1>
128
CHAPTER 2.
SIGNAL PROCESSING AND COMMUNICATION
2.1.3.2.10 The DAC Settings
The DAC settings need to match those of the ADC. Check that it uses the same sampling rates. Click on
OK.
Figure 2.20: Setting the DAC Parameters
2.1.3.2.11 Adding an LMS Block
The Simulink block for LMS is to be found in the Signal Processing Toolbox.
Select View -> Library Browser -> Signal Processing Blockset ->Filtering-> Adaptive Filters.
Highlight Adaptive Filters. Drag-and-drop the LMS Filter block onto the model.
Available for free at Connexions <http://cnx.org/content/col10713/1.1>
129
Figure 2.21: Adding an LMS Filter Block
2.1.3.2.12 Setting the LMS Filter Parameters
The most critical variable in an LMS lter is the Step size (mu).
If mu is too small, the lter has very ne resolution, but reacts too slowly to the audio signal.
If mu is too great, the lter reacts very quickly, but the error also remains large.
We will start with 0.005.
Available for free at Connexions <http://cnx.org/content/col10713/1.1>
130
CHAPTER 2.
SIGNAL PROCESSING AND COMMUNICATION
Figure 2.22: Setting the Parameter Set size (mu)
Available for free at Connexions <http://cnx.org/content/col10713/1.1>
131
2.1.3.2.13 Adding a Delay
From the Signal Processing Blockset, highlight Signal Operations. Drag-and-drop the Delay
6
block onto
the model.
Figure 2.23: Adding a Delay
2.1.3.2.14 Setting the Delay Parameters
Because we are working with frames of 64 samples, it is convenient congure the delay using frames. Doubleclick on the Delay block.
Change the Delay units to Frames.
Set the Delay (frames) to 1. This makes the delay 64 samples.
6 Since
we are working with frames, the delay from Discrete Components library will not work!
Available for free at Connexions <http://cnx.org/content/col10713/1.1>
132
CHAPTER 2.
SIGNAL PROCESSING AND COMMUNICATION
Figure 2.24: Setting the Delay Size
2.1.3.2.15 Adding a DIP Switch and LED
So we can hear the dierence without LMS denoising and with LMS noise reduction, we will use a DIP
switch of the DSK6713.
Available for free at Connexions <http://cnx.org/content/col10713/1.1>
133
Figure 2.25: Adding a Switch and LED
Select View -> Library Browser -> Embedded Target for TI C6000 DSP. Highlight DSK6713 Board
Support.
Drag-and-drop the Switch block onto the model. Also drag-and-drop the LED block onto the model.
2.1.3.2.16 DIP Switch Settings
The DIP switch needs to be congured. Double-click on the Switch block.
Select all the boxes and set Data type to Integer. The Sample time should also be set to 1.
Available for free at Connexions <http://cnx.org/content/col10713/1.1>
134
CHAPTER 2.
SIGNAL PROCESSING AND COMMUNICATION
Figure 2.26: Setting up the DIP Switch Values
2.1.3.2.17 Adding a Constant, Switch and Relational Operator
We now need to setup a way to switch between straight through without noise reduction and with LMS
noise reduction.
Select View -> Library Browser -> Simulink. Highlight Commonly Used Blocks.
Drag-and-drop a Constant onto the model.
Drag-and-drop a Switch block onto the model.
Drag-and-drop a Relational Operator block onto the model.
Available for free at Connexions <http://cnx.org/content/col10713/1.1>
135
Figure 2.27: Selecting the Commonly Used Blocks
2.1.3.2.18 Setting the Constant Value
The switch values lie between 0 and 15. We will use switch values 0 and 1. Double-click on the Constant
block. Set the Constant value to 1 and the Sample time to inf .
Available for free at Connexions <http://cnx.org/content/col10713/1.1>
136
CHAPTER 2.
SIGNAL PROCESSING AND COMMUNICATION
Figure 2.28: Setting the Echo Delay Gain
2.1.3.2.19 Setting the Constant Data Type
Click on the Signal Data Types tab. Set the Output data type mode to int16. This is compatible with
the DAC on the DSK6713.
Available for free at Connexions <http://cnx.org/content/col10713/1.1>
137
Figure 2.29: Data Type Conversion to 16-bit Integer
2.1.3.2.20 Setting the Relational Operator Type
Double click on the Relational Operator block. Change the Relational operator to ==. Click on the
Signal Data Types tab.
Available for free at Connexions <http://cnx.org/content/col10713/1.1>
138
CHAPTER 2.
SIGNAL PROCESSING AND COMMUNICATION
Figure 2.30: Changing the Relational Operator
2.1.3.2.21 Setting the Relational Operator Data Type
Set the Output data type mode to Boolean. Click on OK.
Available for free at Connexions <http://cnx.org/content/col10713/1.1>
139
Figure 2.31: Changing the Output Data Type
2.1.3.2.22 Joining the Blocks
Move the blocks and join them as shown in the Figure below.
Available for free at Connexions <http://cnx.org/content/col10713/1.1>
140
CHAPTER 2.
SIGNAL PROCESSING AND COMMUNICATION
Figure 2.32: Joining the Blocks
2.1.3.2.23 Returning to the Parent System
From the Toolbar, select the Up Arrow icon. This returns you to the next higher level.
Figure 2.33: Returning to the Parent System
Available for free at Connexions <http://cnx.org/content/col10713/1.1>
141
2.1.3.3 Building the Model
2.1.3.3.1 Selecting Real-Time Workshop
Select Tools -> Real-Time Workshop -> Build Model.
Figure 2.34: Building the Model
2.1.3.3.2 Frames Displayed on Model
When built, the single lines are replaced by double lines. This shows frames.
Available for free at Connexions <http://cnx.org/content/col10713/1.1>
142
CHAPTER 2.
SIGNAL PROCESSING AND COMMUNICATION
Figure 2.35: Frames
2.1.3.3.3 The Completed Model Running on Code Composer Studio
From the folders on the left, select the source code for the project.
Available for free at Connexions <http://cnx.org/content/col10713/1.1>
143
Figure 2.36: The Completed Model Running in Code Composer Studio
2.1.3.4 Dierent Settings on the DSK6713
2.1.3.4.1 Microphone Straight Through to Loudspeakers
To check out the microphone and loudspeakers, set the DIP switches on the DSK6713 as follows:
Available for free at Connexions <http://cnx.org/content/col10713/1.1>
144
CHAPTER 2.
SIGNAL PROCESSING AND COMMUNICATION
Figure 2.37: Switch Position 0
The microphone is fed directly to the loudspeakers. There is no LMS noise reduction.
2.1.3.4.2 Switch Position for LMS Noise Reduction
To run the LMS Noise Reduction subsystem, set the DIP switch to 1.
Figure 2.38: Switch Position 1 for LMS Noise Reduction
Available for free at Connexions <http://cnx.org/content/col10713/1.1>
145
2.1.4 Some Things to Try
You may wish to experiment with dierent settings. Here are some suggestions.
2.1.4.1 Experiment with LMS Filter Settings
Change the value of Step size (mu) between 0.0001 and 0.5. This is the critical value.
Low values of mu give good resolution, but a slow reaction time.
High values of mu give less resolution, but faster reaction times.
Find the best value of mu for noise reduction on the TI DSK6713.
Available for free at Connexions <http://cnx.org/content/col10713/1.1>
146
CHAPTER 2.
SIGNAL PROCESSING AND COMMUNICATION
Figure 2.39: Conguring the LMS Filter Block Parameter
Available for free at Connexions <http://cnx.org/content/col10713/1.1>
147
2.1.4.2 Experiment with LMS Filter Settings
Try dierent value of Filter Length. What is the minimum value that will allow the lter to work correctly?
2.1.4.3 Change from LMS Filter to RLS Filter
Inside the Adaptive Filters are dierent LMS types. Which are suitable for LMS denoising and which are
not?
Figure 2.40: Available Adaptive Filter Types
Figure 40 MATLAB
and
Simulink
are
registered
trademarks
of
The
www.mathworks.com/trademarks for a list of additional trademarks.
MathWorks,
Inc.
See
Other product or brand names
may be trademarks or registered trademarks of their respective holders.
Available for free at Connexions <http://cnx.org/content/col10713/1.1>
148
CHAPTER 2.
SIGNAL PROCESSING AND COMMUNICATION
2.2 Amplitude Modulation7
2.2.1 Introduction
This chapter presents the use of the DSK6713 to demonstrate the features of Amplitude Modulation (AM)
transmission and reception. The model runs in real-time and enables the use to select:
1. The AM algorithm
2. The transmission and reception parameters (modulation index and carrier frequency).
The process comprises:
1. Creating a simulation model (not R-T) for the AM transmitter/receiver.
2. Migration to Real-time of the Simulation Model
3. Building a Graphic Users Interface (GUI) to operate the real-time implementation.
2.2.1.1 Related Files
•
•
•
•
•
•
•
•
Powerpoint Presentation - Amplitude Modulation.ppt
Simulink Model for Simulation - AM_Simulation.mdl
MATLAB GUI for Real-Time - AM.g
8
9
10
11
GUI m-leAM.m
m-le for Selection of AM Reception ChangeModel.m
12
Simulink Model for Coherent Detection AM_Coherent.mdl
13
Simulink Model for Square Root (SQRT) Detection AM_Sqrt.mdl
14
15
Congurable Carrier Simulink Model Congurable_Carrier.mdl
2.2.2 Simulation
2.2.2.1 The Environment
Figure 1 shows the data ow 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.
7 This content is available online at <http://cnx.org/content/m22187/1.2/>.
8 See the le at <http://cnx.org/content/m22187/latest/Amplitude Modulation.ppt>
9 See the le at <http://cnx.org/content/m22187/latest/AM_Simulation.mdl>
10 See the le at <http://cnx.org/content/m22187/latest/AM.g>
11 See the le at <http://cnx.org/content/m22187/latest/AM.m>
12 See the le at <http://cnx.org/content/m22187/latest/ChangeModel.m>
13 See the le at <http://cnx.org/content/m22187/latest/AM_Coherent.mdl>
14 See the le at <http://cnx.org/content/m22187/latest/AM_Sqrt.mdl>
15 See the le at <http://cnx.org/content/m22187/latest/Congurable_Carrier.mdl>
Available for free at Connexions <http://cnx.org/content/col10713/1.1>
149
Figure 2.41: Simulation Environment
2.2.2.2 The Procedure
2.2.2.2.1 Building the Transmitter
The basic modulation mathematical description is given by:
y (t) = [1 + m (t)] cos (2πf c t)
Where:
cos (2πf c t)
- The carrier signal
m (t)
- The modulation index
Table 2.1
Available for free at Connexions <http://cnx.org/content/col10713/1.1>
150
CHAPTER 2.
SIGNAL PROCESSING AND COMMUNICATION
Figure 2.42: AM Transmission Principle
•
•
Start by creating a new model in Simulink
®
Open the Simulink library browser and add the DSP sine-wave to your model. This blocks will represent
the information signal m(t).
Available for free at Connexions <http://cnx.org/content/col10713/1.1>
151
Figure 2.43: The Sine Wave Generator Block
•
Congure 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 its label
to information.
Available for free at Connexions <http://cnx.org/content/col10713/1.1>
152
CHAPTER 2.
SIGNAL PROCESSING AND COMMUNICATION
Figure 2.44: Information Signal Conguration Parameters
•
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
Available for free at Connexions <http://cnx.org/content/col10713/1.1>
153
identical to the ones of the information signal. Change its label to carrier
•
Add new DSP-constant to your model:
Figure 2.45: Adding a DSP constant
•
Double-click on the constant object and set its constant value to 1.5:
Available for free at Connexions <http://cnx.org/content/col10713/1.1>
154
CHAPTER 2.
SIGNAL PROCESSING AND COMMUNICATION
Figure 2.46: Set a constant value
•
Add a new adder object from:
Available for free at Connexions <http://cnx.org/content/col10713/1.1>
155
Figure 2.47: Addes
•
•
Add a new multiplexer from the same directory as the adder (choose product).
Add a new scope object:
Available for free at Connexions <http://cnx.org/content/col10713/1.1>
156
CHAPTER 2.
SIGNAL PROCESSING AND COMMUNICATION
Figure 2.48: Scope
•
Set the number of frames parameter to 5.
This parameter determines the horizontal scaling of the
presented signal.
Available for free at Connexions <http://cnx.org/content/col10713/1.1>
157
Figure 2.49: Vector Scope Conguration
•
Place the objects in the following way:
Available for free at Connexions <http://cnx.org/content/col10713/1.1>
158
CHAPTER 2.
SIGNAL PROCESSING AND COMMUNICATION
Figure 2.50: The Transmitter Model
•
Run the model, pause the simulation and activate the scope window. The modulated signal should be
displayed as follows:
Available for free at Connexions <http://cnx.org/content/col10713/1.1>
159
Figure 2.51: AM Modulation Signal
2.2.2.2.2 The AM Receiver (Square Root Demodulator)
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.
Available for free at Connexions <http://cnx.org/content/col10713/1.1>
160
CHAPTER 2.
SIGNAL PROCESSING AND COMMUNICATION
Figure 2.52: SQRT Demodulation Principle of Operation
•
Add the new math function block to your model. This block can be congured to implement various
mathematical functions.
Available for free at Connexions <http://cnx.org/content/col10713/1.1>
161
Figure 2.53: Square Function
•
Congure the block to calculate the square:
Available for free at Connexions <http://cnx.org/content/col10713/1.1>
162
CHAPTER 2.
SIGNAL PROCESSING AND COMMUNICATION
Figure 2.54: Select Math Function
•
Use the math function block to create the Square root function. You may retrieve it from the library
or copy the square block.
•
Add a digital lter design block.
This block enables you to design lters using the MATLAB
FDATool.
Available for free at Connexions <http://cnx.org/content/col10713/1.1>
®
163
Figure 2.55: Digital Filter Design
•
Congure the lter to be Low-Pass Filter. Since the carrier frequency (fc) is 15 KHz and the maximal
frequency of the information is 1 KHz, the lter will be designed to pass frequencies below 5 KHz, and
rejects frequencies higher than 10 KHz (please refer to Figure 16).
Available for free at Connexions <http://cnx.org/content/col10713/1.1>
164
CHAPTER 2.
SIGNAL PROCESSING AND COMMUNICATION
Figure 2.56: LPF Design Window
•
•
•
Add a "Multiplier" and a "Subtract"
16
block.
Add two "DSP Constant" blocks.
Add the matrices concatenation object. This object will enable the modulated and the de-modulated
signals to be displayed simultaneously in the scope:
16 The
subtraction is created by reconguring the adder block, and choosing +- instead of: ++
Available for free at Connexions <http://cnx.org/content/col10713/1.1>
165
Figure 2.57: Matrix Concatenate
•
The blocks should be connected as shown in Figure 18.
Available for free at Connexions <http://cnx.org/content/col10713/1.1>
166
CHAPTER 2.
SIGNAL PROCESSING AND COMMUNICATION
Figure 2.58: AM Simulation Model
•
Run the simulation (push the play button). Double click on the scope. Scale the display to t the
scope window (Choose from the menus: Axes=>Autoscale). Choose a dierent color for each signal
(Please refer to Figure 19).
Available for free at Connexions <http://cnx.org/content/col10713/1.1>
167
Figure 2.59: Displaying the Modulated and Demodulated Signals
You should get the signals presented bellow:
Available for free at Connexions <http://cnx.org/content/col10713/1.1>
168
CHAPTER 2.
SIGNAL PROCESSING AND COMMUNICATION
Figure 2.60: The Video Viewer Display
•
You may change the simulation parameters, and check their inuence.
2.2.3 Real Time Implementation
2.2.3.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 denition block (DSK6713) will be added.
Figure 21 shows the block-diagram for the real time implementation.
Available for free at Connexions <http://cnx.org/content/col10713/1.1>
169
Figure 2.61: Real Time Implementation Environment
Equipment Used (shown in Figure 22):
•
•
•
DSK6713
Dual Channel Oscilloscope
Signal Generator
Available for free at Connexions <http://cnx.org/content/col10713/1.1>
170
CHAPTER 2.
SIGNAL PROCESSING AND COMMUNICATION
Figure 2.62: Equipment Used
We have 4 signals (4 cables):
•
•
•
Information- the signal to be modulated
Modulated- the DSK creates a modulation of the given information
Feedback- since the transmitter and the receiver are running on the same platform, we need to perform
a loopback from the transmitter to the receiver and this is exactly the feedback signal, the modulated
signal that is broadcasted by the transmitter and used as input for the receiver.
•
Demodulated- the signal that the receiver outputs after the demodulation process.
2.2.3.2 The Procedure
•
Open the model created in the previous chapter
Available for free at Connexions <http://cnx.org/content/col10713/1.1>
171
•
•
Remove the scope and the information signal (the 1,000 Hz).
Open the Simulink library browser and add the "C6713DSK".
Figure 2.63: The C6713DSK Block
•
Add the Analog to Digital and Digital to Analog converters (ADC and DAC) to your model:
Figure 2.64: A/D and D/A converters
Available for free at Connexions <http://cnx.org/content/col10713/1.1>
172
•
CHAPTER 2.
SIGNAL PROCESSING AND COMMUNICATION
Add the multi-port selector, in order to split the stereo input.
Figure 2.65: Multiport Selector
•
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.
Available for free at Connexions <http://cnx.org/content/col10713/1.1>
173
Figure 2.66: Multiport Conguration
1. Congure the ADC and DAC blocks to a sampling rate to 96 KHZ and 16-bit samples.
Available for free at Connexions <http://cnx.org/content/col10713/1.1>
174
CHAPTER 2.
SIGNAL PROCESSING AND COMMUNICATION
Figure 2.67: DAC and ADC Conguration
•
The nal model should look as follows:
Available for free at Connexions <http://cnx.org/content/col10713/1.1>
175
Figure 2.68: AM (SQRT) Real Time Model
•
You should congure the DSP constants as shown in Figure 28. The frame period for all constants
should be -1
Available for free at Connexions <http://cnx.org/content/col10713/1.1>
176
CHAPTER 2.
SIGNAL PROCESSING AND COMMUNICATION
Figure 2.69: Constant Value Parameters
•
•
•
Build the project and load the program to the DSK memory using ctrl+B.
Make sure that the signals generator amplitude is set to 1 Volt and frequency of [0.1,5] kHz.
Display the modulated and demodulated signals in the scope.
2.2.4 Model Extensions
In this section we will extend the functionality of the example. Adding two more features:
•
A variable frequency carrier generator (Please refer to secion "A Congurable Carrier Wave Generator"
in the Appendix)
•
An additional model for AM detection (Please refer to secion "The Coherent Detector (in brief )" in
the Appendix).
•
Build GUI that we will enable:
·
·
·
Changing the modulation index
Changing the carrier frequency
Selecting the detection scheme
The modulation index and carrier frequency will be changed through RTDX.
•
Open the model created in the previous section
Available for free at Connexions <http://cnx.org/content/col10713/1.1>
177
•
Replace the constant modulation index by an RTDX input (Please refer to Figure 30), and name it
InputModulation.
Figure 2.70: RTDX input
•
Congure the RTDX input object to the values described bellow:
Available for free at Connexions <http://cnx.org/content/col10713/1.1>
178
CHAPTER 2.
SIGNAL PROCESSING AND COMMUNICATION
Figure 2.71: RTDX Input Conguration
•
Replace the sine wave block used for the carrier by the congurable carrier blocks (you may nd them
Available for free at Connexions <http://cnx.org/content/col10713/1.1>
179
17
in the Congurable_Carrier.mdl
18
le)
, and create a subsystem for the carrier generator as shown
in Figure 32.
Your model should look as shown in Figure 33.
17 See the le at <http://cnx.org/content/m22187/latest/Congurable_Carrier.mdl>
18 The principle of operation of the Congurable Carrier Module is described in the Appendix.
Available for free at Connexions <http://cnx.org/content/col10713/1.1>
180
CHAPTER 2.
SIGNAL PROCESSING AND COMMUNICATION
Figure 2.72: Inserting a Congurable Carrier
Figure 32 Inserting a Congurable Carrier
Available for free at Connexions <http://cnx.org/content/col10713/1.1>
181
Figure 2.73: AM (SQRT) Model with Congurable Carrier
•
Enter the Conguration Parameters menu (ctrl+E). Choose Real-Time Workshop=>TIC6000 CodeGenerator, In The Run-Time box change the Build Action to Build
19 The
19
:
models will be loaded by the GUI script.
Available for free at Connexions <http://cnx.org/content/col10713/1.1>
182
CHAPTER 2.
SIGNAL PROCESSING AND COMMUNICATION
Figure 2.74: Simulation Parameters
Push the OK button and close the Conguration Parameters window.
Rebuild *.out le using ctrl+B.
•
Open the AM_Coherent.mdl
20
le, and repeat step for this le.
You now have two load les each one corresponding to a dierent AM scheme.
2.2.4.1 Creating the GUI
•
•
Open a new GUI (Enter GUIDE in the MATLAB command line)
Add 2 sliders and one list box to the GUI, so it would look like:
20 See
the le at <http://cnx.org/content/m22187/latest/AM_Coherent.mdl>
Available for free at Connexions <http://cnx.org/content/col10713/1.1>
183
Figure 2.75: GUI Design Screen
•
Now, double click on the list-box and change the string eld:
Available for free at Connexions <http://cnx.org/content/col10713/1.1>
184
CHAPTER 2.
SIGNAL PROCESSING AND COMMUNICATION
Figure 2.76: List Box Conguration Screen
Change the string eld to:
Coherent
SQRT
•
•
•
In the Modulation index slider set: Min=0.75, Max=1.5.
In the Carrier Frequency slider set: Min=1, Max=4.
Press the play button so you can save your GUI and open the GUI script m-le.
2.2.4.2 The script le
In the script we have to perform the following tasks:
•
•
When the GUI is launched the DSK should be loaded with a default model (SQRT)
When the user selects a new model> Its correspondent *.out le should be loaded to the DSP.
Available for free at Connexions <http://cnx.org/content/col10713/1.1>
185
•
When the modulation index is changed, its new value should be written to the DSP through the
correspondent RTDX channel.
•
When the carrier frequency modulation index is changed, its new value should be written to the DSP
through the correspondent RTDX channel.
The following steps describe this implementation.
•
The initialization routine AM_OpeningFcn:
function AM_OpeningFcn(hObject, eventdata, handles, varargin)
last_model=1;
handles.last_model=last_model;
modelName = gcs;
%connect to the board
CCS_Obj = connectToCCS(modelName);
% Identify RTDX channel names/modes
chan_struct(1).name = 'InputModulation';
chan_struct(1).mode = 'w';
chan_struct(2).name = 'freq';
chan_struct(2).mode = 'w';
handles.rtdx_chan1=chan_struct(1);
handles.rtdx_chan2=chan_struct(2);
% Identify RTDX host buffer parameters
RTDX_config_struct.Buffsize= 32768;
RTDX_config_struct.Nbuffers = 4;
RTDX_config_struct.Mode = 'continuous';
%building the full path of the file to be loaded
CodegenDir = fullfile(pwd, ['AM_Coherent' '_c6000_rtw']);
OutFile = fullfile(CodegenDir, ['AM_Coherent' '.out']);
%Load is needed for rtdx setup
CCS_Obj.load(OutFile,20);
% Set up RTDX
r = setupRTDX(CCS_Obj, chan_struct, RTDX_config_struct);
handles.pipe=r;
handles.CCS_Obj=CCS_Obj;
%last_x and last_y are the initial values of
%the Index and the carrier respectively
last_x=1;
last_y=15000;
handles.last_x=last_x;
handles.last_y=last_y;
handles.output = hObject;
% Enable all RTDX channels
r.enable('all');
% Update handles structure
guidata(hObject, handles);
%use the change-model function in order to load the current model.
%this function loads a model to the DSK after initiallization (= the code
%above)
ChangeModel(handles.last_model,handles.CCS_Obj,handles.pipe,handles.last_x,handles.last_y);
Available for free at Connexions <http://cnx.org/content/col10713/1.1>
186
CHAPTER 2.
SIGNAL PROCESSING AND COMMUNICATION
)
•
When you select a new model, the following code is invoked:
function listbox1_Callback(hObject, eventdata, handles)
handles.last_model=get(hObject,'Value') ;
ChangeModel(handles.last_model,handles.CCS_Obj,handles.pipe,handles.last_x,handles.last_y);
An external function (written in the ChangeModel.m le) will be used to select the model:
%1. halts the current model
%2. free the rtdx channel
%3. redefine the rtdx channel
%4. loads the current model
%5. binds the rtdx to the current model
%6. run the CCS and enable the rtdx.
%7.writes the last given index modulation to the rtdx
%parameters:
%m - flag that tells if the model is coherential or sqrt
%CCS_Obj - the target
%r_old - the old rtdx channel
%last_x - to keep the current Index
%last_y - to keep the current carrier frequency
function r=ChangeModel(m,CCS_Obj,r_old,last_x,last_y)
%halt the current model
CCS_Obj.halt;
%free the curent rtdx channel
cleanupRTDX(CCS_Obj,r_old);
%redefine the rtdx:
chan_struct(1).name = 'InputModulation';
chan_struct(1).mode = 'w';
chan_struct(2).name = 'freq';
chan_struct(2).mode = 'w';
handles.rtdx_chan1=chan_struct(1);
handles.rtdx_chan2=chan_struct(2);
% Identify RTDX host buffer parameters
RTDX_config_struct.Buffsize= 32768;
RTDX_config_struct.Nbuffers = 4;
RTDX_config_struct.Mode = 'continuous';
%reload the new model
switch m
case 1
model='AM_Coherent';
case 2
model='AM_Sqrt';
end
CodegenDir = fullfile(pwd, [model '_c6000_rtw']);
OutFile = fullfile(CodegenDir, [model '.out']);
CCS_Obj.load(OutFile,20);
% set up the new rtdx channel and run the target
Available for free at Connexions <http://cnx.org/content/col10713/1.1>
187
r = setupRTDX(CCS_Obj, chan_struct, RTDX_config_struct);
CCS_Obj.run;
r.enable('all');
% keep the last Index and carrier frequency:
if last_x∼=1
r.writemsg(chan_struct(2).name,1/last_x);
end
•
Changing the modulation index:
function slider1_Callback(hObject, eventdata, handles)
last_x=handles.last_x;
r=handles.pipe;
x=single(get(hObject,'Value'));
if or (y<last_y,y>last_y) %if the Index was changed:
r.writemsg(handles.rtdx_chan1.name,1/x);
%the Index increases when the added amplitude decreases
%and thats the reason that we write 1/x to the rtdx
handles.last_x=x;
end
guidata(hObject, handles);
•
Changing the carrier frequency:
function slider2_Callback(hObject, eventdata, handles)
last_y=handles.last_y;
r=handles.pipe;
y=single(get(hObject,'Value'));
if or (y<last_y,y>last_y)
r.writemsg(handles.rtdx_chan2.name,y);
handles.last_y=y;
end
guidata(hObject, handles);
Available for free at Connexions <http://cnx.org/content/col10713/1.1>
188
CHAPTER 2.
SIGNAL PROCESSING AND COMMUNICATION
Figure 2.77: AM Model Graphic User Interface
You may change the modulation index and frequency for both models, and observe its inuence on the
modulated and demodulated signals.
2.2.5 Appendix
2.2.5.1 A Congurable Carrier Wave Generator
The Simulink sine wave block cannot be congured during run-time; its frequency is a parameter that should
be set in advance. We will introduce the implementation of a block where the frequency is a variable that
can be set in real-time (In this case using RTDX). The block is based on the following relationship:
cosωc t
= Re ejωc t
(2.1)
In the discrete case the following relationship applies:
cosωc nTs
= cos2π
h
i
fc
fc
n = Re ej2π fs n
fs
Available for free at Connexions <http://cnx.org/content/col10713/1.1>
(2.2)
189
The following model implements the last equation. Please note that a feedback path was included for phase
continuity
Figure 2.78: Carrier Wave Generator
2.2.5.2 The Coherent Detector (in brief )
21
The coherent detector principle of operation is in Figure 39. The AM example model (AM_Coherent.mdl
is shown in Figure 40.
21 See
the le at <http://cnx.org/content/m22187/latest/AM_Coherent.mdl>
Available for free at Connexions <http://cnx.org/content/col10713/1.1>
)
190
CHAPTER 2.
SIGNAL PROCESSING AND COMMUNICATION
Figure 2.79: Coherent SQRT Demodulation Principle of Operation
Available for free at Connexions <http://cnx.org/content/col10713/1.1>
191
Figure 2.80: Amplitude Modulation Example with Coherent Detection
MATLAB
and
Simulink
are
registered
trademarks
of
The
www.mathworks.com/trademarks for a list of additional trademarks.
MathWorks,
Inc.
See
Other product or brand names
may be trademarks or registered trademarks of their respective holders.
2.3 Audio Conference Bridge22
2.3.1 Introduction
The Audio Conference Bridge enables a voice call with multiple (n
>2)
attendants, as described in Figure
1. The algorithm monitors the voice signals from all attendants, and creates the signals to be transmitted
to the attendants.
This application cannot be implemented using solely the DSK6713, as it has only 2 analog ports. Therefore two daughterboards, the TLV320AIC20/20KEVM and the DSP/CODEC development platform, are
used. In this example we will integrate an algorithm based on Simulink blocks, with a legacy driver.
This module demonstrates the use of the device driver building blocks together with legacy code integration to implement a custom device driver on the DSK6713. This feature allows the use of the Simulink
22 This
content is available online at <http://cnx.org/content/m22185/1.2/>.
Available for free at Connexions <http://cnx.org/content/col10713/1.1>
®
192
CHAPTER 2.
SIGNAL PROCESSING AND COMMUNICATION
environment with user-specic drivers.
A wide range of algorithms exist, in the current chapter a simple algorithm based on nding the maximum
level among 3 attendants is implemented
Figure 2.81: The Audio Conference Bridge
2.3.1.1 Related Files
2.3.1.1.1
•
•
•
23
Powerpoint Presentation - Multichannel.ppt
CCS Example Project - C67.rar
24
25
Simulink Model for Audio Conference Bridge and Legacy Driver Files - C67_Simulink_conference.rar
2.3.2 The Platform
The DSK6713 supports stereo analog inputs and outputs.
The Audio Conference Bridge application de26
mands more analog ports. In this example we will use TLV320AIC24EVM
(). This board contains two
TLV320AIC24 () stereo CODECs, thus supporting 4 audio channels. The system is shown in Figure 2.
—
The TLV320AIC24 implements the smart time division multiplexed serial port (SMARTDM ). The
SMARTDM port is a synchronous 4-wire serial port in TDM format for glue-free interface to TI DSPs. The
23 See
24 See
25 See
26 An
the le at <http://cnx.org/content/m22185/latest/Multichannel.ppt>
the le at <http://cnx.org/content/m22185/latest/C67.rar>
the le at <http://cnx.org/content/m22185/latest/C67_Simulink_conference.rar>
additional
board
the
DSP-CODEC
Platform
()
is
also
needed.
This
board
mainly
TLV320AIC24EVM connector and the peripherals connector in the DSK6713.
Available for free at Connexions <http://cnx.org/content/col10713/1.1>
interfaces
between
the
193
TLV320AIC24 can be gluelessly cascaded to any SMARTDM-based device to form a multichannel CODEC,
27
and up to eight TLV320AIC2x CODECs can be cascaded
.
The SMARTDM port is connected to the Multichannel Buered Serial Port (McBSP) in the DSP as
shown in Figure 3.
The TLV320AIC24 supports various types of analog interfaces, and can operate with sampling rates to
104 KSPS, with 16 bit samples. The block diagram is shown in Figure 4. The TLV320AIC24 features are
summarized in Figure 5.
Figure 2.82: The Platform
27 We
will use a single EVM board in this example.
Available for free at Connexions <http://cnx.org/content/col10713/1.1>
194
CHAPTER 2.
SIGNAL PROCESSING AND COMMUNICATION
Figure 2.83: TLV320AIC24 Interface
Available for free at Connexions <http://cnx.org/content/col10713/1.1>
195
Figure 2.84: TLV320AIC24 Block Diagram
Available for free at Connexions <http://cnx.org/content/col10713/1.1>
196
CHAPTER 2.
SIGNAL PROCESSING AND COMMUNICATION
Figure 2.85: TLV320AIC24 Features Summary
Available for free at Connexions <http://cnx.org/content/col10713/1.1>
197
2.3.3 The TLV320AIC24 Driver
2.3.3.1 Principle of Operation
The driver operates in a double-buering scheme as shown in Figure 6. There are two buers in each direction
(Receive/Transmit). For each frame to processes occur simultaneously:
1. The CPU processes samples from one of the receive buers, and stores the results in the correspondent
transmit buer.
2. The EDMA reads and writes samples that belong to the next frame.
(a) Frame #n
(b) Frame #n+1
Figure 2.86:
Double-Buering Mechanism
The driver uses two EDMA channels. The rst will read from a xed location in the memory, which is the
received data register (DRR) of the MCBSP port, to a buer in the memory that will hold those samples.
The second will write from a buer in the memory to a xed location that is the transmit register (DXR) of
the MCBSP port.
Samples are send/received to/from the CODEC in an interleaved mode.
The EDMA receive channel
sorts the samples and place the samples of each channel placed in consecutive addresses in the data memory.
A symmetric process occurs in the opposite direction. Figure 7 describes the process of receiving samples
Available for free at Connexions <http://cnx.org/content/col10713/1.1>
198
CHAPTER 2.
SIGNAL PROCESSING AND COMMUNICATION
and Figure 8 describes the process of transmitting samples. Once a buer is received/transmitted a Callback
(please refer to section ) function is called, activating the signal processing procedures.
Figure 2.87: Receiving Samples
Available for free at Connexions <http://cnx.org/content/col10713/1.1>
199
Figure 2.88: Transmitting Samples
2.3.3.2
The driver consists of 4 les:
1. aic24_defs.h This le contains the denitions of the various registers of the TLV320AIC24.
2. aic24.h Needed for the DSP conguration.
3. aic24.c Contains the various initialization routines.
4. AIC24-C6713.cdb - DSP-BIOS conguration le.
Those les should be integrated with a user le, explained in the next section.
2.3.3.3 The Driver Interface
The driver interface is implemented in the user dened le. This le consists of the main program and the
callback processing function.
Available for free at Connexions <http://cnx.org/content/col10713/1.1>
200
CHAPTER 2.
SIGNAL PROCESSING AND COMMUNICATION
2.3.3.3.1 The main program
The driver allocates a handle to the chain of CODECs, initializes it and afterwards activates the components.
This le:
1. Initializes the AIC24 handle.
This is a structure that contains handles to the EDMA and to the
MCBSP port. It also contains their conguration structures, pointers to user buers (the data is read
and written through them) and some more variables like the AIC24 register values, the current buer
etc. handle and the data is exchanged through a callback function. The function AIC24_Init Defaults
initializes the handle with the values provided by user and some default values.
2. Congures the TLV320AIC24 mode
3. n
addition,
the
user
needs
to
28
.
map
the
analog
input/output
ports
to
the
channels
in
the
SMARTDM/McBSP (Please refer to ).
4. Run the AIC24_Start, the main function that:
•
•
•
•
•
Congures the McBSP
Activates the McBSP
Congures the AIC24 (through the McBSP).
Congures the EDMA
Activates the EDMA
2.3.3.3.2 The Callback Function
The user is required to create a callback function were the processing is implemented. This function receives
pointers to two buers as arguments; one buer contains the latest information read from the CODECs,
while the second will contain the data to be written to the CODECs.
The callback function template is
shown:
The Callback Function Template
void process(Int16 *r_data, Int16 *w_data
{
/* Processing functions (user-defined) */
}
2.3.3.4 Using the Driver in the CCS Environment
In this section we will describe the way the driver is used in the CCS environment.
1. Create a new project in the CCS environment
2. Copy the following les to the project directory
•
•
•
•
•
•
29
:
aic24.c
aic24.h
aic24_defs.h
AIC24-C6713.cdb
Add aic24.c and AIC24-C6713.cdb les to your project.
Add the user le with the callback function.
An example of this process is provided in the next section.
28 The
CODEC can operate in DATAMODE or PROGRAMMING mode.
We'll use DATAMODE only.
explanation, please refer to the TLV320AIC24 datasheet.
29 This
is not mandatory. You may add the les from any directory.
Available for free at Connexions <http://cnx.org/content/col10713/1.1>
For a detailed
201
2.3.3.5 An example
The example creates two audio paths as follows:
⇒
⇒
Path # 2: J13 ⇒
McBSP1/Channel 0 ⇒
Path # 1:
J14
McBSP1/Channel 2
⇒ McBSP1/Channel
⇒ J4
CODEC#2/INP3 ⇒ SMARTDM/Channel 2 ⇒ McBSP1/Channel
SMARTDM/Channel 0 ⇒ CODEC#0/OUTP2 ⇒ J5
CODEC#0/INP1
⇒
SMARTDM/Channel 0
SMARTDM/Channel 2
⇒
0
⇒
DSP
⇒
2
⇒
DSP
⇒
CODEC#2/OUTP1
The example is illustrated in Figure 9. A user dened function test.c was created for this application.
Figure 2.89: CCS Example Conguration
2.3.3.5.1 The Program
The rst part of the program denes the buers for reading and writing samples.
Buer Allocation
#define NUM_CODECS 4 // The number of CODECs connected
#define DATANUM 128 // The number of samples in each channel
Available for free at Connexions <http://cnx.org/content/col10713/1.1>
202
CHAPTER 2.
SIGNAL PROCESSING AND COMMUNICATION
#define DATAMODE 0 // AIC24 operates in data mode
+
,
#if DATAMODE == 1
#define BUFS_PER_CHANNEL 1
#else
#define BUFS_PER_CHANNEL 2
#endif
Int16
Int16
Int16
Int16
r_data1[DATANUM*NUM_CODECS*BUFS_PER_CHANNEL];
w_data1[DATANUM*NUM_CODECS*BUFS_PER_CHANNEL];
r_data2[DATANUM*NUM_CODECS*BUFS_PER_CHANNEL];
w_data2[DATANUM*NUM_CODECS*BUFS_PER_CHANNEL];
// data buffer for read
// data buffer for read
// data buffer for write
// data buffer for write
The callback function follows the template introduced in the previous section, and calls the subroutine
copyData.
The Callback Function
+
void copyData Int16 *inbuf, Int16 *outbuf, Int16 length
{
Int16 i = 0;
for
}
}
,
+i = 0; i < length; i++rbbrk; {
outbuf[i] = inbuf[i];
// The callback function that is called when the EDMA buffers are full
// The function copies the data from channel 0 to channel 2
void process(Int16 *r_data, Int16 *w_data)
{
if (hAIC24.DataMode)
{
int i;
for (i=0; i<DATANUM; i++)
r_data[0*DATANUM+i] [U+2A53]= 0xfffe;
}
copyData(r_data+0*DATANUM, w_data+2*DATANUM, DATANUM);
}
The main program:
•
•
•
Sets the AIC24 handle
Maps the analog ports
30
Starts the AIC24
After this step, the program will enter in an endless loop. Samples will be processed each time an EDMA
interrupt occurs.
The main program
30 The
driver sets a default conguration. Those commands are needed if changes in the default conguration are required.
Available for free at Connexions <http://cnx.org/content/col10713/1.1>
203
int main()
{
// setting up the AIC24 handle
AIC24_InitDefaults([U+2A53]hAIC24, NUM_CODECS, DATANUM, r_data1, r_data2, w_data1, w_data2, process);
// determining data mode (continuous or programming)
hAIC24.DataMode = DATAMODE;
// example for setting devices input and outputs
// if defaults are ok then this is not necessary
hAIC24.Regs[0].creg6.reg6a.control_bit.mici = 0;
hAIC24.Regs[0].creg6.reg6a.control_bit.inp1 = 1;
hAIC24.Regs[0].creg6.reg6a.control_bit.inp2 = 0;
hAIC24.Regs[0].creg6.reg6a.control_bit.inp3 = 0;
hAIC24.Regs[0].creg6.reg6a.control_bit.inp4 = 0;
hAIC24.Regs[0].creg6.reg6b.control_bit.outp1 = 0;
hAIC24.Regs[0].creg6.reg6b.control_bit.outp2 = 1;
hAIC24.Regs[0].creg6.reg6b.control_bit.outp3 = 0;
hAIC24.Regs[1].creg6.reg6a.control_bit.mici = 0;
hAIC24.Regs[1].creg6.reg6a.control_bit.inp1 = 0;
hAIC24.Regs[1].creg6.reg6a.control_bit.inp2 = 0;
hAIC24.Regs[1].creg6.reg6a.control_bit.inp3 = 0;
hAIC24.Regs[1].creg6.reg6a.control_bit.inp4 = 0;
hAIC24.Regs[1].creg6.reg6b.control_bit.outp1 = 0;
hAIC24.Regs[1].creg6.reg6b.control_bit.outp2 = 0;
hAIC24.Regs[1].creg6.reg6b.control_bit.outp3 = 0;
hAIC24.Regs[2].creg6.reg6a.control_bit.mici = 0;
hAIC24.Regs[2].creg6.reg6a.control_bit.inp1 = 0;
hAIC24.Regs[2].creg6.reg6a.control_bit.inp2 = 0;
hAIC24.Regs[2].creg6.reg6a.control_bit.inp3 = 1;
hAIC24.Regs[2].creg6.reg6a.control_bit.inp4 = 0;
hAIC24.Regs[2].creg6.reg6b.control_bit.outp1 = 1;
hAIC24.Regs[2].creg6.reg6b.control_bit.outp2 = 0;
hAIC24.Regs[2].creg6.reg6b.control_bit.outp3 = 0;
hAIC24.Regs[3].creg6.reg6a.control_bit.mici = 0;
hAIC24.Regs[3].creg6.reg6a.control_bit.inp1 = 0;
hAIC24.Regs[3].creg6.reg6a.control_bit.inp2 = 0;
hAIC24.Regs[3].creg6.reg6a.control_bit.inp3 = 0;
hAIC24.Regs[3].creg6.reg6a.control_bit.inp4 = 0;
hAIC24.Regs[3].creg6.reg6b.control_bit.outp1 = 0;
hAIC24.Regs[3].creg6.reg6b.control_bit.outp2 = 0;
hAIC24.Regs[3].creg6.reg6b.control_bit.outp3 = 0;
// Starting the AIC24
AIC24_Start([U+2A53]hAIC24);
Available for free at Connexions <http://cnx.org/content/col10713/1.1>
204
CHAPTER 2.
SIGNAL PROCESSING AND COMMUNICATION
2.3.3.5.2 Running the Example
Connect an audio source to J14, a speaker / headphone to J4 and check Path #1.
Connect an audio source to J13, a speaker / headphone to J5 and check Path #2.
2.3.4 Migration to Simulink
2.3.4.1 Principle of Operation
The main idea is to create a Simulink environment that reads samples form 4 channels, process them and
send them to 4 output channels. The example model is shown in Figure 14.
Figure 2.90: Simulink Environment for Multichannel Processing
Available for free at Connexions <http://cnx.org/content/col10713/1.1>
205
The Simulink driver block is based on the driver described in the previous chapters. Both drivers read and
write samples using a double-buering mechanism, but they dier in the way they activate the processing
algorithm.
The algorithm code, in the Simulink environment, runs as a separate free-running task. At the start of
the function it checks the semaphore to see if data is ready to read from the buer if not then it stays
in a wait state until the semaphore is posted by the callback routine (Please refer to section ). Once this
has been posted, it reads the data elements from the addresses supplied by the appropriate pointers. Once
the algorithm has then processed the data, it writes the data elements from the addresses supplied by the
appropriate pointers. After process is concluded, it will wait for the next frame of samples. This process
then repeats until halted.
The callback function, in the Simulink environment, needs to set the appropriate pointers each time an
EDMA interrupt occur, and post a semaphore for the Algorithm task afterwards.
2.3.4.2 Driver Structure
The driver consists of 4 les:
1. aic24_defs.h This le contains the denitions of the various registers of the TLV320AIC24.
2. aic24.h Needed for the DSP conguration.
3. aic24.c Contains the various initialization routines.
4. aic24link.c
The rst three les are the same les used for the CCS driver.
The ai24link.c le is similar to the user
dened le (test.c for example) described in ,
This le contains the following functions and denitions:
Buers Denitions:
Int16
Int16
Int16
Int16
r_data1[DATANUM*NUM_CODECS*BUFS_PER_CHANNEL];
w_data1[DATANUM*NUM_CODECS*BUFS_PER_CHANNEL];
r_data2[DATANUM*NUM_CODECS*BUFS_PER_CHANNEL];
w_data2[DATANUM*NUM_CODECS*BUFS_PER_CHANNEL];
//
//
//
//
data
data
data
data
buffer
buffer
buffer
buffer
for
for
for
for
Pointers to each channel buers (read and write).
Those pointers are used by the Algorithm block in the Simulink model.
Int16
Int16
Int16
Int16
Int16
Int16
Int16
Int16
*InSig1;
*InSig2;
*InSig3;
*InSig4;
*OutSig1;
*OutSig2;
*OutSig3;
*OutSig4;
An AIC24 handle and a Semaphore handle
As explained the semaphore will be used to wait for the data to arrive.
AIC24_Handle hAIC24;
SEM_Obj AIC24_ready_sem;
Available for free at Connexions <http://cnx.org/content/col10713/1.1>
read
read
write
write
206
CHAPTER 2.
SIGNAL PROCESSING AND COMMUNICATION
The AIC24LINK_init function.
It calls the AIC24_Init function and also initializes the semaphore.
void AIC24LINK_init()
{
// setting up the AIC24 handle
AIC24_InitDefaults([U+2A53]hAIC24, NUM_CODECS, DATANUM, r_data1, r_data2, w_data1, w_data2, AIC24LINK_pr
SEM_new([U+2A53]AIC24_ready_sem,0);
}
The callback function.
The callback function AIC24LINK_process simply sets the channel buer pointers (the pointers the model
uses) to the correct places and posts on the semaphore.
void AIC24LINK_process(Int16 *r_data, Int16 *w_data)
{
InSig1 = r_data;
InSig2 = r_data + DATANUM;
InSig3 = r_data + DATANUM*2;
InSig4 = r_data + DATANUM*3;
OutSig1 = w_data;
OutSig2 = w_data + DATANUM;
OutSig3 = w_data + DATANUM*2;
OutSig4 = w_data + DATANUM*3;
SEM_post([U+2A53]AIC24_ready_sem);
}
void AIC24LINK_wait()
{
SEM_pend([U+2A53]AIC24_ready_sem, SYS_FOREVER);
}
AIC24LINK_wait
This function pends on the semaphore.
AIC24LINK_start
This function calls AIC24_start.
2.3.4.3
The Simulink block will be created from the AIC23 driver used in the Custom Device Driver/Legacy Code
Integration Simulink demo.
•
Open the demo
Available for free at Connexions <http://cnx.org/content/col10713/1.1>
207
Figure 2.91: The Simulink demo for Device Driver/Legacy Code Integration
•
Open the model
Available for free at Connexions <http://cnx.org/content/col10713/1.1>
208
CHAPTER 2.
SIGNAL PROCESSING AND COMMUNICATION
Figure 2.92: Real-time model using a custom device driver
•
•
•
•
Double-click the "AIC23 Codec Driver" box.
Rename it (TLV320AIC24EVM).
31
Delete the EDMA related boxes
.
Double-click the "System Start" box.
Delete the code and replace it by the initialization function
AIC24LINK_init () in the execution box.
•
Double-click the "System Enable". Delete the code and add the AIC24LINK_Start(), to the execution
box.
•
•
Delete the code in the "Model Header" box.
Double-click the "Model Source" box. Delete the code. Add to the "Top of Model Source" box the
line #include "aic24link.h".
This will allow calling the functions in the aic24link.c le.
summarizes the driver blocks conguration
31 The
EDMA and interrupts congurations are handled as in the original CCS driver.
Available for free at Connexions <http://cnx.org/content/col10713/1.1>
Figure 17
209
Figure 2.93: TLV320AIC24EVM driver blocks
The next steps will guide you through the Algorithm block conguration
•
Add 6 terminators (inputs and outputs) both inside and outside the "Algorithm" box and of course
32
wiring them appropriately. Double click on each terminator and set its dimension to 64
32 The
terminator dimension should match the value of the DATANUM constant in the aic24link.c le
Available for free at Connexions <http://cnx.org/content/col10713/1.1>
(except for
210
CHAPTER 2.
SIGNAL PROCESSING AND COMMUNICATION
the internal terminators). Set the data type to int16.The 8 input and output ports should be linked
to the buers (i.e. the pointers) in the aic24link.c le.
•
Right-click the wires connecting the terminators to the algorithm and select "Signal Properties". A
new window will be opened window, Select "RealTime Workshop" tab and "ImportedExternPointer".
Enter the signal name. It should have the same name of the correspondent pointers in the driver (As
dened in the aic24link.c le).
•
Double-click the "Algorithm" box again and then open the "System Outputs" block. Delete the code
and add a call to AIC24LINK_wait. This way the loop of the task stops each time and waits for the
data.
Figure 2.94: The Algorithm block
The model is now ready to generate real-time code for processing of 4 audio channels. AN example is shown
in the next chapter.
Available for free at Connexions <http://cnx.org/content/col10713/1.1>
211
2.3.5 The Audio Conference Bridge Application
This chapter illustrates the use of the Simulink driver introduced in the previous chapter, to implement a
conference bridge.
33
Figure 15 shows the conguration used for this application. Three headsets
are used, enabling a 3-port
conference. The DSP monitors the 3 input signals, and routes the loudest input signal to the three outputs.
The algorithm is described in the next section.
Figure 2.95: System Conguration
33 The
TLV320AIC24 contains three analog interfaces for headsets. The use of an additional channel requires minor hardware
changes in the board.
Available for free at Connexions <http://cnx.org/content/col10713/1.1>
212
CHAPTER 2.
SIGNAL PROCESSING AND COMMUNICATION
2.3.5.1 The Algorithm
Figure 2.96: The Algorithm (Block Diagram)
The algorithm processes 64 samples (each channel). It calculates the absolute power of each channel (sum
of absolute values). Three counters are used, each one corresponding to a distinct channel.
For each frame the counter correspondent to the loudest channel is incremented. When a channel counter
equals a threshold
34
, the correspondent channel is selected.
For Each 64 samples frame the following algorithm is implemented:
Output Channel Selection Procedure
1. Find Maximum Input Level
2. Increment Counter correspondent to the loudest channel
3. If the Counter value =10 THEN:
4. Broadcast correspondent input channel to all outputs
5. Reset Counter
2.3.5.2 The Simulink Algorithm Implementation
This section will describe the process of generating a real-time application using Simulink blocks for the
algorithm itself and the driver introduced in the previous chapter. The Simulink model is shown in Figure
35
21
.
34 The
requirement for a threshold amount of wining rounds was set in order to prevent random noise or occasional spikes
from interfering with the algorithms function. This threshold is congurable. In this example it was set to 10.
35 The
algorithm is implemented for 4 channels, however we will use only three of them.
Available for free at Connexions <http://cnx.org/content/col10713/1.1>
213
Figure 2.97: Simulink Model
The block diagram shown in Figure 20 is translated to the model shown in the following gures.
•
The conference algorithm routes a selected channel to the 4 outputs:
Available for free at Connexions <http://cnx.org/content/col10713/1.1>
214
CHAPTER 2.
SIGNAL PROCESSING AND COMMUNICATION
Figure 2.98: Signal Routing
•
The input level is measured for 4 channels:
Available for free at Connexions <http://cnx.org/content/col10713/1.1>
215
Figure 2.99: Algorithm Model
•
The 4 level values compose a 4 element vector. This vector is fed to the Max abs value block:
Figure 2.100: Finding the Maximum Level
Available for free at Connexions <http://cnx.org/content/col10713/1.1>
216
CHAPTER 2.
•
SIGNAL PROCESSING AND COMMUNICATION
The index of the Maximum level enters the index selection block.
The correspondent channel is
incremented and compared to the threshold.
Figure 2.101: Index Selection
•
If the counter value equals the threshold, the index is selected as input to the conference block
The real-time model can be found in the le C67_Simulink_conference.rar.
36
2.3.6 References
1. "TLV320AIC20K/24KEVM
User's
Guide
",
(http://focus.ti.com/lit/ug/slau088a/slau088a.pdf
37
TI
Document
SLAU088A,
April
2005
)
2. "DSP−CODEC Development Platform User's Guide", TI Document SLAU090, September 2002
(http://focus.ti.com/lit/ug/slau090/slau090.pdf
3. "Low
CODEC
Power
(Rev.
Highly-Integrated
D)"
TI
38
Document
SLAS363D,
(http://focus.ti.com/lit/ds/slas363d/slas363d.pdf
MATLAB
and
Simulink
are
)
Programmable
registered
39
16-Bit
26-KSPS
March
2002
Dual
Revised
Channel
April
2005
)
trademarks
of
The
www.mathworks.com/trademarks for a list of additional trademarks.
MathWorks,
Inc.
See
Other product or brand names
may be trademarks or registered trademarks of their respective holders.
36 See the le at <http://cnx.org/content/m22185/latest/C67_Simulink_conference.rar>
37 http://focus.ti.com/lit/ug/slau088a/slau088a.pdf
38 http://focus.ti.com/lit/ug/slau090/slau090.pdf
39 http://focus.ti.com/lit/ds/slas363d/slas363d.pdf
Available for free at Connexions <http://cnx.org/content/col10713/1.1>
217
2.3.7 Appendix A Conguration
2.3.7.1 TLV320AIC24K & CODEC Development Platform
2.3.7.1.1 Analog Ports
The following table is based on the one the Codec's EVM Datasheet.
It matches the board connectors with the inputs and outputs.
(Notice, this table includes corrections and elaborations in compare to the one in the Datasheet).
Figure 2.102
•
We are using the TLV320AIC24KEVM is 24K.
The Inputs and Outputs of a certain channel are set by its 6a and 6b registers.
Those registers can be set, like before, between the initialization of the Handle and its activation.
40
If, for example, the input samples of channel 0 in the CODEC should be received from INP3
.
The
conguration should be as follows:
int main()
{
// setting up the AIC24 handle
AIC24_InitDefaults([U+2A53]hAIC24,
4, 64, r_data1, r_data2, w_data1, w_data2, process);
hAIC24.Regs[0].creg6.reg6a.control_bit.mici = 0;
hAIC24.Regs[0].creg6.reg6a.control_bit.inp1 = 0;
hAIC24.Regs[0].creg6.reg6a.control_bit.inp2 = 0;
40 According
to the table the connection is to J10, since we are working with 24K EVM and channel 0 is located at the master
side.)
Available for free at Connexions <http://cnx.org/content/col10713/1.1>
218
CHAPTER 2.
SIGNAL PROCESSING AND COMMUNICATION
hAIC24.Regs[0].creg6.reg6a.control_bit.inp3 = 1;
hAIC24.Regs[0].creg6.reg6a.control_bit.inp4 = 0;
}
// Starting the AIC24
AIC24_Start([U+2A53]hAIC24);
Each entry corresponds to a bit that determines whether it should be connected or not to the channel
41
input
. The names of the elds correlate to the table.
A similar procedure applies for the output channel:
hAIC24.Regs[0].creg6.reg6b.control_bit.outp1 = 0;
hAIC24.Regs[0].creg6.reg6b.control_bit.outp2 = 1;
hAIC24.Regs[0].creg6.reg6b.control_bit.outp3 = 0;
In the case above, output of channel 0 is connected to OUTP2 (i.e. J1).
A single channel can be connected to a number of outputs. It is not recommended to connect two CODEC
channels to a single output.
The default channel conguration is:
Even Channels (i.e. 0,2,. . .) Input: MICI
Even Channels (i.e. 0,2,. . .) Output: OUTP1
Odd Channels (i.e. 1,3,. . .) Input: INP1
Odd Channels (i.e. 1,3,. . .) Output: OUTP2
2.3.7.1.2 Switches and Jumpers
Jumper settings for the AIC24 EVM
Jumper
State
W1:
Closed
W2:
2-3
W3:
1-2
W4:
1-2
W5:
Closed
P1.13-P1.14:
Closed
P1.9-P1.10:
Closed
P1.11-P1.12:
Closed
Table 2.2
Jumper settings for the AIC Motherboard
Jumper
State
W1:
1-2
W2:
2-3
Table 2.3
41 Other
entries were reset ('0'), as they should not be connected to the channel's input.
Available for free at Connexions <http://cnx.org/content/col10713/1.1>
219
2.3.7.2 DSP
2.3.7.2.1 EDMA Conguration
EDMA Receive Channel Conguration (Register Values)
RegisterValue
Remarks
opt
EDMA_OPT_PRI_LOW
Low Priority (Allows other DMAs rst)
EDMA_OPT_ESIZE_16BIT
16 bits elements
EDMA_OPT_2DS_NO
Source not using 2D option
EDMA_OPT_SUM_NONE
Source Address is xed (The MCBSP rcv register)
EDMA_OPT_2DD_NO
Destination not using 2D option
EDMA_OPT_DUM_IDX
Destination address is in double index (sort)
mode
EDMA_OPT_TCINT_YES
Cause interrupt
EDMA_OPT_TCC_OF(0)
Transfer Complete Code (given to the interrupt, set later)
EDMA_OPT_LINK_YES
Use linking to another EDMA record
EDMA_OPT_FS_NO
Don't use frame sync
src
MCBSP_getRcvAddr(hAIC->hMcbsp)
The address of the McBSP recv register
cnt
EDMA_CNT_FRMCNT_OF(ChannelBuerSize
The number of frames is the size of the buer
1)
EDMA_CNT_ELECNT_OF(TotalNumChannels)
Each frame has NumChannel elements
dst
EDMA_DST_OF(ReadAddr)
The address of the buer to write to
idx
EDMA_IDX_FRMIDX_OF(-
Negative Frame Index to move us back to the
((ChannelBuerSize * (TotalNumChannels-1))
next position in the rst channel after each
* 2)+2
frame
EDMA_IDX_ELEIDX_OF((ChannelBuerSize Positive Element Index to move us to the next
* 2)
rld
position in channel after every elemnt
EDMA_RLD_ELERLD_OF(TotalNumChannels)
Should be the same as Element Count
EDMA_RLD_LINK_OF(LinkedRecord)
The number of the next record to load (since we
use double buering the next record will point
back to this one)
Table 2.4
EDMA Transmit Channel Conguration (Register Values)
Available for free at Connexions <http://cnx.org/content/col10713/1.1>
220
CHAPTER 2.
SIGNAL PROCESSING AND COMMUNICATION
RegisterValue
Remarks
opt
EDMA_OPT_PRI_LOW
Low Priority (Allows other DMAs rst)
EDMA_OPT_ESIZE_16BIT
16 bits elements
EDMA_OPT_2DS_NO
Source not using 2D option
EDMA_OPT_SUM_IDX
Source address is in double index (sort)
EDMA_OPT_2DD_NO
Destination not using 2D option
EDMA_OPT_DUM_NONE
Destination Address is xed (The MCBSP xmt
register)
EDMA_OPT_TCINT_YES
Cause interrupt
EDMA_OPT_TCC_OF(0)
Transfer Complete Code (given to the interrupt, set later)
EDMA_OPT_LINK_YES
Use linking to another EDMA record
EDMA_OPT_FS_NO
Don't use frame sync
src
EDMA_SRC_OF(WriteAddr)
The address of the buer read from
cnt
EDMA_CNT_FRMCNT_OF(ChannelBuerSize
Each frame has NumChannel elements
1)
EDMA_CNT_ELECNT_OF(TotalNumChannels)
Each frame has NumChannel elements
dst
MCBSP_getXmtAddr(hAIC->hMcbsp)
The address of the McBSP transmit register
idx
EDMA_IDX_FRMIDX_OF(-
Negative Frame Index to move us back to the
((ChannelBuerSize * (TotalNumChannels-1))
next position in the rst channel after each
* 2)+2)
frame
EDMA_IDX_ELEIDX_OF((ChannelBuerSize Positive Element Index to move us to the next
* 2))
rld
position in channel after every elemnt
EDMA_RLD_ELERLD_OF(TotalNumChannels)
Should be the same as Element Count
EDMA_RLD_LINK_OF(LinkedRecord)
The number of the next record to load (since we
use double buering the next record will point
back to this one)
Table 2.5
2.3.7.2.2 MCBSP Conguration
McBSP Conguration (Register Values)
Available for free at Connexions <http://cnx.org/content/col10713/1.1>
221
RegisterValue
Remarks
Serial MCBSP_SPCR_FREE_YES
Port
Control
Register
(SPCR)
Used for emulation
MCBSP_SPCR_SOFT_YES
Used for emulation
MCBSP_SPCR_FRST_YES
Frame sync generator is in reset (generated by
master CODEC)
MCBSP_SPCR_GRST_YES
Sample rate generator is in reset (generated by
master CODEC)
MCBSP_SPCR_XINTM_FRM
The transmit interrupt is driven by new frame
sync
MCBSP_SPCR_XSYNCERR_NO
No synchronization error detected
MCBSP_SPCR_XRST_YES
The serial port transmitter is disabled and in
reset state
MCBSP_SPCR_DLB_OFF
Digital Loopback mode o
MCBSP_SPCR_RJUST_RZF
Receive data right-justied and zero-ll MSBSs
in DRR
MCBSP_SPCR_CLKSTP_DISABLE
The Clock stop mode is disabled
MCBSP_SPCR_DXENA_OFF
Disable extra delay of DX
MCBSP_SPCR_RINTM_FRM
Receive interrupt on new frame synch
MCBSP_SPCR_RSYNCERR_NO
No synchronization error detected
MCBSP_SPCR_RRST_YES
The serial port receiver is disabled and in reset
state
ReceiveMCBSP_RCR_RPHASE_SINGLE
Control
Register
(RCR)
receive one phase only
continued on next page
Available for free at Connexions <http://cnx.org/content/col10713/1.1>
222
CHAPTER 2.
SIGNAL PROCESSING AND COMMUNICATION
MCBSP_RCR_RFRLEN2_OF(0)
Don't Care. Phase 2 is not used
MCBSP_RCR_RWDLEN2_16BIT
Don't Care. Phase 2 is not used
MCBSP_RCR_RCOMPAND_MSB
No companding, data transfer starts with MSB
rst
MCBSP_RCR_RFIG_NO
sync error doesn't cause transfer restart
MCBSP_RCR_RDATDLY_1BIT
1 bit data delay
MCBSP_RCR_RFRLEN1_OF(NumChannels- Each frame contains an element for each chan1)
nel
MCBSP_RCR_RWDLEN1_16BIT
Each sample is 16 bit
MCBSP_RCR_RWDREVRS_DISABLE
Don't Care. Only 16 bit elements are used
Transmit
MCBSP_XCR_XPHASE_SINGLE
Control
Register
(XCR)
Transmit one phase only
MCBSP_XCR_XFRLEN2_OF(0)
Don't Care. Phase 2 is not used
MCBSP_XCR_XWDLEN2_16BIT
Don't Care. Phase 2 is not used
MCBSP_XCR_XCOMPAND_MSB
No companding, data transfer starts with MSB
rst
MCBSP_XCR_XFIG_NO
sync error doesn't cause transfer restart
MCBSP_XCR_XDATDLY_1BIT
1 bit data delay
MCBSP_XCR_XFRLEN1_OF(NumChannels- Each frame contains an element for each chan1)
nel
MCBSP_XCR_XWDLEN1_16BIT
Each sample is 16bit
MCBSP_XCR_XWDREVRS_DISABLE
Does not matter, we use 16 bit elements
Sample 0
Rate
Generator
Register
(SRGR)
Not used, clock and frame sync are generated
by the master CODEC (The source code contains the ags but they are 0)
continued on next page
Available for free at Connexions <http://cnx.org/content/col10713/1.1>
223
Pin
MCBSP_PCR_XIOEN_SP
Control
Register
(PCR)
All pins are dedicated for MCBSP (Not GPIO)
MCBSP_PCR_RIOEN_SP
All pins are dedicated for MCBSP (Not GPIO)
MCBSP_PCR_FSXM_EXTERNAL
Transmit frame sync is generated by the master
CODEC
MCBSP_PCR_FSRM_EXTERNAL
Receive frame sync is generated by the master
CODEC
MCBSP_PCR_CLKXM_INPUT
Transmit clock sync is generated by the master
CODEC
MCBSP_PCR_CLKRM_INPUT
Receive clock sync is generated by the master
CODEC
MCBSP_PCR_CLKSSTAT_0
Does not matter (used in GPIO)
MCBSP_PCR_DXSTAT_0
Does not matter (used in GPIO)
MCBSP_PCR_FSXP_ACTIVEHIGH
Transmit frame sync is active high for AIC24
MCBSP_PCR_FSRP_ACTIVEHIGH
Receive frame sync is active high for AIC24
MCBSP_PCR_CLKXP_RISING
Transmit data driven on rising edge
MCBSP_PCR_CLKRP_FALLING
Receive data sampled on falling edge
MCR
0
Unused
RCER
0
Unused
XCER
0
Unused
Table 2.6
2.4 DTMF Detection42
2.4.1 Introduction
The Dual-tone multi-frequency (DTMF) signaling method was developed originally to replace pulse
44
Pulse or DP in the U.S.
43
(Dial
) and loop disconnect (LD) signaling methods to dial numbers, in order to shorten
the holding time of the switch during dialing , specially for long distance calls.
DTMF signaling uses two tones to represent each key on the touch pad. There are 12 distinct tones
(Please refer to Table 1).
45
When any key is pressed the tone of the column and the tone of the row are
generated. As an example, pressing the '5' button generates the tones 770 Hz and 1336 Hz. The frequencies
were chosen to avoid harmonics:
no frequency is a multiple of another, the dierence between any two
frequencies does not equal any of the frequencies, and the sum of any two frequencies does not equal any of
the frequencies.
42 This content is available online at <http://cnx.org/content/m22937/1.2/>.
43 http://en.wikipedia.org/wiki/Pulse_dialing
44 http://en.wikipedia.org/wiki/United_States
45 The DTMF method denes four additional digits: A, B,C & D. Most
of the systems today do not use those digits.
Available for free at Connexions <http://cnx.org/content/col10713/1.1>
224
CHAPTER 2.
SIGNAL PROCESSING AND COMMUNICATION
.
1209 Hz
1336 Hz
1477 Hz
697 Hz
1
2
3
770 Hz
4
5
6
852 Hz
7
8
9
941 Hz
*
0
#
Table 2.7: DTMF Frequencies
Table 1- DTMF frequencies
The low frequencies are referred as rows, The higher frequencies are referred as columns.
This example will show the implementation of a DTMF receiver using the DSK6713. The DTMF receiver
will be based on the simulation model used in the Simulink demo. A graphic user interface (GUI) will also
be created to activate the DSK6713. DTMF digits will be sent from the PC sound card.
2.4.1.1 Related Files
•
•
•
•
•
46
Powerpoint Presentation - DTMF.ppt
Simulink Model for Simulation - DTMF.mdl
MATLAB GUI for Real-Time - DTMF.g
GUI m-le - DTMF.m
47
48
49
50
Simulink Model for Real-Time - DTMF_DSK6713.mdl
2.4.2 Simulation
2.4.2.1 The Simulation Model
Figure 1 shows the model used to simulate DTMF detection and generation.
46 See
47 See
48 See
49 See
50 See
the le at <http://cnx.org/content/m22937/latest/DTMF.ppt>
the le at <http://cnx.org/content/m22937/latest/DTMF.mdl>
the le at <http://cnx.org/content/m22937/latest/DTMF.g>
the le at <http://cnx.org/content/m22937/latest/DTMF.m>
the le at <http://cnx.org/content/m22937/latest/DTMF_DSK6713.mdl>
Available for free at Connexions <http://cnx.org/content/col10713/1.1>
225
Figure 2.103: DTMF Simulation
The DTMF generator is composed by 7 sine wave generators, corresponding to the 7 DTMF frequencies.
The oscillators are grouped as described in Table 1. The oscillators outputs are multiplexed and summed
(Please refer to Figure 2).
Upon selection of a digit to be transmitted, the correspondent oscillators are
activated.
Available for free at Connexions <http://cnx.org/content/col10713/1.1>
226
CHAPTER 2.
SIGNAL PROCESSING AND COMMUNICATION
Figure 2.104: DTMF Generation
The DTMF detection comprises two processes, the frequency detection algorithm itself, and a leading
edge detection subsystem.
The frequency detection subsystem measures the energy present at the seven frequencies, and calculates
the digit by taking the component of maximum energy in the lower and upper frequency groups. The process
is shown in Figure 3.
This process runs continuously; however the calculated digit is reported only if its
energy is above a threshold as determined by the leading edge detection subsystem. The DTMF detection
process is shown in Figure 4.
Available for free at Connexions <http://cnx.org/content/col10713/1.1>
227
Figure 2.105: Frequency Detection
Available for free at Connexions <http://cnx.org/content/col10713/1.1>
228
CHAPTER 2.
SIGNAL PROCESSING AND COMMUNICATION
Figure 2.106: DTMF Detection
2.4.2.2 Running the Simulation
•
•
Open the simulation model DTMF.mdl
In order to select the digit double click the DTMF generator subsystem and enter the digits to be sent
as follows:
Available for free at Connexions <http://cnx.org/content/col10713/1.1>
229
Figure 2.107: "Dialing" DTMF Digits
•
Activate the simulation, the detected digits will be displayed as shown:
Available for free at Connexions <http://cnx.org/content/col10713/1.1>
230
CHAPTER 2.
SIGNAL PROCESSING AND COMMUNICATION
Figure 2.108: Displaying the Detected DTMF Digits
2.4.3 Real Time Implementation
The real-time implementation environment is shown in Figure 7. The DTMF generation will be performed in
® and sent to the DSK through the PC sound card.
MATLAB
The detected digits will be reported through
RTDX. A graphic user interface (GUI) will be built to activate the transmitter, and display the reported
digits.
Available for free at Connexions <http://cnx.org/content/col10713/1.1>
231
Figure 2.109: Real Time Implementation
The DTMF receiver will be based on the DTMF receiver from the simulation model, with the following
changes:
•
•
•
Samples will be read from the Analog to Digital Converter, and ltered by a DC removal block
51
Digits will be reported through RTDX.
Addition of the DSK6713 target preference
2.4.3.1 The DTMF Receiver
•
•
Open the simulation model DTMF.mdl, remove all the blocks besides the DTMF receiver block.
Open the Simulink
51 This
® library browser and add the "C6713DSK".
block is necessary to convert the unipolar format of the samples to a 2's complement format for processing by the
DSP.
Available for free at Connexions <http://cnx.org/content/col10713/1.1>
232
CHAPTER 2.
SIGNAL PROCESSING AND COMMUNICATION
Figure 2.110: The C6713DSK target Block
•
Add the Analog to Digital converter (ADC) to your model:
Available for free at Connexions <http://cnx.org/content/col10713/1.1>
233
Figure 2.111: The ADC target Block
Available for free at Connexions <http://cnx.org/content/col10713/1.1>
234
CHAPTER 2.
SIGNAL PROCESSING AND COMMUNICATION
Figure 2.112: The ADC Block Conguration
•
The TO RTDX will be used to report the detected digits to the PC. Add it to your model:
Available for free at Connexions <http://cnx.org/content/col10713/1.1>
235
Figure 2.113: The "To RTDX" Block
Available for free at Connexions <http://cnx.org/content/col10713/1.1>
236
CHAPTER 2.
SIGNAL PROCESSING AND COMMUNICATION
Figure 2.114: The "To RTDX" Block Conguration
•
Add the Digital Filter and Gain blocks for DC removal:
Figure 2.115: The Digital Filter Block
Available for free at Connexions <http://cnx.org/content/col10713/1.1>
237
Figure 2.116: The Digital Filter Block Conguration
Available for free at Connexions <http://cnx.org/content/col10713/1.1>
238
CHAPTER 2.
SIGNAL PROCESSING AND COMMUNICATION
Figure 2.117: The Gain Block
Figure 2.118: The Gain Block Conguration
•
The DTMF receiver model is shown Figure 17:
Available for free at Connexions <http://cnx.org/content/col10713/1.1>
239
Figure 2.119: DTMF Receiver
•
•
Save the model as "DTMF_DSK6713.mdl".
Built the model.
2.4.3.2 The User Interface
2.4.3.3 Functionality
The GUI will perform the following functions:
•
Initialization: Initialize the RTDX interface and loading the DTMF Receiver program we have built
in the last section to the DSK.
•
52
Generate the DTMF signal samples: The GUI will enable the user to select a sequence of 11 digits
to be transmitted. It will create the samples of the DTMF signal based on this selection, and send
them to the sound card.
•
Display the detected digits reported by the DSK
2.4.3.4 Description
The desired GUI is shown in Figure 18
52 If
the user selects less than 11 digits, the sequence is padded with DTMF digit '1'.
Available for free at Connexions <http://cnx.org/content/col10713/1.1>
240
CHAPTER 2.
SIGNAL PROCESSING AND COMMUNICATION
Figure 2.120: DTMF GUI
It will enable the user to:
•
Dial the digits: every digit dialed is added to a specic buer, and displayed under the Dialed Digits
label.
•
•
•
Delete the last digit
Clear all the digits
53
Send: Create the DTMF signal from the digits selected
. A dual-tone signal will be created for each
digit. Silence will be inserted between consecutive digits. This signal is sent to the sound blaster using
the sound command in MATLAB.
•
Display: Digits reported by the DSK will be displayed under the Detected Digits label.
2.4.3.5 The Procedure
•
Activate the GUIDE (Graphic User Interface Integrated Development Environment in MATLAB.
53 The
DSK operates with a buer of 11 digits so if the user dialed less then 11 digits we are padding them to 11 in the
MATLAB.
Available for free at Connexions <http://cnx.org/content/col10713/1.1>
241
•
Open a new GUI and name it DTMF
•
Add 12 Push buttons for the keypad and set their String property to the proper values (0-9,*,#) using
the property inspector.
•
•
•
Add the Send, Clear and Delete buttons
Add 2 Edit Texts objects for display
You may now add the labels (static texts):
·
·
·
•
•
Dialed Digits
Detected Estimation
DTMF Transmitter
Press the play button to open the MATLAB script. Name the script DTMF.m.
Enter the Initialization (DTMF_OpeningFcn ) as shown:
function DTMF_OpeningFcn(hObject, eventdata, handles, varargin)
modelName = gcs;
CCS_Obj = connectToCCS(modelName);
% Identify RTDX channel names/modes
chan_struct(1).name = 'OutputDigit';
chan_struct(1).mode = 'r';
handles.RTDX_chan1=chan_struct(1);
% Identify RTDX host buffer parameters
RTDX_config_struct.Buffsize= 32768;
RTDX_config_struct.Nbuffers = 4;
RTDX_config_struct.Mode = 'continuous';
CodegenDir = fullfile(pwd, ['DTMF_RT' '_c6000_rtw']);
OutFile = fullfile(CodegenDir, ['DTMF_RT' '.out']);
%Load is needed for RTDX setup
CCS_Obj.load(OutFile,20);
% Set up RTDX
r = setupRTDX(CCS_Obj, chan_struct, RTDX_config_struct);
handles.pipe=r;
handles.CCS_Obj=CCS_Obj;
handles.output = hObject;
CCS_Obj.run;
% Enable all RTDX channels
r.enable('all');
%The buffer that stores the user input digits
A=[];
handles.A=A;
% flag that tells if the gui needs to clear the dialed string or
%the next digit joins the previous string:
handles.initFlag=0;
handles.maxSize=11;
handles.freqTable=generateTable();
% Update handles structure
guidata(hObject, handles);
This function will run after activating the GUI. It will then load the DSK, initialize the RTDX interface,
and initialize a table of samples for each digit, by calling the generateTable auxiliary function:
Available for free at Connexions <http://cnx.org/content/col10713/1.1>
242
CHAPTER 2.
SIGNAL PROCESSING AND COMMUNICATION
function res=generateTable()
t=(1:256*6)/8192;
res(1,:)=sin(2*pi*697*t)+sin(2*pi*1209*t);
res(2,:)=sin(2*pi*697*t)+sin(2*pi*1336*t);
res(3,:)=sin(2*pi*697*t)+sin(2*pi*1477*t);
res(4,:)=sin(2*pi*770*t)+sin(2*pi*1209*t);
res(5,:)=sin(2*pi*770*t)+sin(2*pi*1336*t);
res(6,:)=sin(2*pi*770*t)+sin(2*pi*1477*t);
res(7,:)=sin(2*pi*852*t)+sin(2*pi*1209*t);
res(8,:)=sin(2*pi*852*t)+sin(2*pi*1336*t);
res(9,:)=sin(2*pi*852*t)+sin(2*pi*1477*t);
res(10,:)=sin(2*pi*941*t)+sin(2*pi*1209*t);
res(11,:)=sin(2*pi*941*t)+sin(2*pi*1336*t);
res(12,:)=sin(2*pi*941*t)+sin(2*pi*1477*t);
•
Enter the handle Button function:
function handleButton(hObject,handles,k)
%get the digits buffer
A=handles.A;
%if we have to erase so we are doing it here:
if handles.initFlag==1
handles.initFlag=0;
A=[];
end
%check if the string is too long with the new digit:
if length(A)==handles.maxSize
fprintf('Error: too many digits\n');
return;
end
%concatenate the new digit to the existing buffer
A=[A k];
handles.A=A;
set(handles.text1, 'String', strrep(strrep(strrep(int2str(A),'10','*'),'11','0'),'12','#'));
guidata(hObject,handles);
% invoked when the user dials '1':
function pushbutton1_Callback(hObject, eventdata, handles)
handleButton(hObject,handles,1);
% invoked when the user dials '2':
function pushbutton2_Callback(hObject, eventdata, handles)
handleButton(hObject,handles,2);
. . .
This function will be activated, every time the user pushes a digit button in the keypad. The digit will be
displayed under the Dialed Digits label.
•
The following function will be activated by the Send button:
Available for free at Connexions <http://cnx.org/content/col10713/1.1>
243
%input: digits and handle to the signals table
%output: buffer that contains the DTMF samples for the digits.
function res=buildXmt(handles,A)
res=[];
for k=1 : length(A)
freqTable=handles.freqTable;
%place the next digit and then zeros (space)
res=[res freqTable(A(k),:) zeros(1,256*6);];
end
%The Send Button Handler:
function pushbutton13_Callback(hObject, eventdata, handles)
r=handles.pipe;
A=handles.A;
padding=0;
if length(A)==0
return
end
% if dialed less than 11 digits pad to 11 digits
if length(A)<11
padding=11-length(A);
A=[A ones(1,11-length(A))];
end
%build the Send Buffer
xmt=0.5*buildXmt(handles,A);
%Transmit DTMF signals buffer
sound(xmt,8192)
%Wait for end of detection
pause(4)
%read the digits from the rtdx:
num_of_msgs = msgcount(r,'OutputDigit');
r.flush('OutputDigit',num_of_msgs-1);
y=r.readmsg(handles.rtdx_chan1.name, 'double',1);
y=y(1:end-padding);
%Update the upper label with the digits read from dsk estimation
set(handles.text4, 'String', strrep(strrep(strrep(int2str(y),'10','*'),'11','#'),'20','*'));
handles.initFlag=1;
guidata(hObject, handles);
It will generate the DTMF samples Buer, based on the User Dialed information. The samples will be
sent to the sound-card. The program will then monitor the RTDX channel to receive the digits reported by
the DSK.
•
Enter the functions activated by the Clear and delete push buttons:
% Delete one digit.
function pushbutton14_Callback(hObject, eventdata, handles)
A=handles.A;
if length(A)==0
Available for free at Connexions <http://cnx.org/content/col10713/1.1>
244
CHAPTER 2.
SIGNAL PROCESSING AND COMMUNICATION
return
end
A=A(1:end-1);
set(handles.text1, 'String', strrep(strrep(strrep(int2str(A),'10','*'),'11','0'),'12','#'));
handles.A=A;
guidata(hObject, handles);
%Clear all the dialed digits.
function pushbutton15_Callback(hObject, eventdata, handles)
A=handles.A;
A=[];
set(handles.text1, 'String',
strrep(strrep(strrep(int2str(A),'10','*'),'11','0'),'12','#'));
handles.A=A;
guidata(hObject, handles);
2.4.3.6 Running the Example
The system used to run this example is shown in Figure 7.
Activate the GUI (DTMF.g). Enter an array of digits and compare them to those detected by the DSK.
2.4.4 Things to Try
The original algorithm (simulation) runs in a "noiseless" environment. You are invited to check the performance of the real-time model, and eventually change the algorithm to reduce its sensitivity to noise.
You may also add new buttons for DTMF parameters (level, frequency deviation, etc
. . .),
and test the
DTMF receiver performance against these parameters.
MATLAB
and
Simulink
are
registered
trademarks
of
The
www.mathworks.com/trademarks for a list of additional trademarks.
MathWorks,
Inc.
See
Other product or brand names
may be trademarks or registered trademarks of their respective holders.
2.5 Echo and Reverberation54
2.5.1 Introduction
Echo and Reverberation are two of the simplest applications of Digital Signal Processing (DSP). This laboratory shows how models of Echo and Reverberation can be designed using MATLAB and Simulink, and
run them in real-time on the Texas Instruments C6000 DSPs.
2.5.1.1 Objectives
•
Design models of Echo and Reverberation for the Texas Instruments C6000 family of DSP devices
® and Simulink®.
using MATLAB
•
•
Modify an existing Simulink model.
Run the model in real-time on the Texas Instruments C6713 DSK.
54 This
content is available online at <http://cnx.org/content/m22940/1.1/>.
Available for free at Connexions <http://cnx.org/content/col10713/1.1>
245
2.5.1.2 Level
Beginner - Assumes only very basic knowledge of MATLAB and Simulink. It is suitable for students with
limited knowledge of Texas Instruments DSPs.
2.5.1.3 Hardware and Software Requirements
This laboratory was originally developed using the following hardware and software:
•
•
•
•
MATLAB R2006b with Embedded Target for TI C6000.
Code Composer Studio (CCS) v3.1
Texas Instruments C6713 DSK hardware
Microphone and computer loudspeakers/headphones
2.5.1.4 Related Files
•
•
•
•
•
55
Powerpoint Presentation - EchoAndReverberation.ppt
56
Simulink Model for Echo Simulation - EchoUsingWav.mdl
Simulink Model for Reverberation Simulation - ReverberationUsingWav.mdl
Simulink Model for Real-Time - EchoAndReverberationDSKC6713.mdl
57
58
59
Audio Template for the DSK6713C6713_Audio_Template.mdl
2.5.2 Simulation
We shall start by running the Echo and Reverberation Simulink models. These use .wav les as the inputs.
2.5.2.1 Echo using Wave File
2.5.2.1.1 Opening the Echo Simulink Model
From MATLAB, open EchoUsingWav.mdl
55 See
56 See
57 See
58 See
59 See
the le at <http://cnx.org/content/m22940/latest/EchoAndReverberation.ppt>
the le at <http://cnx.org/content/m22940/latest/EchoUsingWav.mdl>
the le at <http://cnx.org/content/m22940/latest/ReverberationUsingWav.mdl>
the le at <http://cnx.org/content/m22940/latest/EchoAndReverberationDSKC6713.mdl>
the le at <http://cnx.org/content/m22940/latest/C6713_Audio_Template.mdl>
Available for free at Connexions <http://cnx.org/content/col10713/1.1>
246
CHAPTER 2.
SIGNAL PROCESSING AND COMMUNICATION
Figure 2.121: Echo using .wav File
2.5.2.1.2 Changing the Delay Time
Double-click on the Delay block and change the Delay (samples) to a dierent value.
Available for free at Connexions <http://cnx.org/content/col10713/1.1>
247
Figure 2.122: Changing the Delay Time
Run the model and hear how the eect has changed. Try a few dierent settings between 100 and 20000
Delay (samples).
2.5.2.2 Reverberation using Wave File
2.5.2.2.1 Opening the Reverberation Simulink Model
From MATLAB, open ReverberationUsingWav.mdl
Available for free at Connexions <http://cnx.org/content/col10713/1.1>
248
CHAPTER 2.
SIGNAL PROCESSING AND COMMUNICATION
Figure 2.123: Reverberaton Using .wav File
2.5.2.2.2 Changing the Delay Time
Double-click on the Delay block. Change the Delay (samples) to a dierent value then run the model
and listen to the eect.
2.5.2.2.3 Changing the Gain
Double-click on the Gain block. Change the Gain to 0.95 then run the model. Listen to the eect.
Available for free at Connexions <http://cnx.org/content/col10713/1.1>
249
Figure 2.124: Changing the Reverberation Gain
2.5.2.2.4 Questions
•
•
Why does Reverberation require a shorter delay time than echo?
What eect does the Gain block have on the stability of the reverberation system?
Available for free at Connexions <http://cnx.org/content/col10713/1.1>
250
CHAPTER 2.
SIGNAL PROCESSING AND COMMUNICATION
2.5.3 Real-Time Model for TI C6713 DSK
2.5.3.1 Texas Instruments C6713 DSK Setup
Figure 2.125: Texas Instruments C6713 DSK Setup
Alternatively, you can use computer loudspeakers.
Connect the C6713 hardware to a USB port of the computer and turn on the supply to the board.
If the board is powered, then the green LED lights on the board will come on during self-test.
2.5.3.2 Starting Code Composer Studio
The stages required to implement Echo and Reverberation are now described.
2.5.3.2.1 Starting Code Composer Studio
Start Code Composer Studio for C6713 DSK and use Debug -> Connect
Available for free at Connexions <http://cnx.org/content/col10713/1.1>
251
Figure 2.126: Startup Screen for Code Composer Studio (CCS)
2.5.3.2.2 Opening an Existing Model
Start MATLAB 7.3.0 R2006b
In the top left hand corner of the MATLAB screen, select File -> Open.
Available for free at Connexions <http://cnx.org/content/col10713/1.1>
252
CHAPTER 2.
SIGNAL PROCESSING AND COMMUNICATION
Figure 2.127: Opening an Existing Model(CCS)
The following screen will appear.
Figure 2.128: Selecting an Existing Model
Highlight C6713_Audio_Template then click on Open.
Available for free at Connexions <http://cnx.org/content/col10713/1.1>
253
2.5.3.2.3 Viewing the C6713 Audio Template
The C6713_Audio_Template is now displayed.
Figure 2.129: The C6713 DSK Audio Template>
2.5.3.2.4 Overview of the Complete Echo Subsystem
You are now going to implement the Echo Subsystem shown below.
Available for free at Connexions <http://cnx.org/content/col10713/1.1>
254
CHAPTER 2.
SIGNAL PROCESSING AND COMMUNICATION
Figure 2.130: The Complete Echo Subsytem
2.5.3.2.5 Implementing the Echo Subsystem
Double click on the Eect 1 subsystem block. An empty model will appear.
Available for free at Connexions <http://cnx.org/content/col10713/1.1>
255
Figure 2.131: The Blank Eect 1 Subsystem
You will now drag-and-drop some library components onto the model.
2.5.3.2.6 The Simulink Library Browser Commonly Used Blocks
Select View -> Library Browser. Expand the Simulink section.
A list of available blocks will appear. We are initially interested in the Commonly Used Blocks.
Available for free at Connexions <http://cnx.org/content/col10713/1.1>
256
CHAPTER 2.
SIGNAL PROCESSING AND COMMUNICATION
Figure 2.132: Commonly Used Blocks
From Commonly Used Blocks, drag-and-drop a Gain block, a Sum block and two Data Type
Conversion blocks onto the model.
2.5.3.2.7 The Simulink Library Browser - Discrete
From the Simulink Library Browser, select Discrete.
Highlight Integer Delay and drag-and-drop this
block onto the model.
Available for free at Connexions <http://cnx.org/content/col10713/1.1>
257
Available for free at Connexions <http://cnx.org/content/col10713/1.1>
Figure 2.133: Blocks
258
CHAPTER 2.
SIGNAL PROCESSING AND COMMUNICATION
2.5.3.2.8 Setting the Integer Delay Time
The delay time will be 0.5 seconds.
Using a sampling rate of 8000 Hz, this requires 8000 x 0.5 = 4000
samples. In the equation given in the lecture, this would make N = 4000.
Double click on the Integer Delay block. Change the Number of delays eld to 4000, then click on
OK.
Figure 2.134: Setting the Integer Delay Time
2.5.3.2.9 Setting the Output Data Conversion to Single
We want to set the gain to 0.9. If you multiply an integer value by 0.9, then the value 0.9 will be roundeddown to zero. Instead, you need to convert the integer value to a oating-point value such as single, and
then convert it back later. Click on OK.
Available for free at Connexions <http://cnx.org/content/col10713/1.1>
259
Figure 2.135: Setting the Data Conversion to Single
2.5.3.2.10 Setting the Delay Gain
We required that 0.9 of the delayed input is added to the normal input. Therefore, set the Gain to 0.9
then click on OK.
Available for free at Connexions <http://cnx.org/content/col10713/1.1>
260
CHAPTER 2.
SIGNAL PROCESSING AND COMMUNICATION
Figure 2.136: Setting the Echo Delay Gain
2.5.3.2.11 Setting the Output Data Conversion to int16
Double click on the second Data Type Conversion block. Set the Output data type mode to int16. This
is compatible with the DAC on the C6713 DSK.
Available for free at Connexions <http://cnx.org/content/col10713/1.1>
261
Figure 2.137: Data Type Conversion to 16-bit Integer
2.5.3.2.12 The Completed Echo Subsystem
Join the blocks as shown and add a title.
Available for free at Connexions <http://cnx.org/content/col10713/1.1>
262
CHAPTER 2.
SIGNAL PROCESSING AND COMMUNICATION
Figure 2.138: Joining the Blocks
2.5.3.2.13 Returning to the Parent System
From the Toolbar, select the Up Arrow icon. This returns you to the next higher level.
Figure 2.139: Returning to the Parent System
Available for free at Connexions <http://cnx.org/content/col10713/1.1>
263
2.5.3.3 The Reverberation Subsystem
The next subsystem to be implemented will be Reverberation.
2.5.3.3.1 Overview of the Completed Reverberation Subsystem
We are now going to implement the Reverberation System shown below.
Figure 2.140: Overview of the Reverberation Subsystem
Note that the reverberation subsystem is very similar to that of echo. We will cut-and-paste from the
Echo Subsystem
2.5.3.3.2 Opening the Eects 2 Subsystem
From the C6713 Audio Template top level, double-click on the Eect 2 subsystem.
Available for free at Connexions <http://cnx.org/content/col10713/1.1>
264
CHAPTER 2.
SIGNAL PROCESSING AND COMMUNICATION
Figure 2.141: The Blank Eect 2 Subsystem
2.5.3.3.3 Copying a Block from the Echo Subsystem
Double click on the Eect 1 subsystem. Cut-and-paste a copy of the echo block as follows: while leftclicking the mouse, mark the area to be copied.
Available for free at Connexions <http://cnx.org/content/col10713/1.1>
265
Figure 2.142: Outlining the Block to be Copied
Release the left button on the mouse.
Available for free at Connexions <http://cnx.org/content/col10713/1.1>
266
CHAPTER 2.
SIGNAL PROCESSING AND COMMUNICATION
Figure 2.143: Block to be Copied is Marked
From pull-down menu, select Edit -> Copy (or Ctrl + C)
2.5.3.3.4 Blocks Dropped onto Eect 2 Subsystem
Return to the Eect 2 subsystem and Edit -> Paste (Ctrl + V) into the model.
Available for free at Connexions <http://cnx.org/content/col10713/1.1>
267
Figure 2.144: Blocks Dropped onto Subsystem
2.5.3.3.5 Flipping the Blocks
The blocks are facing the wrong way. Turn them round using Format -> Flip Block.
Figure 2.145: Flipping the Blocks
2.5.3.3.6 Changing the Integer Delay for Reverberation.
Because the sound goes round several times with reverberation, a shorter delay time can be used. Here the
delay time is 0.1 seconds.
Available for free at Connexions <http://cnx.org/content/col10713/1.1>
268
CHAPTER 2.
SIGNAL PROCESSING AND COMMUNICATION
Figure 2.146: Delay Time for Reverberation
Set the Number of delays to 800 then click on OK.
2.5.3.3.7 Completing the Reverberation Subsystem
Connect the blocks as shown below. Change the title to Reverberation Subsystem.
Available for free at Connexions <http://cnx.org/content/col10713/1.1>
269
Figure 2.147: The Completed Reverberation Subsystem
2.5.3.3.8 Returning to the Parent System
From the Toolbar, select the Up Arrow icon. This returns you to the next higher level.
Figure 2.148: Returning to the Parent System
Available for free at Connexions <http://cnx.org/content/col10713/1.1>
270
CHAPTER 2.
SIGNAL PROCESSING AND COMMUNICATION
2.5.3.4 The Improved Echo Subsystem
The nal subsystem to be implemented will be Improved Echo. This is based on the Echo subsystem,
but with several delay paths.
2.5.3.4.1 The Complete Improved Echo Subsystem
Double click on the Eect 3 subsystem box. The required components are shown below.
Figure 2.149: The Improved Echo Subsystem
2.5.3.4.2 Implementing the Improved Echo Subsystem
You should now have enough knowledge to implement this subsystem block without further assistance. This
time you are on your own!
2.5.3.4.3 Building the Model
Select Tools -> Real-Time Workshop -> Build Model.
Available for free at Connexions <http://cnx.org/content/col10713/1.1>
271
Figure 2.150: Building the Model
2.5.3.5 Running the Model
2.5.3.5.1 Microphone Straight Through to Loudspeakers
To check out the microphone and loudspeakers, set the DIP switches on the C6713 DSK as follows:
Available for free at Connexions <http://cnx.org/content/col10713/1.1>
272
CHAPTER 2.
SIGNAL PROCESSING AND COMMUNICATION
Figure 2.151: Switch Position 0
The microphone is fed directly to the loudspeakers without any digital signal processing.
2.5.3.5.2 Switch Position for Echo
To run the Echo subsystem, set the DIP switch to 1.
Figure 2.152: Switch Position 1 for Echo
2.5.3.5.3 Switch Position for Reverberation
To run the Reverberation subsystem, set the DIP switch to 2.
Available for free at Connexions <http://cnx.org/content/col10713/1.1>
273
Figure 2.153: Switch Position 2 for Reverberation
2.5.3.5.4 Switch Position for Improved Echo
To run the Improved Echo subsystem, set the DIP switch to 3.
Figure 2.154: Switch Position 3 for Improved Echo
2.5.4 Some Things to Try
2.5.4.1 Change the Echo Delay
Change the value of the Integer Delay block for echo. Listen to the eect of using short and long delays.
Set the delay time to a large value and sing a round such as Frere Jacques or Row, Row, Row your Boat.
Available for free at Connexions <http://cnx.org/content/col10713/1.1>
274
CHAPTER 2.
SIGNAL PROCESSING AND COMMUNICATION
2.5.4.2 Change the Amount of Reverberation Gain
In the Reverberation Subsystem block, change the Gain from 0.8 to higher and lower values. Notice how
the system can become unstable if the gain is too large.
2.5.4.3 Modify the Improved Echo Subsystem
In the Improved Echo Subsystem, you may wish to experiment with the number of delay elements, the
delay times and the amounts of gain. Try to make the echo as realistic as possible.
2.5.4.4 Create Your Own Subsystem
Add your own subsystem block and add your own signal processing. You might want to design a subsystem
with both echo and reverberation.
MATLAB
and
Simulink
are
registered
trademarks
of
The
www.mathworks.com/trademarks for a list of additional trademarks.
MathWorks,
Inc.
See
Other product or brand names
may be trademarks or registered trademarks of their respective holders.
2.6 Signal to Noise Measurement60
2.6.1 Introduction
The signal-to-noise ratio of an audio signal gives a measurement of the quality of that signal. Signal-to-Noise
ratio can be measured in real-time using statistics.
This laboratory shows how to evaluate a model of Signal-to-Noise Ratio measurement using Simulink
®
and run it on a Texas Instruments C6000 DSP.
2.6.1.1 Objectives
•
Run the Simulink model of signal-to-noise ratio measurement on a PC, to determine the optimum
parameter settings.
•
Modify the Simulink model for real-time measurement of signal-to-noise ratio using the Texas Instruments C6713 DSK.
•
Run the project on the Texas Instruments C6713 DSK with a microphone and computer loudspeakers
/ headphones.
2.6.1.2 Level
® and Simulink.
Intermediate - Assumes prior knowledge of MATLAB
It also requires some understanding
of statistics and some knowledge of Texas Instruments DSPs.
2.6.1.3 Hardware and Software Requirements
This laboratory was originally developed using the following hardware and software:
•
•
•
•
MATLAB R2006b with Embedded Target for TI C6000.
Code Composer Studio (CCS) v3.1
Texas Instruments C6713 DSK hardware.
Microphone and computer loudspeakers / headphones.
60 This
content is available online at <http://cnx.org/content/m22941/1.1/>.
Available for free at Connexions <http://cnx.org/content/col10713/1.1>
275
2.6.1.4 Related Files
•
•
•
61
Powerpoint Presentation - SignalToNoise.ppt
Simulink Model for Simulation - SignalToNoise.mdl
62
Simulink Model for Real-Time - SignalToNoiseDSKC6713.mdl
63
2.6.2 Simulation
2.6.2.1 Procedure
2.6.2.1.1 Opening the SignalToNoise Model
Start MATLAB 7.3.0 R2006b then open the SignalToNoise.mdl
Figure 2.155: Opening SignalToNoise Model
2.6.2.1.2 Viewing the SignalToNoise Parent
The SignalToNoise parent is now displayed. Double-click on the Algorithm box.
61 See
62 See
63 See
the le at <http://cnx.org/content/m22941/latest/SignalToNoise.ppt>
the le at <http://cnx.org/content/m22941/latest/SignalToNoise.mdl>
the le at <http://cnx.org/content/m22941/latest/SignalToNoiseDSKC6713.mdl>
Available for free at Connexions <http://cnx.org/content/col10713/1.1>
276
CHAPTER 2.
SIGNAL PROCESSING AND COMMUNICATION
Figure 2.156: SignalToNoise Parent
2.6.2.1.3 Algorithm for Signal-to-Noise Ratio Measurement
The Signal-to-Noise Ratio algorithm is now displayed. Run the model.
Available for free at Connexions <http://cnx.org/content/col10713/1.1>
277
Figure 2.157: Signal-to-Noise Ratio Algorithm
2.6.2.1.4 Output of the Model
Run the model.
Available for free at Connexions <http://cnx.org/content/col10713/1.1>
278
CHAPTER 2.
SIGNAL PROCESSING AND COMMUNICATION
Figure 2.158: Algorithm Output
It will be seen that the output of the algorithm (Unltered S/N) varies from frame to frame. The next
step is to ne-tune the algorithm parameters.
2.6.2.2 Tuning the Simulink Model
The model is run several times to determine the best values of the parameters:
•
•
•
•
•
To evaluate the algorithm accuracy for dierent frequencies
To determine the optimal frame length
To set the optimum delay time
To evaluate the eect of sampling frequency
To obtain a consistent algorithm output.
2.6.2.2.1 Evaluating the Algorithm Accuracy for Dierent Frequencies
Change the sine wave frequency from 500 Hz (default) to 1000 Hz then run the model several times. Make
a note of the four dierent meter outputs (S/N Ratio from RMS Signals, Unltered S/N, Filtered S/N and
Buered).
Available for free at Connexions <http://cnx.org/content/col10713/1.1>
279
Figure 2.159: Changing the Sine Wave Frequency
Repeat using 1500Hz and 2000Hz.
Question: Does the input frequency of the Sine Wave have an eect on the accuracy of the algorithm?
If it does, then it would be useful to put a digital lter at the input to the algorithm to limit the frequency
Available for free at Connexions <http://cnx.org/content/col10713/1.1>
280
CHAPTER 2.
SIGNAL PROCESSING AND COMMUNICATION
band.
2.6.2.3 Sine Wave 300 Hz
Change the Sine Wave Frequency to 300Hz then run the model.
Available for free at Connexions <http://cnx.org/content/col10713/1.1>
281
Figure 2.160: Setting the Sine Wave to 300 Hz
Make a note of the accuracy of the model.
Available for free at Connexions <http://cnx.org/content/col10713/1.1>
282
CHAPTER 2.
SIGNAL PROCESSING AND COMMUNICATION
2.6.2.4 Changing the Frame Sizes
Increase the Samples per frame to 1024 in both the Sine Wave and the Random Source Blocks.
Figure 2.161: Adjusting Frame Size for Sine Wave
Available for free at Connexions <http://cnx.org/content/col10713/1.1>
283
Figure 2.162: Adjusting the Frame Size for the Random Source
Available for free at Connexions <http://cnx.org/content/col10713/1.1>
284
CHAPTER 2.
SIGNAL PROCESSING AND COMMUNICATION
Run the model again.
Question: How does this change to the frame size aect performance?
2.6.2.5 Setting the Delay Value
Click on the Delay Block. Change the number of Delay (samples) to 50.
Figure 2.163: Setting the Delay (samples)
Run the model again and make a note of the accuracy of the measurement.
64
Change Delay (samples)
to 12 and run the model again.
Question: How does the value of delay (samples) aect the accuracy of the model?
2.6.2.6 Changing the Amount of Noise Present
Reload the original model to restore the initial settings.
Change the amount of Gain to make the gain 0.10 (10% noise).
64 The
Delay (samples) should be smaller than the frame size, otherwise the frames do not overlap.
Available for free at Connexions <http://cnx.org/content/col10713/1.1>
285
Figure 2.164: Changing the Amount of Noise Present
Run the model and make a note of the accuracy of the measurements. Repeat, but this time, use a gain
of 0.01 (1% noise).
Question: Does the algorithm work better for high signal-to-noise ratios or for low signal-to-noise ratios?
Make a note of the answer.
2.6.2.7 Changing the Sampling Frequency
Change the sample time in both the Sine Wave and the Random Noise blocks to 48000 Hz.
Available for free at Connexions <http://cnx.org/content/col10713/1.1>
286
CHAPTER 2.
SIGNAL PROCESSING AND COMMUNICATION
Figure 2.165: Changing the Sine Wave Sample Time
Available for free at Connexions <http://cnx.org/content/col10713/1.1>
287
Figure 2.166: Changing the Random Source Sample Time
Available for free at Connexions <http://cnx.org/content/col10713/1.1>
288
CHAPTER 2.
SIGNAL PROCESSING AND COMMUNICATION
Run the model.
Question: Does the model produce better results with 8000Hz sampling or 48000 Hz sampling? Make a
note of the answer.
2.6.2.8 The Fully Optimized Simulation
You should now know what are the optimum parameters for the simulation.
Set these parameters and run the model.
2.6.2.9 Summary of Simulation
You have now run the signal-to-noise ratio model and should be aware of the best settings for consistency
of measurements, delay and sampling frequency.
You are now ready to go to the C6713 DSK Model.
2.6.3 Real-Time Model for TI C6713 DSK
2.6.3.1 Texas Instruments C6713 DSK Setup
Figure 2.167: Texas Instruments C6713 DSK Setup
Alternatively, you can use computer loudspeakers.
Available for free at Connexions <http://cnx.org/content/col10713/1.1>
289
2.6.3.2 Starting Code Composer Studio
There are several stages required in order to implement the Signal-to-Noise measurement. These are now
described.
2.6.3.2.1 Starting up Code Composer Studio
Start Code Composer Studio for C6713 DSK and use Debug -> Connect
Figure 2.168: Startup Screen for Code Composer Studio (CCS)
2.6.3.3 The Texas Instruments C6713 DSK Model
You will now use the knowledge you have gained during the PC Simulation to produce an optimized version
of this algorithm for use with the Texas Instruments C6713 DSK.
2.6.3.3.1 Opening the C6713 DSK Model
Open the SignalToNoiseDSK6713.mdl.
Available for free at Connexions <http://cnx.org/content/col10713/1.1>
290
CHAPTER 2.
SIGNAL PROCESSING AND COMMUNICATION
The parent is shown in Figure 15.
Figure 2.169: SignalToNoiseDSK6713.mdl
Double click on the function() block.
2.6.3.3.2 Viewing the Signal-to-Noise Measurement Algorithm
The details of the C6713 Algorithm are shown in Figure 16.
Available for free at Connexions <http://cnx.org/content/col10713/1.1>
291
Figure 2.170: Audio Noise Gate
2.6.3.3.3 Setting the Sampling Rate and Frame Size
Double-click on the Mic In C6713 DSK ADC block.
Set the Sampling rate (Hz) and Samples per frame elds to the best value you found while carrying out
the Simulation. The values may be dierent to those written here.
Available for free at Connexions <http://cnx.org/content/col10713/1.1>
292
CHAPTER 2.
SIGNAL PROCESSING AND COMMUNICATION
Figure 2.171: Setting the Sampling Rate and Frame Size
2.6.3.3.4 Setting the Delay Size
Double-click on the Delay block. Set the Delay (samples) to the best value found during simulation. The
value will not be 999!
Available for free at Connexions <http://cnx.org/content/col10713/1.1>
293
Figure 2.172: Setting the Delay Size
2.6.3.3.5 Returning to the Parent System
From the Toolbar, select the Up Arrow icon. This returns you to the next higher level.
Available for free at Connexions <http://cnx.org/content/col10713/1.1>
294
CHAPTER 2.
SIGNAL PROCESSING AND COMMUNICATION
Figure 2.173: Returning to the Parent System
2.6.3.4 Building the Model
2.6.3.4.1 Selecting Real-Time Workshop
Select Tools -> Real-Time Workshop -> Build Model.
Available for free at Connexions <http://cnx.org/content/col10713/1.1>
295
Figure 2.174: Building the Model
2.6.3.4.2 The Completed Model Running on Code Composer Studio
From the folders on the left, select the source code for the project.
Available for free at Connexions <http://cnx.org/content/col10713/1.1>
296
CHAPTER 2.
SIGNAL PROCESSING AND COMMUNICATION
Figure 2.175: The Completed Model Running in Code Composer Studio
2.6.3.5 Dierent Settings on the C6713 DSK
2.6.3.5.1 Microphone Straight Through to Loudspeakers
To check out the microphone and loudspeakers, set the DIP switches on the C6713 DSK as follows:
Figure 2.176: Switch Position 0
Available for free at Connexions <http://cnx.org/content/col10713/1.1>
297
The microphone is fed directly to the loudspeakers. There is no noise gate.
2.6.3.6 Switch Position for the Audio Noise Gate
To run the Audio Noise Gate, set the DIP switch to 1.
Figure 2.177: Switch Position 1 for Audio Noise Gate
Note that when you are not speaking, there is no audio output at all just silence.
2.6.4 Modifying the Model
The next stage is to modify the model. You can change the smoothing lter. If the lter is too long, the
delay will be noticeable.
2.6.4.1 Changing the Filter Type
Double-click on the Lowpass block. Change the Order to a value other than 10.
Available for free at Connexions <http://cnx.org/content/col10713/1.1>
298
CHAPTER 2.
SIGNAL PROCESSING AND COMMUNICATION
Figure 2.178: Changing the Number of Filter Elements
Available for free at Connexions <http://cnx.org/content/col10713/1.1>
299
2.6.4.2 Re-building the Model
Select Tools -> Real-Time Workshop -> Build Model.
Figure 2.179: Re-building the Model
2.6.4.3 Running the Updated Model
Run the updated model and listen to the eect on the audio noise gate.
2.6.5 Some Things to Try
You may wish to experiment with dierent settings. Here are some suggestions.
2.6.5.1 Add an Input Filter
While running the Simulation, you will have noticed that the Signal-to-Noise Algorithm works better on
some frequencies than others.
Add the appropriate lter to select only the frequencies where the algorithm works well.
Available for free at Connexions <http://cnx.org/content/col10713/1.1>
300
CHAPTER 2.
SIGNAL PROCESSING AND COMMUNICATION
2.6.5.2 Process Stereo Inputs
Change the input from Microphone to Stereo Line Input.
Add a second channel to make the processing stereo.
2.6.5.3 Best Signal Selection
When stage 3.2 has been completed, modify the model so that the output is the better of the two stereo
inputs.
MATLAB
and
Simulink
are
registered
trademarks
of
The
www.mathworks.com/trademarks for a list of additional trademarks.
MathWorks,
Inc.
See
Other product or brand names
may be trademarks or registered trademarks of their respective holders.
2.7 Spectrum Estimation65
2.7.1 Introduction
In this module the DSK6713 will be used for spectrum estimation.
Three estimation methods will be
implemented:
1. Periodogram
2. Burg
3. M-Cov
Periodogram
Figure 2.180
The Periodogram block computes a nonparametric estimate of the spectrum.
The block averages the
squared magnitude of the FFT computed over windowed sections of the input and normalizes the spectral
average by the square of the sum of the window samples.
The Modied Covariance Method
65 This
content is available online at <http://cnx.org/content/m22942/1.1/>.
Available for free at Connexions <http://cnx.org/content/col10713/1.1>
301
Figure 2.181
The Modied Covariance Method block estimates the power spectral density (PSD) of the input using
the modied covariance method. This method ts an autoregressive (AR) model to the signal by minimizing
the forward and backward prediction errors in the least squares sense. The order of the all-pole model is the
value specied by the Estimation order parameter. To guarantee a valid output, you must set the Estimation
order parameter to be less than or equal to two thirds the input vector length. The spectrum is computed
from the FFT of the estimated AR model parameters.
Burg Method
Figure 2.182
The Burg Method block estimates the power spectral density (PSD) of the input frame using the Burg
method.
This method ts an autoregressive (AR) model to the signal by minimizing (least squares) the
forward and backward prediction errors while constraining the AR parameters to satisfy the Levinson-Durbin
recursion.
2.7.1.1 Related Files
•
•
•
•
•
•
•
•
Powerpoint Presentation - SpectrumEstimation.ppt
66
67
Simulink Model for Simulation - SpectrumEstimation.mdl
MATLAB GUI for Real-Time - Spectrum.g
68
69
GUI m-leSpectrum.m
m-le for Selection of estimation method SelectModel.m
70
71
Simulink Model for Burg Estimation Method Burg.mdl
Simulink Model for Periodogram Estimation MethodPeriodogram.mdl
72
Simulink Model for Modied Covariance Estimation MethodMCov_AR.mdl
66 See
67 See
68 See
69 See
70 See
71 See
72 See
73 See
73
the le at <http://cnx.org/content/m22942/latest/SpectrumEstimation.ppt>
the le at <http://cnx.org/content/m22942/latest/SpectrumEstimation.mdl>
the le at <http://cnx.org/content/m22942/latest/Spectrum.g>
the le at <http://cnx.org/content/m22942/latest/Spectrum.m>
the le at <http://cnx.org/content/m22942/latest/SelectModel.m>
the le at <http://cnx.org/content/m22942/latest/Burg.mdl>
the le at <http://cnx.org/content/m22942/latest/Periodogram.mdl>
the le at <http://cnx.org/content/m22942/latest/MCov_AR.mdl>
Available for free at Connexions <http://cnx.org/content/col10713/1.1>
302
CHAPTER 2.
SIGNAL PROCESSING AND COMMUNICATION
2.7.2 Simulation
2.7.2.1 The Environment
Figure 4 shows the data ow for the Estimation simulation. The input signal for the estimator is an AR
process generated by feeding an all-poles lter with white noise. The AR coecients generate the reference
spectrum to be compared against the estimated one.
Figure 2.183: Spectrum Estimation Simulation
2.7.2.2 The Procedure
® and name it:
1. Create a new model in Simulink
SpectrumEstimation.mdl
2. Open the Simulink library browser and add a random source object:
Available for free at Connexions <http://cnx.org/content/col10713/1.1>
303
Figure 2.184: The Random Source Object
3. Double click on the random source object, and congure its parameters to t the white noise characteristics we want to achieve:
Available for free at Connexions <http://cnx.org/content/col10713/1.1>
304
CHAPTER 2.
SIGNAL PROCESSING AND COMMUNICATION
Figure 2.185: The Random Source Object Conguration
Available for free at Connexions <http://cnx.org/content/col10713/1.1>
305
4. Add a new digital lter to the model:
Figure 2.186: The Digital Filter Block
5. Double-click on the lter and ll in the following parameters
74 The
74
Auto-Regressive process is represented by an all-pole IIR lter. The AR coecients are the ones in the Denominator
coecients label.
Available for free at Connexions <http://cnx.org/content/col10713/1.1>
306
CHAPTER 2.
SIGNAL PROCESSING AND COMMUNICATION
Figure 2.187: The Digital Filter Block Parameters
Available for free at Connexions <http://cnx.org/content/col10713/1.1>
307
6. Add the 3 estimators: Periodogram, Burg and Modied-Covariance to your model:
Figure 2.188: The Burg Method Block
75
7. Congure the FFT length of the three models to 128
75 The
:
same conguration parameters apply for the three models.
Available for free at Connexions <http://cnx.org/content/col10713/1.1>
308
CHAPTER 2.
SIGNAL PROCESSING AND COMMUNICATION
Figure 2.189: FFT Length Conguration for Spectrum Estimation
8. Add a new constant to your model:
Available for free at Connexions <http://cnx.org/content/col10713/1.1>
309
Figure 2.190: The "DSP Constant" Block
9. This constant will have the AR coecients values:
Available for free at Connexions <http://cnx.org/content/col10713/1.1>
310
CHAPTER 2.
SIGNAL PROCESSING AND COMMUNICATION
Figure 2.191: The AR coecients values
10. Add a magnitude FFT block in order to get the spectrum from the AR coecients:
Available for free at Connexions <http://cnx.org/content/col10713/1.1>
311
Figure 2.192: The FFT Block
11. Set the FFT length to 128:
Figure 2.193: The FFT Length
12. Add a new math function object:
Available for free at Connexions <http://cnx.org/content/col10713/1.1>
312
CHAPTER 2.
SIGNAL PROCESSING AND COMMUNICATION
Figure 2.194: The Math Function Block
13. The Math Function block should be congured to calculate the reciprocal:
Available for free at Connexions <http://cnx.org/content/col10713/1.1>
313
Figure 2.195: The "Math Function" Block Conguration
14. Add a new gain to your model (to represent the white noise variance in the reference spectrum generation) and set its value to 0.1:
Available for free at Connexions <http://cnx.org/content/col10713/1.1>
314
CHAPTER 2.
SIGNAL PROCESSING AND COMMUNICATION
Figure 2.196: The Gain Block
15. In order to display the Real and Estimated spectra simultaneously, you need to add a new concatenate
object:
Figure 2.197: The "Matrix Concatenate" Block
16. Set the number of inputs of the concatenation object to 4:
Available for free at Connexions <http://cnx.org/content/col10713/1.1>
315
Figure 2.198: The "Matrix Concatenate" Block Conguration
17. The various spectra will be displayed in a vector scope:
Available for free at Connexions <http://cnx.org/content/col10713/1.1>
316
CHAPTER 2.
SIGNAL PROCESSING AND COMMUNICATION
Figure 2.199: The "Vector Scope" Block
18. Select frequency as its input domain
Available for free at Connexions <http://cnx.org/content/col10713/1.1>
317
Figure 2.200: The "Vector Scope" Block Conguration
19. Connect the blocks as shown:
Available for free at Connexions <http://cnx.org/content/col10713/1.1>
318
CHAPTER 2.
SIGNAL PROCESSING AND COMMUNICATION
Figure 2.201: Spectrum Estimation Simulation
20. When running the model
76 You
76
, you should see the get the following display:
should select a dierent color for each channel
Available for free at Connexions <http://cnx.org/content/col10713/1.1>
319
Figure 2.202: Comparing the various spectrum estimators
2.7.3 Real Time Implementation
2.7.3.1 The Environment
Figure 21 shows the block-diagram for the real time implementation.
The DSP will deliver two outputs.
The rst is the reference spectrum; the second is an estimated spectrum of the output of the all-pole lter.
Three real-time models will be created, each one corresponding to an estimator. The user will be able to
select the desired estimator through a Graphic User Interface (GUI).
Available for free at Connexions <http://cnx.org/content/col10713/1.1>
320
CHAPTER 2.
SIGNAL PROCESSING AND COMMUNICATION
Figure 2.203: Real Time Implementation Environment
The real-time implementation model will be created from the simulation model, after the following
changes:
•
•
•
The noise generator block will be replaced by the CODEC of the DSK6713
The virtual scope will be replaced also by the CODEC
A target denition block (DSK6713) will be added.
Equipment Used:
•
•
•
DSK6713
Dual Channel Oscilloscope
Signal Generator
Available for free at Connexions <http://cnx.org/content/col10713/1.1>
321
Figure 2.204: Real Spectrum Estimation Equipment
2.7.3.2 Creating the Models
1. Open the simulation model SpectrumEstimation.mdl.
2. Remove the Burg and MCov AR estimators.
3. Add the C6713DSK target to the model
Available for free at Connexions <http://cnx.org/content/col10713/1.1>
322
CHAPTER 2.
SIGNAL PROCESSING AND COMMUNICATION
Figure 2.205: The C6713DSK target Block
4. Replace the vector scope by the Digital to Analog converter (DAC)
Available for free at Connexions <http://cnx.org/content/col10713/1.1>
323
Figure 2.206: The DAC Block
5. Congure the DAC block to a sampling rate to 8 KHZ and 16-bit samples.
Available for free at Connexions <http://cnx.org/content/col10713/1.1>
324
CHAPTER 2.
SIGNAL PROCESSING AND COMMUNICATION
Figure 2.207: The DAC Block Conguration
6. Double- click on the concatenation object and change the number of inputs from 4 to 2.
7. Replace the white noise generator by the Analog to Digital converter (ADC).
Available for free at Connexions <http://cnx.org/content/col10713/1.1>
325
Figure 2.208: The ADC Block
8. Congure the ADC blocks to a sampling rate to 8 KHZ and 16-bit samples.
Available for free at Connexions <http://cnx.org/content/col10713/1.1>
326
CHAPTER 2.
SIGNAL PROCESSING AND COMMUNICATION
Figure 2.209: The ADC Block Conguration
9. The nal model should look as follows:
Available for free at Connexions <http://cnx.org/content/col10713/1.1>
327
Figure 2.210: Periodogram Real-Time Model
10. Set the AR-coecients data type to single.
11. Congure the Model to generate and build (without executing) the CCS code as shown:
Available for free at Connexions <http://cnx.org/content/col10713/1.1>
328
CHAPTER 2.
SIGNAL PROCESSING AND COMMUNICATION
Figure 2.211: Model Conguration
Available for free at Connexions <http://cnx.org/content/col10713/1.1>
329
12. Save the model as Periodogram.mdl
13. Build the model (CTRL-B)
14. Replace the Periodogram estimator block by the Burg estimator
15. The nal model should look as follows:
Figure 2.212: Burg Real-Time Model
16. Save the model as Burg.mdl
17. Build the model (CTRL-B)
18. Replace the Burg estimator block by the MCov AR estimator
19. The nal model should look as follows:
Available for free at Connexions <http://cnx.org/content/col10713/1.1>
330
CHAPTER 2.
SIGNAL PROCESSING AND COMMUNICATION
Figure 2.213: MCov AR Burg Real-Time Model
20. Save the model as MCcov_AR.mdl
21. Build the model (CTRL-B)At this step you'll have three .out les to be loaded to the DSK. Each one
corresponding to an estimator.
2.7.3.3 The Graphic User Interface (GUI)
The GUI shown in Figure 32 will be used to select the model. Upon selecting a model, its correspondent
load le will be loaded to the DSP.
Available for free at Connexions <http://cnx.org/content/col10713/1.1>
331
Figure 2.214: Graphic User Interface (GUI)
® command line.
1. Enter GUIDE in the MATLAB
2. Choose a new GUI, and name it Spectrum
3. Add a list-box to your GUI with the string:
Periodogram
Burg
M-Cov
4. A script le spectrum.m will open, when you press the play button. Name the script spectrum.m
5. The GUI will perform the following tasks:
•
•
Upon activating the GUI, the default model is loaded to the DSP.
When the user selects a new model, it is loaded to the DSP.
6. The initialization routine Spectrum_OpeningFcn will be:
function Spectrum_OpeningFcn(hObject, eventdata, handles, varargin)
modelName = gcs;
%connect to target:
CCS_Obj = connectToCCS(modelName);
% Identify RTDX channel names/modes
CodegenDir = fullfile(pwd, ['Periodogram' '_c6000_rtw']);
OutFile = fullfile(CodegenDir, ['Periodogram' '.out']);
%load the model to the DSK:
CCS_Obj.load(OutFile,20);
handles.CCS_Obj=CCS_Obj;
Available for free at Connexions <http://cnx.org/content/col10713/1.1>
332
CHAPTER 2.
SIGNAL PROCESSING AND COMMUNICATION
handles.output = hObject;
%remember the current model:
handles.last_model=1;
CCS_Obj.run;
% Update handles structure
guidata(hObject, handles);
7. Selecting a new model:
%1. halts the current model
%2. loads the current model
%inputs:
%m - 3 levels flag that tells which model to load.
%CCS_Obj - the target object
function ChangeModel(m,CCS_Obj)
CCS_Obj.halt;
switch m
case 1
model='Periodogram';
case 2
model='Burg';
case 3
model= 'MCov_AR';
end
CodegenDir = fullfile(pwd, [model '_c6000_rtw']);
OutFile = fullfile(CodegenDir, [model '.out']);
CCS_Obj.load(OutFile,20);
CCS_Obj.run;
if last_y∼=15000
r.writemsg(chan_struct(2).name,1/last_y);
end
8. When the user changes the model, the list-box handler function is invoked:
function listbox1_Callback(hObject, eventdata, handles)
handles.last_model=get(hObject,'Value') ;
ChangeModel(handles.last_model,handles.CCS_Obj);
guidata(hObject, handles);
The handler saves the new model as the current model and invokes the change model function we described
above.
Now you can run the model, and observe the results in the oscilloscope for the various estimators.
2.8 Wavelet Denoising77
2.8.1 Introduction
Wavelets can be used in a range of applications, one of which is noise reduction.
This laboratory shows how to design a model of Wavelet Noise Reduction using Simulink and run it on
a Texas Instruments C6000 DSP.
77 This
content is available online at <http://cnx.org/content/m23011/1.1/>.
Available for free at Connexions <http://cnx.org/content/col10713/1.1>
333
2.8.1.1 Objectives
•
Design a model of Wavelet Noise Reduction for the Texas Instruments C6000 family of DSP devices
® and Simulink®.
using MATLAB
•
•
Modify an existing Simulink demonstration model.
Run the project on the Texas Instruments C6713 DSK with a microphone and computer loudspeakers
/ headphones.
2.8.1.2 Level
Intermediate.
Assumes prior knowledge of MATLAB and Simulink.
It also requires a theoretical under-
standing of wavelets and some knowledge of Texas Instruments DSPs.
2.8.1.3 Hardware and Software Requirements
This laboratory was originally developed using the following hardware and software:
•
•
•
•
MATLAB R2006b with Embedded Target for TI C6000.
Code Composer Studio (CCS) v3.1
Texas Instruments C6713 DSK hardware.
Microphone and computer loudspeakers / headphones.
2.8.1.4 Related Files
•
•
•
Powerpoint Presentation WaveletDenoising.ppt
78
79
Simulink Model for Simulation- WaveletDenoising.mdl
80
Simulink Model for Real-Time WaveletDenoisingDSKC6713.mdl
2.8.2 Simulation
2.8.2.1 Simulink Model
The Simulink model described here is based on a MATLAB Demo.
2.8.2.1.1 Opening the Model
Open WaveletDenoising.mdl
78 See
79 See
80 See
the le at <http://cnx.org/content/m23011/latest/WaveletDenoising.ppt>
the le at <http://cnx.org/content/m23011/latest/WaveletDenoising.mdl>
the le at <http://cnx.org/content/m23011/latest/WaveletDenoisingDSKC6713.mdl>
Available for free at Connexions <http://cnx.org/content/col10713/1.1>
334
CHAPTER 2.
SIGNAL PROCESSING AND COMMUNICATION
Figure 2.215: Opening WaveletDenoising.mdl
2.8.2.1.2 Running the Model
Run the model. The colors change to show the dierent lter channels. Green = high frequency.
Available for free at Connexions <http://cnx.org/content/col10713/1.1>
335
Figure 2.216: Wavelet Model Showing Color Coding
2.8.2.1.3 Scope Output
The scope output shows how the random noise has been separated out (Residual).
Available for free at Connexions <http://cnx.org/content/col10713/1.1>
336
CHAPTER 2.
SIGNAL PROCESSING AND COMMUNICATION
Figure 2.217: Scope Output
2.8.2.1.4 Monitoring the Dyadic Filter Outputs
Add an extra scope as shown in Figure 4 to display the Diadic Filter Outputs.
Available for free at Connexions <http://cnx.org/content/col10713/1.1>
337
Figure 2.218: Monitoring the Dyadic Filter Outputs
2.8.2.1.5 Analysis of Diadic Filter Outputs
It can be seen that the noise is on Out1, Out2 and Out3. The clean input signal is on Out4.
Available for free at Connexions <http://cnx.org/content/col10713/1.1>
338
CHAPTER 2.
SIGNAL PROCESSING AND COMMUNICATION
Figure 2.219: Noise Levels at Dyadic Filter Outputs
2.8.2.1.6 Modifying the Dead Zone
Double-click on the Soft Threshold block. This is the actual noise reduction stage. The elds are in order
Out1, Out2, Out3 and Out4.
Available for free at Connexions <http://cnx.org/content/col10713/1.1>
339
Figure 2.220: Noise Levels at Dyadic Filter Outputs
Here Out1 has been given a threshold of 3. This means that only values
>
3 are let through.
Out2, Out3 and Out4 have been given the value of 0. This means the whole signal is let through.
The output is shown in Figure 6.
Note that the noise associated with Out2 and Out3 have not been
reduced.
Available for free at Connexions <http://cnx.org/content/col10713/1.1>
340
CHAPTER 2.
SIGNAL PROCESSING AND COMMUNICATION
Figure 2.221: Threshold only applied to Out1
2.8.2.1.7 Changing the Delay Alignment
Double-click on the Delay Alignment block. Temporarily remove the delays on Out1 and Out2.
Available for free at Connexions <http://cnx.org/content/col10713/1.1>
341
Figure 2.222: Removing the Delay Alignments
Run the model to see the eect.
2.8.2.1.8 Summary of Simulation
From practical experimentation using the Simulink model, you should now understand how wavelet denoising
works.
Available for free at Connexions <http://cnx.org/content/col10713/1.1>
342
CHAPTER 2.
SIGNAL PROCESSING AND COMMUNICATION
2.8.3 Real-Time Model for TI C6713 DSK
2.8.3.1 Texas Instruments C6713 DSK Setup
Figure 2.223: Texas Instruments C6713 DSK Setup
2.8.3.2 Simulink Model for C6713 DSK
2.8.3.2.1 Starting Code Composer Studio
Start Code Composer Studio for C6713 DSK and use Debug -> Connect.
Available for free at Connexions <http://cnx.org/content/col10713/1.1>
343
Figure 2.224: Startup Screen for Code Composer Studio (CCS)
2.8.3.2.2 Opening an Existing Model
Start MATLAB 7.3.0 R2006b:
Figure 2.225: Opening an Existing Demo
Available for free at Connexions <http://cnx.org/content/col10713/1.1>
344
CHAPTER 2.
SIGNAL PROCESSING AND COMMUNICATION
Click on Demos. The following screen will appear:
Figure 2.226: Selecting the Audio Demo Models
Highlight Embedded Target for TI C6000 DSP then Audio. Click on Wavelet Denoising.
2.8.3.2.3 Viewing the Wavelet Denoising Parent
The Wavelet Denoising model is now displayed. Double-click on the function() box.
Available for free at Connexions <http://cnx.org/content/col10713/1.1>
345
Figure 2.227: Wavelet Denoising Parent
2.8.3.2.4 The Original Wavelet Noise Reduction Algorithm
The Wavelet Noise Reduction Algorithm model is now displayed.
Available for free at Connexions <http://cnx.org/content/col10713/1.1>
346
CHAPTER 2.
SIGNAL PROCESSING AND COMMUNICATION
Figure 2.228: Wavelet Denoising Algorithm
2.8.3.2.5 Copying the Model
For convenience, copy the model to the MATLAB Work directory where most models are stored.
Available for free at Connexions <http://cnx.org/content/col10713/1.1>
347
Figure 2.229: Copying the Model to the MATLAB Work directory
2.8.3.2.6 Overview of the Modied Model
In order to run the model on the C6713 DSK and be able to compare the performance with and without
noise reduction, we will make some small modications to the demo model.
Available for free at Connexions <http://cnx.org/content/col10713/1.1>
348
CHAPTER 2.
SIGNAL PROCESSING AND COMMUNICATION
Figure 2.230: The Modied Algorithm
You will now update the existing model by dragging-and-dropping some library components onto the
model.
2.8.3.2.7 Changing the Input to Microphone
Double-click on the blue box to the left marked C6713 DSK ADC. The following options will appear.
Available for free at Connexions <http://cnx.org/content/col10713/1.1>
349
Figure 2.231: Setting up the ADC for Microphone Input
Change the ADC source to Mic In and tick the Stereo box. If you have a quiet microphone, tick
the +20dB Mic gain boost box. When done, click on OK.
2.8.3.2.8 The DAC Settings
The DAC settings need to match those of the ADC. Check that they are the same.
Available for free at Connexions <http://cnx.org/content/col10713/1.1>
350
CHAPTER 2.
SIGNAL PROCESSING AND COMMUNICATION
Figure 2.232: Setting the DAC Parameters
2.8.3.2.9 Adding a DIP Switch and LED
To change between no wavelet denoising and with wavelet noise reduction, we will use a DIP switch of the
C6713 DSK.
Available for free at Connexions <http://cnx.org/content/col10713/1.1>
351
Available for free at Connexions <http://cnx.org/content/col10713/1.1>
Figure 2.233: Adding a Switch and LED
352
CHAPTER 2.
SIGNAL PROCESSING AND COMMUNICATION
Select View -> Library Browser -> Embedded Target for TI C6000 DSP. Highlight C6713 DSK Board
Support.
Drag-and-drop the Switch block onto the model. Also drag-and-drop the LED block onto the model.
2.8.3.2.10 DIP Switch Settings
The DIP switch needs to be congured. Double-click on the Switch block.
Put at tick in all of the boxes and set Data type to Integer. The Sample time should also be set to
1.
Figure 2.234: Setting up the DIP Switch Value
2.8.3.2.11 Adding a Constant, Switch and Relational Operator
We now need to setup a way to switch between straight through without noise reduction and with wavelet
noise reduction.
Select View -> Library Browser -> Simulink. Highlight Commonly Used Blocks.
Available for free at Connexions <http://cnx.org/content/col10713/1.1>
353
Drag-and-drop a Constant onto the model.
Drag-and-drop a Switch block onto the model.
Drag-and-drop a Relational Operator block onto the model.
Available for free at Connexions <http://cnx.org/content/col10713/1.1>
354
CHAPTER 2.
SIGNAL PROCESSING AND COMMUNICATION
Available for free at Connexions <http://cnx.org/content/col10713/1.1>
Figure 2.235: Selecting the Commonly Used Blocks
355
2.8.3.2.12 Setting the Constant Value
The switch values lie between 0 and 15. We will use switch values 0 and 1. Double-click on the Constant
block. Set the Constant value to 1 and the Sample time to inf .
Figure 2.236: Setting the Echo Delay Gain
2.8.3.2.13 Setting the Constant Data Type
Click on the Signal Data Types tab. Set the Output data type mode to int16. This is compatible with
the DAC on the C6713 DSK. Click on OK.
Available for free at Connexions <http://cnx.org/content/col10713/1.1>
356
CHAPTER 2.
SIGNAL PROCESSING AND COMMUNICATION
Figure 2.237: Data Type Conversion to 16-bit Integer
2.8.3.2.14 Setting the Relational Operator Type
Double click on the Relational Operator block. Change the Relational operator to ==. Click on the
Signal Data Types tab.
Available for free at Connexions <http://cnx.org/content/col10713/1.1>
357
Figure 2.238: Changing the Relational Operator
2.8.3.2.15 Setting the Relational Operator Data Type
Set the Output data type mode to Boolean.
Available for free at Connexions <http://cnx.org/content/col10713/1.1>
358
CHAPTER 2.
SIGNAL PROCESSING AND COMMUNICATION
Figure 2.239: Changing the Output Data Type
2.8.3.2.16 Joining the Blocks
Move the blocks and join them as shown in the Figure below.
Available for free at Connexions <http://cnx.org/content/col10713/1.1>
359
Figure 2.240: Joining the Blocks
2.8.3.2.17 Checking the Dyadic Analysis Filter Bank
Double click on the Dyadic Analysis Filter Bank block. The values of the Dyadic Analysis Filter Bank are
shown below. You do not need to change them yet. Click on OK.
Available for free at Connexions <http://cnx.org/content/col10713/1.1>
360
CHAPTER 2.
SIGNAL PROCESSING AND COMMUNICATION
Figure 2.241: Checking the Dyadic Analysis Filter Bank
Available for free at Connexions <http://cnx.org/content/col10713/1.1>
361
2.8.3.2.18 Checking the Delay Alignment
The delay alignment is shown below, with dierent delay times for the dierent frequencies.
Figure 2.242: Checking the Delay Alignment
2.8.3.2.19 Checking the Soft Threshold
The Soft Threshold sets the threshold below which noise is ignored for each of the four channels.
means no noise reduction.
Available for free at Connexions <http://cnx.org/content/col10713/1.1>
Zero
362
CHAPTER 2.
SIGNAL PROCESSING AND COMMUNICATION
Figure 2.243: Checking the Thresholds
2.8.3.2.20 Checking the Dyadic Synthesis
Double-click on the Dyadic Synthesis Filter Bank. There is no need to change the values at this time. Click
on OK when done.
Available for free at Connexions <http://cnx.org/content/col10713/1.1>
363
Figure 2.244: Checking the Dyadic Synthesis Filter Bank
Available for free at Connexions <http://cnx.org/content/col10713/1.1>
364
CHAPTER 2.
SIGNAL PROCESSING AND COMMUNICATION
2.8.3.2.21 Returning to the Parent System
From the Toolbar, select the Up Arrow icon. This returns you to the next higher level.
Figure 2.245: Returning to the Parent System
2.8.3.3 Building the Model
2.8.3.3.1 Selecting Real-Time Workshop
Select Tools -> Real-Time Workshop -> Build Model.
Available for free at Connexions <http://cnx.org/content/col10713/1.1>
365
Figure 2.246: Building the Model
2.8.3.3.2 The Completed Model Running on Code Composer Studio
From the folders on the left, select the source code for the project.
Available for free at Connexions <http://cnx.org/content/col10713/1.1>
366
CHAPTER 2.
SIGNAL PROCESSING AND COMMUNICATION
Figure 2.247: The Completed Model Running under Code Composer Studio
2.8.3.4 Dierent Settings on the C6713 DSK
2.8.3.4.1 Microphone Straight Through to Loudspeakers
To check out the microphone and loudspeakers, set the DIP switches on the C6713 DSK as follows:
Available for free at Connexions <http://cnx.org/content/col10713/1.1>
367
Figure 2.248: Switch Position 0
The microphone is fed directly to the loudspeakers. There is no noise reduction.
2.8.3.4.2 Switch Position for Wavelet Noise Reduction
To run the Wavelet Noise Reduction subsystem, set the DIP switch to 1.
Figure 2.249: Switch Position 1 for Wavelet Noise Reduction
2.8.3.5 Modifying the Model
The next stage is to modify the model. We will change the wavelet type to Symlets.
2.8.3.5.1 Changing the Filter Type
Double-click on the Dyadic Analysis Filter Bank block. Change the Filter eld to Symlets. Click on
OK.
Available for free at Connexions <http://cnx.org/content/col10713/1.1>
368
CHAPTER 2.
SIGNAL PROCESSING AND COMMUNICATION
Figure 2.250: Dyadic Analysis Filter Bank set to Symlets
Available for free at Connexions <http://cnx.org/content/col10713/1.1>
369
2.8.3.5.2 Updating the Dyadic Synthesis Filter Bank
The wavelet type should be the same as that used in the Dyadic Analysis Filter Bank. Double-click on the
Dyadic Synthesis Filter Bank block. Change the Filter eld to Symlets. Click on OK.
Available for free at Connexions <http://cnx.org/content/col10713/1.1>
370
CHAPTER 2.
SIGNAL PROCESSING AND COMMUNICATION
Figure 2.251: Conguring the Dyadic Synthesis Filter Bank
Available for free at Connexions <http://cnx.org/content/col10713/1.1>
371
2.8.3.5.3 Building the Model
Select Tools -> Real-Time Workshop -> Build Model.
Figure 2.252: Building the Model
2.8.3.5.4 Running the Updated Model
Run the updated model and listen to the eect of using dierent lter types.
2.8.4 Some Things to Try
You may wish to experiment with dierent settings. Here are some suggestions.
2.8.4.1 Change the Wavelet Types
Inside the Dyadic Analysis Filter Bank are dierent wavelet types. Which are suitable for wavelet denoising
and which are not? Note: you will also have to alter the values used in the Dyadic Synthesis Filter Bank.
Available for free at Connexions <http://cnx.org/content/col10713/1.1>
372
CHAPTER 2.
SIGNAL PROCESSING AND COMMUNICATION
Figure 2.253: Available Wavelet Types
Available for free at Connexions <http://cnx.org/content/col10713/1.1>
373
2.8.4.2 Change the Delay Alignment Times
Experiment with the delay alignment times. Try higher and lower values.
What is the eect of completely removing the Delay Alignment block?
2.8.4.3 Change the Noise Reduction Thresholds
In the Soft Threshold block, change the values. The existing vector of [3, 2, 1, 0] reduces high frequency
noise, but does not aect low frequencies.
2.8.4.4 Create Your Own Subsystem
Add your own subsystem block controlled by the DIP switches and add your own wavelet denoising algorithm.
Choose your own wavelet, number of channels, sampling frequency and thresholds.
Available for free at Connexions <http://cnx.org/content/col10713/1.1>
374
CHAPTER 2.
SIGNAL PROCESSING AND COMMUNICATION
Available for free at Connexions <http://cnx.org/content/col10713/1.1>
Chapter 3
Video and Imaging
3.1 A Framework for Image Processing with the DSK64161
3.1.1 Introduction
This module describes general procedures for reading and writing stills images.
The scripts and models
created in this chapter will be the basis for image processing algorithms simulation and implementation
using the DSK6416.
3.1.1.1 Related Files
•
•
•
•
2
Simulink Model for Simulation - stills_sim.mdl
3
Input Image - TMW2.jpg
MATLAB script for Real-Time - Picture_script.m
4
5
Simulink Model for Real-Time - stills_R_W.mdl
3.1.2 Activating CCS under Simulink
®
This section will show you how to activate CCS under the Simulink.
1. Create a new Simulink model.
2. Open the Simulink library browser and add the "C6416DSK" from the "Target Preferences" group of
the "Embedded Target for the TI TMS320C6000 DSP" Blockset (Please refer to Figure 1).
1 This content is available online at <http://cnx.org/content/m23996/1.1/>.
2 See the le at <http://cnx.org/content/m23996/latest/stills_sim.mdl>
3 See the le at <http://cnx.org/content/m23996/latest/TMW2.jpg>
4 See the le at <http://cnx.org/content/m23996/latest/Picture_script.m>
5 See the le at <http://cnx.org/content/m23996/latest/stills_R_W.mdl>
Available for free at Connexions <http://cnx.org/content/col10713/1.1>
375
376
CHAPTER 3.
VIDEO AND IMAGING
Figure 3.1: The C6416DSK Block
3. Set the model to Generate a CCS Project in the Simulation->Conguration Parameters -> Build
Action, as shown in the following picture:
Available for free at Connexions <http://cnx.org/content/col10713/1.1>
377
Figure 3.2: Conguration Parameters for CCS
We now need to create Simulink dedicated blocks to execute CCS commands. The rst is the Build.
®
We can do this in many ways: clicking Build icon, pressing Ctrl-B or in MATLAB
typing make_rtw.
Given this command is available in MATLAB, we will create a custom block with this command.
•
•
•
·
·
·
Give it a name. In our example we use Generate Code & Create Project
Choose the shadow, colour etc. . .
Right click on the Subsystem, choose Block Properties. Go to the Callbacks tab, and under
OpenFcn enter: make_rtw;, as shown in the following picture:
Available for free at Connexions <http://cnx.org/content/col10713/1.1>
378
CHAPTER 3.
VIDEO AND IMAGING
Figure 3.3: Creating the Generate Code & Create Project Simulink block
•
Repeat this process for the following commands as follows:
Available for free at Connexions <http://cnx.org/content/col10713/1.1>
379
Block Name
CCS Command
OpenFcn
Build
Build in CCS:
CCS_Obj.build;
Load Program in CCS:
CCS_Obj.load([pwd,'\',bdroot,'_c6000_rtw\',
Load
bdroot, '.out']);
Run
Run on target:
CCS_Obj.run;
Halt
Halt on target:
CCS_Obj.halt;
Reset
Reset target:
CCS_Obj.reset;
Close Active Project
close(CCS_Obj,[],'project')
Close Active Project
Table 3.1
Your model should look as follows:
Figure 3.4: Simulink Blocks for CCS commands
3.1.3 Image (Stills) I/O
3.1.3.1 Simulation
Figure 5 shows the data ow for the edge detection simulation. The Edge detection model reads the source
picture from a le in the PC, and displays both the original and the processed images.
Available for free at Connexions <http://cnx.org/content/col10713/1.1>
380
CHAPTER 3.
VIDEO AND IMAGING
Figure 3.5: Simulation Environment
3.1.3.1.1 Reading and Displaying a Picture
1. Start by creating a new model in Simulink
2. Open the Simulink library browser and add the "Image from File" from the "Sources" group of the
Video and Image Processing Blockset (Please refer to Figure 6). This block reads an image and converts
it to the RGB format in Simulink .
Available for free at Connexions <http://cnx.org/content/col10713/1.1>
381
Figure 3.6: The "ImageFrom File" Simulink Block
3. Double Click and select the TMW2.jpg
6 See
6
image (Please refer to Figure 7).
the le at <http://cnx.org/content/m23996/latest/TMW2.jpg>
Available for free at Connexions <http://cnx.org/content/col10713/1.1>
382
CHAPTER 3.
VIDEO AND IMAGING
Figure 3.7: The Source Block Conguration
4. In order to display the picture the "Video Viewer" from the "Sinks" group of the Video and Image
Processing Blockset (Please refer to Figure 8). This block displays an input RGB or intensity video
stream or image. The edge detection block operates on intensity images.
Available for free at Connexions <http://cnx.org/content/col10713/1.1>
383
Figure 3.8: The Video Viewer Block
5. Select the "intensity" input format as shown in Figure 9.
Available for free at Connexions <http://cnx.org/content/col10713/1.1>
384
CHAPTER 3.
VIDEO AND IMAGING
Figure 3.9: Video Viewer Conguration
6. The conversion from RGB to intensity will be executed in the Color Space Conversion:
from the
"Conversions" group of the Video and Image Processing Blockset (Please refer to Figure 10).
Available for free at Connexions <http://cnx.org/content/col10713/1.1>
385
Figure 3.10: The Color Conversion Block
7. Double Click and select the "R'G'B' to intensity" conversion scheme as shown in Figure 11.
Available for free at Connexions <http://cnx.org/content/col10713/1.1>
386
CHAPTER 3.
VIDEO AND IMAGING
Figure 3.11: Conguring the Color Conversion Scheme
8. Connect the three blocks as shown in Figure 12.
Figure 3.12: Reading and Displaying a Picture
9. Run the model, you should get the image shown in Figure 13
Available for free at Connexions <http://cnx.org/content/col10713/1.1>
387
Figure 3.13: The Video Viewer Display
3.1.3.2 Real-Time
shows the data ow for the real time implementation of the image processing algorithms. The algorithms
will be implemented using the DSK6416. A MATLAB will run simultaneously in the PC. This script will
read the source picture from a le in the PC, convert it to grayscale and send it to the DSK6416 through
an RTDX channel. The processed picture will be sent from the DSK6416 through a second RTDX channel.
The script will display three images:
•
•
•
The original color picture
The grayscale picture
The processed image
Available for free at Connexions <http://cnx.org/content/col10713/1.1>
388
CHAPTER 3.
VIDEO AND IMAGING
Figure 3.14: Real Time Implementation Environment
3.1.3.2.1 CCS Code Generation
Use the model created in chapter 2.
1. Add the "From RTDX" from the "RTDX Instrumentation" group of the "Embedded Target for the TI
TMS320C6000 DSP" Blockset (Please refer to Figure 15). This block will be used receive data from
the PC using a specied RTDX.
Available for free at Connexions <http://cnx.org/content/col10713/1.1>
389
Figure 3.15: The "From RTDX" Block
2. Congure the block to receive data from a channel named "inputimage" as shown in Figure 16
7
. For
8
the test we will send in an image over RTDX . The selection of `Blocking Mode' will cause the code
running on the DSP to wait until the RTDX transfer is complete before executing. This will give the
MATLAB script full control over the execution.
7 If
you are using the XDS560 or the Blackhawk USB560, you will need to enable High Speed RTDX in the "C61416DSK"
block.
8 The
"Output Dimensions" should contain the Frame size
Available for free at Connexions <http://cnx.org/content/col10713/1.1>
390
CHAPTER 3.
VIDEO AND IMAGING
Figure 3.16: Conguring the Input Channel
3. Add the "To RTDX" from the "RTDX Instrumentation" group of the "Embedded Target for the TI
TMS320C6000 DSP" Blockset (Please refer to Figure 15). This block will be used to send the processed
image to the PC using a specied RTDX.
Available for free at Connexions <http://cnx.org/content/col10713/1.1>
391
Figure 3.17: The "To RTDX" Block
Congure the block to send data through a channel named "outputimage" as shown in Figure 9.
Figure 3.18: Conguring the Output Channel
Available for free at Connexions <http://cnx.org/content/col10713/1.1>
392
CHAPTER 3.
VIDEO AND IMAGING
4. The RTDX channel transfers data in the uint8 format. Therefore the output of the Edge Detection
Block should be converted to this format. Add the "Convert Image" block from from the "Conversions"
group of the Video and Image Processing Blockset, (Please refer to Figure 19). The block should be
congured as shown in Figure 20.
Figure 3.19: The Image Conversion Block
Available for free at Connexions <http://cnx.org/content/col10713/1.1>
393
Figure 3.20: The Image Conversion Conguration
5. Save your model (We used the name stills_R_W.mdl). Your model should look as shown in Figure
21.
Available for free at Connexions <http://cnx.org/content/col10713/1.1>
394
CHAPTER 3.
VIDEO AND IMAGING
Figure 3.21: Reading and Displaying a Picture
9
6. Now you can generate the code to your DSK by using Ctrl-B . When the model builds, it creates an
object in the MATLAB workspace which represents CCS, by default called CCS_Obj.
This object
will be used to interact with the application on the DSP from MATLAB.
7. Build the project. Double-click the Build Project block.
8. Load the project. Double-click the Load Project block.
9. Run the target. Double-click the Run block. It should now be running, as displayed in CCS:
9 If
you do so, the build will fail at compilation in CCS due to an ISRAM space issue.
In this case, we can x this by
redening the location for .far as SDRAM rather than ISRAM (the default) in the board properties box. Rebuild, and it should
compile ne.
Available for free at Connexions <http://cnx.org/content/col10713/1.1>
395
This media object is a downloadable le. Please view or download it at
<g22.JPG>
Figure 3.22: CCS Compilation Display
3.1.3.2.2 The MATLAB Script
The purpose of the MATLAB code we want is to dene an interface with the RTDX channels, to control the
execution of the application on the processor, to send/retrieve data from the processor and to display it. An
example script, picture_script.m will do this. The steps are also detailed below:
1. With the application running, we can congure the RTDX channels in CCS.
%% Configure RTDX channels
% Identify RTDX channel names/modes
chan_struct(1).name = 'inputimage';
chan_struct(1).mode = 'w';
chan_struct(2).name = 'outputimage';
chan_struct(2).mode = 'r';
% Identify RTDX host buffer parameters
RTDX_config_struct.Buffsize = 32768;
RTDX_config_struct.Nbuffers = 4;
RTDX_config_struct.Mode = 'continuous';
% Set up RTDX
r = setupRTDX(CCS_Obj, chan_struct, RTDX_config_struct);
This This sets up a writeable RTDX channel to inputimage and a readable RTDX channel to outputimage. The names used are those in the blocks in the Simulink model.
2. Once running, we enable the RTDX channels for use, and get some data to send to the DSP in this
case a grayscale image taken from a le.
%% Enable RTDX
r.enable('all');
%% Import an image from file to send to the DSP
Y = imread('TMW2.jpg');
I = rgb2gray(Y);
3. We then send this to the DSP:
%% Send test frame to target via RTDX
r.writemsg('inputimage', I);
On receipt of this message, the DSP will process the data and send it back over the return RTDX
channel, and then wait for further input.
4. We can read the processed data back:
%% Read processed test frame from DSP
O = r.readmsg('outputimage', 'uint8', size(I));
5. This script is saved under Picture_script.m
Available for free at Connexions <http://cnx.org/content/col10713/1.1>
396
CHAPTER 3.
VIDEO AND IMAGING
6. Run the script and you will see:
(a) The Original Color Picture
(b) The Correspondent Grayscale Picture
(c) The Received Image (Loopback)
Figure 3.23: Image Processing Display
Available for free at Connexions <http://cnx.org/content/col10713/1.1>
397
3.2 A Framework for Video Processing with the DM6437 DVDP10
3.2.1 Introduction
This chapter describes general procedures for reading and writing video streamss. The scripts and models
created in this chapter will be the basis for the other video processing chapters.
3.2.1.1 Hardware and Software Requirements
This laboratory was originally developed using the following hardware and software:
•
•
•
•
® R2008a
MATLAB
Code Composer Studio (CCS) v3.3
Texas Instruments DM6437 Digital Video Development Platform (DVDP) .
Video camera and screen.
3.2.1.2 Related Files
•
•
•
•
•
11
Simulink Model for Simulation - Video_sim.mdl
12
Input Video File - vipmem_Y.avi
Simulink Model for Real-Time Video Processing with a Camera- Video_R_W.mdl
MATLAB script for Real-Time TCP/IP Interface - RW_tcpip_script.m
Simulink
Model
for
RW_dm6437_tcpip.mdl
•
Real-Time
Video
Processing
through
13
14
the
TCP/IP
Interface
-
15
Simulink Model for PC Control of Real-Time Video Processing through the TCP/IP Interface 16
RW_pcl_tcpip.mdl
3.2.2 Simulation
®.
Start by creating a new model in Simulink
1. Open the Simulink library browser and add the "From Multimedia File" from the "Sources" group of
the Video and Image Processing Blockset (Please refer to Figure 1).
10 This content is available online at <http://cnx.org/content/m23999/1.1/>.
11 See the le at <http://cnx.org/content/m23999/latest/Video_sim.mdl>
12 See the le at <http://cnx.org/content/m23999/latest/vipmem_Y.avi>
13 See the le at <http://cnx.org/content/m23999/latest/Video_R_W.mdl>
14 See the le at <http://cnx.org/content/m23999/latest/RW_tcpip_script.m>
15 See the le at <http://cnx.org/content/m23999/latest/RW_dm6437_tcpip.mdl>
16 See the le at <http://cnx.org/content/m23999/latest/RW_pcl_tcpip.mdl>
Available for free at Connexions <http://cnx.org/content/col10713/1.1>
398
CHAPTER 3.
VIDEO AND IMAGING
Figure 3.24: The "From Multimedia File" Simulink Block
2. Double Click and select the vipmem_Y.avi
17 See
17
input le(Please refer to Figure 2).
the le at <http://cnx.org/content/m23999/latest/vipmem_Y.avi>
Available for free at Connexions <http://cnx.org/content/col10713/1.1>
399
Figure 3.25: Source Block Conguration
3. In order to display the picture the "Video Viewer" from the "Sinks" group of the Video and Image
Processing Blockset will be used.
Available for free at Connexions <http://cnx.org/content/col10713/1.1>
400
CHAPTER 3.
VIDEO AND IMAGING
Figure 3.26: The "To Video Display" Block
Figure 3.27: Conguring the Video Viewer
Available for free at Connexions <http://cnx.org/content/col10713/1.1>
401
4. Connect the three blocks as shown in Figure 5.
Figure 3.28: Displaying a Video-Clip
5. Run the model, you should see the video clip. A single frame is shown mage shown in Figure 6.
Figure 3.29: The Video Display
6. Save your model (We used the name Video_sim.mdl", that you may nd it here
3.2.3 Real-Time Processing with the DM6437 DVDP
3.2.3.1 Using a Camera and a Display
The procedure for capture/display video using the DM6437 is shown in Figure 7.
18 See
the le at <http://cnx.org/content/m23999/latest/Video_sim.mdl>
Available for free at Connexions <http://cnx.org/content/col10713/1.1>
18
).
402
CHAPTER 3.
VIDEO AND IMAGING
Figure 3.30: Using the Video I/O of the DM6437 board
3.2.3.1.1 CCS Code Generation
This procedure is similar to the one developed for stills pictures.
Video will be capture/display using a
camera and a monitor. Image acquisition and Processing will run in a DSP/BIOS task.
1. Open the stills_R_W.mdl
2. Delete the From RTDX and To RTDX blocks
3. Add the "Task" block from the "DSP/BIOS library" group of the "Target Support Package TC6"
Blockset.
4. Add the Function- Call Subsystem from the Ports & Subsystems" group of the "Simulink" Blockset
(Please refer to Figure 8).
Available for free at Connexions <http://cnx.org/content/col10713/1.1>
403
Figure 3.31: The "Function-Call Subsystem" Block
5. Rename Function- Call Subsystem to Video Processing and connect it to the Task block.
19
6. Save the model as Video_R_W.mdl. Your model should look as follows
19 You
:
may add a title to the model, as done here ( Video Processing Template)
Available for free at Connexions <http://cnx.org/content/col10713/1.1>
404
CHAPTER 3.
VIDEO AND IMAGING
Figure 3.32: The Video Processing Model Template
7. Double-click the Task block and make the same changes as shown in Figure 34.
Available for free at Connexions <http://cnx.org/content/col10713/1.1>
405
Figure 3.33: Conguring a "Task"
8. Double-click the Video Processing block. A new window will be opened.
9. In the new window, add the "Video Capture" and "Video Display" from the "DM6437 EVM Board
Support" group of the ""Target Support Package TC6" Blockset as shown in Figure 11.
Available for free at Connexions <http://cnx.org/content/col10713/1.1>
406
CHAPTER 3.
VIDEO AND IMAGING
Figure 3.34: The "Video Capture" block
10. Double-click the Video Capture block and change the Sample Time (and the Video capture mode
only if you are using the components in the PAL mode) as shown in Figure 12.
Available for free at Connexions <http://cnx.org/content/col10713/1.1>
407
Figure 3.35: Video Capture Conguration
11. Double-click the Video Display block and change the Video capture mode only if you are using the
components in the PAL
20
mode as shown in Figure 13.
Figure 3.36: Video Display Conguration
20 If
the camera video capture mode is NTSC you should choose this option
Available for free at Connexions <http://cnx.org/content/col10713/1.1>
408
CHAPTER 3.
VIDEO AND IMAGING
12. Connect the blocks as shown in Figure 14.
Figure 3.37: Capturing and Displaying Video
13. Generate code & create project. Double-click the " Generate code &.." block.
14. Build the project. Double-click the Build Project block.
15. Load the project. Double-click the Load Project block.
21
16. Run the target. Double-click the Run block. This model can be found here
.
3.2.3.2 Using the TCP/IP Interface
This section will describe a Simulink model used to generate code for capturing and displaying video frames
from/to the PC target using the TCP/IP protocol
22
.
21 See the le at <http://cnx.org/content/m23999/latest/Video_R_W.mdl>
22 You should allocate an IP address to the DM6437 DVDP, as described in the
board documentation.
Available for free at Connexions <http://cnx.org/content/col10713/1.1>
409
Figure 3.38: Capturing and Displaying Video Using the TCP/IP port
1. Create a new Simulink model
2. Open the Simulink library browser and add the "C6437EVM" from the "Target Support Package TC6"
group of the " C6000 Target Preferences" Blockset (Please refer to Figure 16).
Available for free at Connexions <http://cnx.org/content/col10713/1.1>
410
CHAPTER 3.
VIDEO AND IMAGING
Figure 3.39: The "C6437EVM" Block
We now need to create Simulink dedicated block to execute CCS commands.
3. Drag in an empty subsystem into the model (Simulink->Ports & Subsystem-> Subsystem).
4. Delete its contents
5. Format it: Give it a name. In our example we use Bulid / Reload & Run".
6. Right click on the Subsystem, choose Block Properties. Go to the Callbacks tab, and under OpenFcn*
enter: RW_tcpip_script('RW_pcl_tcpip');, as shown in the following picture:
Available for free at Connexions <http://cnx.org/content/col10713/1.1>
411
Figure 3.40: Creating the Bulid / Reload & Run Simulink block
7. Add the "Task" block from the "DSP/BIOS library" group of the "Target Support Package TC6"
Blockset.
8. Add the Function- Call Subsystem from the Ports & Subsystems" group of the "Simulink" Blockset
(Please refer to Figure 18).
Available for free at Connexions <http://cnx.org/content/col10713/1.1>
412
CHAPTER 3.
VIDEO AND IMAGING
Figure 3.41: The "Function-Call Subsystem" Block
9. Rename Function- Call Subsystem to R_W Algorithm and connect it to the Task block.
10. Add the "IP Cong" block from "Target Support Package
— TC6->DM6437 EVM Board Support"
11. Save the model as RW_dm6437_tcpip.mdl. Your model should look as follows:
Available for free at Connexions <http://cnx.org/content/col10713/1.1>
413
Figure 3.42: The " RW_dm6437_tcpip.mdl " Model
12. Double-click the Task block and make the same changes as shown in Figure 20.
Available for free at Connexions <http://cnx.org/content/col10713/1.1>
414
CHAPTER 3.
VIDEO AND IMAGING
Figure 3.43: "Task" Conguration
13. Double-click the IP Cong block and make the same changes as shown in Figure 21.
Available for free at Connexions <http://cnx.org/content/col10713/1.1>
415
Figure 3.44: IP Cong Conguration
14. Double-click the R_W Algorithm block. A new window will be opened.
15. In the new window, add the "TCP/IP Recive", "TCP/IP Send", "Byte Unpack" and "Byte Pack"
from the "C6000 DSP Communication Libary" group of the ""Target Support Package TC6" Blockset
as shown in Figure 22.
Available for free at Connexions <http://cnx.org/content/col10713/1.1>
416
CHAPTER 3.
VIDEO AND IMAGING
Figure 3.45: The "TCP/IP Receive" and "TCP/IP Send" blocks
16. Connect the blocks as shown in Figure 23.
Available for free at Connexions <http://cnx.org/content/col10713/1.1>
417
Figure 3.46: The R_W Algorithm block
17. Double-click the TCP/IP Receive block and make the same changes as shown in Figure 24.
Available for free at Connexions <http://cnx.org/content/col10713/1.1>
418
CHAPTER 3.
VIDEO AND IMAGING
(a)
(b)
Figure 3.47: "TCP/IP Receive" Conguration (a) Main Screen (b) Data Types
.
18. Double-click the TCP/IP Send block and congure it as shown in Figure 25:
Available for free at Connexions <http://cnx.org/content/col10713/1.1>
419
Figure 3.48: "TCP/IP Send" Conguration
19. Double-click the Byte Unpack block and congure it as shown in Figure 26.
Available for free at Connexions <http://cnx.org/content/col10713/1.1>
420
CHAPTER 3.
VIDEO AND IMAGING
Figure 3.49: " Byte Unpack " Conguration
20. Double-click the Byte pack block and congure it as shown in Figure 27.
Figure 3.50: " Byte Pack " Conguration
21. Open a new m-le, copy the following code and save it as "RW_tcpip_script.m" at the same directory
Available for free at Connexions <http://cnx.org/content/col10713/1.1>
421
as the model.
22. Create another new Simulink model.
Add the "Byte Pack" from the "C6000 DSP Communication
Libary" group of the ""Target Support Package TC6" Blockset as shown before and the "TCP/IP
Receive", "TCP/IP Send" from the "Instrument Control Toolbox" blockset.
23. Congure the " TCP/IP Receive " and " TCP/IP Send " blocks :
(a)
(b)
Figure 3.51:
"TCP/IP Receive" "TCP/IP Send" Blocks Conguration (a) "TCP/IP Receive" (b)
TCP/IP Send
24. Add the "To Video Display" from the "DM6437 EVM Board Support" group of the ""Target Support
Package TC6" Blockset , also add the "From Multimedia File" from " Signal Processing Sources" group
of the "Signal Processing blockset".
25. Congure the " From Multimedia File " block
Available for free at Connexions <http://cnx.org/content/col10713/1.1>
422
CHAPTER 3.
VIDEO AND IMAGING
(a)
(b)
Figure 3.52: "From Multimedia File" Conguration (a) "TCP/IP Receive" (b) TCP/IP Send
26. Add the Subsystem from the Ports & Subsystems" group of the "Simulink" Blockset as shown before.
27. Rename Function- Call Subsystem to Display.Double-click the Display block. A new window will
be opened. In the new window, add the "Byte Unpack" and " To Video Display " as shown before,
add the "Reshape" from the "Math Operations" grope of the "Simulink" blockset. (Congurations are
the same as before).
28. Connect the blocks as follows:
Available for free at Connexions <http://cnx.org/content/col10713/1.1>
423
Figure 3.53: The "Display" block
29. Your model should look as follows:
30. Save it as RW_pcl_tcpip.mdl.
31. Build load and run the project. Double-click the "Build / Reload & Run" block.
32. Running the script, you will see the video captured and displayed. A single frame is shown in Figure
32.
(a)
(b)
Figure 3.54: Capturing and Displaying Video Using TCP/IP (a) The Captured Video (b) The Displayed
Video
Available for free at Connexions <http://cnx.org/content/col10713/1.1>
424
CHAPTER 3.
23
33. This model can be found here
VIDEO AND IMAGING
.
3.3 Finding Shapes in Images24
3.3.1 Introduction
In this section, you will use the Hough Transform, Find Local Maxima, and Hough Lines blocks to nd the
longest line in an image. In the second step, the algorithm used for line detection will be the basis of a lane
detection procedure.
3.3.1.1 Hardware and Software Requirements
This laboratory was originally developed using the following hardware and software:
•
•
•
® R2008a
MATLAB
Code Composer Studio (CCS) v3.3
Texas Instruments DM6437 hardware.
3.3.1.2 Related Files
•
•
•
•
•
•
•
•
•
•
•
Powerpoint Presentation - Shape Detection.ppt
25
26
Simulink Model for Line Detection Simulation - LineDetection.mdl
27
Simulink Model for Lane Detection Simulation - LaneDetection.mdl
28
Source Image for Line - circuit.tif
29
Video-clip for Lane Detection - viplane.avi
MATLAB script for Line Detection - linedetection_script.m
30
31
Simulink Model for Real-Time Line Detection - LineDetectionDSK6416.mdl
32
Simulink Model for Real-Time Lane Detection - LaneDetection.mdl
33
MATLAB script for Lane Detection - lane_tcpip_script.m
34
Simulink Model for Real-Time Lane Detection (DM6437) - lane_dm6437_tcpip.mdl
35
Simulink Model for Real-Time Lane Detection (PC) - lane_pcl_tcpip.mdl
3.3.2 Line Detection
In this session we will show how to create the line detection model , and how it can be integrated in Simulation
and Real-Time Implementations.
23 See the le at <http://cnx.org/content/m23999/latest/RW_pcl_tcpip.mdl>
24 This content is available online at <http://cnx.org/content/m24404/1.2/>.
25 See the le at <http://cnx.org/content/m24404/latest/Shape Detection.ppt>
26 See the le at <http://cnx.org/content/m24404/latest/LineDetection.mdl>
27 See the le at <http://cnx.org/content/m24404/latest/LaneDetection.mdl>
28 See the le at <http://cnx.org/content/m24404/latest/circuit.tif>
29 See the le at <http://cnx.org/content/m24404/latest/viplane.avi>
30 See the le at <http://cnx.org/content/m24404/latest/linedetection_script.m>
31 See the le at <http://cnx.org/content/m24404/latest/LineDetectionDSK6416.mdl.mdl>
32 See the le at <http://cnx.org/content/m24404/latest/LaneDetection.mdl>
33 See the le at <http://cnx.org/content/m24404/latest/lane_tcpip_script.m>
34 See the le at <http://cnx.org/content/m24404/latest/lane_dm6437_tcpip.mdl>
35 See the le at <http://cnx.org/content/m24404/latest/lane_pcl_tcpip.mdl>
Available for free at Connexions <http://cnx.org/content/col10713/1.1>
425
Figure 3.55: The Line Detection Process
3.3.2.1 Simulation
Open the stills_R_W.mdl
the DSK6416
37
36
Simulink model (generated in the "A Framework for Image Processing with
" module).
Add to it the blocks shown in the following table:
36 http://cnx.org/Members/jfaing/m23996/stills_sim.mdl
37 http://cnx.org/content/m23996/latest/
Available for free at Connexions <http://cnx.org/content/col10713/1.1>
426
CHAPTER 3.
VIDEO AND IMAGING
Block
Library
Quantity
Edge Detection
Video and Image Processing Blockset / Analysis & Enhancement
1
Hough Transform
Video and Image Processing Blockset / Transforms
1
Find Local Maxima
Video and Image Processing Blockset / Statistics
1
Selector
Simulink
Variable Selector
Signal Processing Blockset / Signal Management / Indexing
2
Terminator
Simulink / Sinks
1
Hough Lines
Video and Image Processing Blockset / Transforms
1
Draw Shapes
Video and Image Processing Blockset / Text & Graphics
1
®/ Signal Routing
2
Table 3.2
You are now ready to set your block parameters.
Use the Image From Workspace block to import your image from the MATLAB workspace.
Set the block parameters as follows:
•
•
Main pane, Value = I
Main pane, Output port labels = I
Use the Edge Detection block to nd the edges in the intensity image. This process improves the eciency
of the Hough Lines block as it reduces the image area over which the block searches for lines. The block also
converts the image to a binary image, which is the required input for the Hough Transform block. Use the
default parameters.
Use the Video Viewer block to display the edges found by the Edge Detection block. Set the Input image
type parameter to Intensity.
Use the Hough Transform block to compute the Hough matrix by transforming the input image into
the rho-theta parameter space. The block also outputs the rho and theta values associated with the Hough
matrix. Set the block parameters as follows:
•
•
Theta resolution (radians) = pi/360
Select the Output theta and rho values check box.
Available for free at Connexions <http://cnx.org/content/col10713/1.1>
427
Figure 3.56
Use the Find Local Maxima block to nd the location of the maximum value in the Hough matrix. Set the
block parameters as follows:
•
•
Maximum number of local maxima (N) = 1
Select the Input is Hough matrix spanning full theta range check box.
Available for free at Connexions <http://cnx.org/content/col10713/1.1>
428
CHAPTER 3.
VIDEO AND IMAGING
Figure 3.57
Use the Selector blocks to separate the indices of the rho and theta values, which are output at the Idx port,
that are associated with the maximum value in the Hough matrix.
Set the Selector block parameters as
follows:
•
•
•
Index mode = Zero-based
Elements (-1 for all elements) = 0
Input port width = 2
Set the Selector1 block parameters as follows:
•
•
•
Index mode = Zero-based
Elements (-1 for all elements) = 1
Input port width = 2
Use the Variable Selector blocks to index into the rho and theta vectors and determine the rho and theta
values that correspond to the longest line in the original image. Set the parameters of the Variable Selector
blocks as follows:
Available for free at Connexions <http://cnx.org/content/col10713/1.1>
429
•
•
Select = Columns
Index mode = Zero-based
Use the Hough Lines block to determine where the longest line intersects the edges of the original image.
You use these coordinates to superimpose a white line on the original image. Use the default parameters.
Use the Draw Shapes block to draw a white line over the longest line on the original image. Set the block
parameters as follows:
•
•
•
Input image type = Intensity
Shape = Lines
Border intensity = White
Use the Video Viewer block to display the original image with a white line superimposed over the longest
line in the image. Set the Input image type parameter to Intensity.
38
Connect the blocks as shown in the gure below. Use the le circuit.tif
as input.
Figure 3.58
Create a Subsystem for the Hough algorithm. Select the blocks as shown in the following picture:
38 See
the le at <http://cnx.org/content/m24404/latest/circuit.tif>
Available for free at Connexions <http://cnx.org/content/col10713/1.1>
430
CHAPTER 3.
VIDEO AND IMAGING
Figure 3.59
In the main menu, click on Edit/Create Subsystem (you may also enter Ctrl+G), as follows:
Available for free at Connexions <http://cnx.org/content/col10713/1.1>
431
Figure 3.60
Your model should resemble the following gure:
Available for free at Connexions <http://cnx.org/content/col10713/1.1>
432
CHAPTER 3.
VIDEO AND IMAGING
Figure 3.61
Double-click the "Hough Algorithm", and you should see:
Available for free at Connexions <http://cnx.org/content/col10713/1.1>
433
Figure 3.62
Create a Subsystem for the Line Drawing and Image Construction. Select the blocks as shown in the
following picture:
Available for free at Connexions <http://cnx.org/content/col10713/1.1>
434
CHAPTER 3.
VIDEO AND IMAGING
Figure 3.63
In the main menu, click on Edit/Create Subsystem (you may also enter Ctrl+G),
Your model should resemble the following gure:
Figure 3.64
Available for free at Connexions <http://cnx.org/content/col10713/1.1>
435
Double-click the " Line Drawing and Image Construction ", and you should see:
Figure 3.65
Create a Subsystem for the Line Detection. Select the blocks as shown in the following picture:
Available for free at Connexions <http://cnx.org/content/col10713/1.1>
436
CHAPTER 3.
VIDEO AND IMAGING
Figure 3.66
The model should look as follows:
Figure 3.67
Available for free at Connexions <http://cnx.org/content/col10713/1.1>
437
Save the le as "LineDetection.mdl"
Set the conguration parameters. Open the Conguration dialog box by selecting Conguration Parameters from the Simulation menu. Set the parameters as follows:
•
•
•
Solver pane, Stop time = 0
Solver pane, Type = Fixed-step
Solver pane, Solver = discrete (no continuous states)
Run your model.
The Video Viewer window displays the edges found in the original image in white and the background
in black. To view the image at its true size, right-click the window and select Set Display To True Size.
Running this gives you the images in Figure 1.
Figure 3.68: Line Detection
The Video Viewer1 window displays the original image with a white line drawn over the longest line in
the image.
You may repeat the simulation here to experiment the various algorithms with dierent thresholds.
3.3.2.2 Real Time Implementation
Open the stills_R_W.mdl
the DSK6416
40
39
Simulink model (generated in the "A Framework for Image Processing with
" module).
Copy the "Line Detection" block from "LineDetection.mdl".
Connect the various blocks as shown in . Save the model (LineDetectionPictureDSK6416.mdl).
39 http://cnx.org/Members/jfaing/m23996/stills_sim.mdl
40 http://cnx.org/content/m23996/latest/
Available for free at Connexions <http://cnx.org/content/col10713/1.1>
438
CHAPTER 3.
VIDEO AND IMAGING
Figure 3.69: The Edge Detection Real Time Implementation Model for Stills Images
Build the project. Double-click the Build Project block.
Load the project. Double-click the Load Project block.
Run the target. Double-click the Run block.
Plotting the input and output in MATLAB, you will see :
Available for free at Connexions <http://cnx.org/content/col10713/1.1>
439
Figure 3.70: Edge Detection using the DSK6416
3.3.3 Lane Detection
In this session we will show how to create the lane detection model, as an extension of the Line Detection
Model, introduced in the previous chapter.
Available for free at Connexions <http://cnx.org/content/col10713/1.1>
440
CHAPTER 3.
VIDEO AND IMAGING
Figure 3.71: The Lane Detection Process
3.3.3.1 Simulation
41
Open the video_sim.mdl
the DM6437 DVDP
42
Simulink model (generated in the "A Framework for Video Processing with
" module). Copy the line Detection block in this model into the video_sim.mdl,
and connect it to the I/O blocks as follows:
41 http://cnx.org/Members/jfaing/m23999/video_sim.mdl
42 http://cnx.org/content/m23999/latest/
Available for free at Connexions <http://cnx.org/content/col10713/1.1>
441
Figure 3.72
Double-Click the Line Detection block. In the open window, add the Submatrix block from the Signal
Processing Toolbox (EIhter from the Math Functions / Matrices and Linear Algebra / Matrix Operations
group or from the Signal Management / Indexing group. Connect it between the input node and the Edge
Detection Block as follows:
Available for free at Connexions <http://cnx.org/content/col10713/1.1>
442
CHAPTER 3.
VIDEO AND IMAGING
Figure 3.73
Congure the Submatrix block as follows:
Figure 3.74
Available for free at Connexions <http://cnx.org/content/col10713/1.1>
443
This will dene the Region of Interest (ROI). Rename the block to Dene ROI
Select the Edge Detection Block, and create a Subsystem for the Enhanced Detection, as shown in
the following picture:
Figure 3.75
The model should look as follows:
Available for free at Connexions <http://cnx.org/content/col10713/1.1>
444
CHAPTER 3.
VIDEO AND IMAGING
Figure 3.76
Double Click the Enhanced Edge Detection block. Rename the Input port to ROI, and the output
port to Binary Image
Available for free at Connexions <http://cnx.org/content/col10713/1.1>
445
Figure 3.77
Add to it the blocks shown in the following table:
Block
Library
Quantity
2-D Histogram
Video and Image Processing Blockset / Statistics
1
Maximum
Signal Processing Blockset/ Statistics
1
Data Type Conversion
Simulink/ Signal Attributes
1
Bias
Simulink / Math Operations
1
Gain
Simulink / Math Operations
1
Relational Operator
Simulink / Logic and Bit Operations
1
Logical Operator
Simulink / Logic and Bit Operations
1
Table 3.3
Place the blocks so that your model resembles the following gure.
Create the Calculated threshold
based on histogram with the selected blocks.
Available for free at Connexions <http://cnx.org/content/col10713/1.1>
446
CHAPTER 3.
VIDEO AND IMAGING
Figure 3.78
The model should look as shown in the following picture. Create the Histogram based binary thresholding with the selected blocks.
Figure 3.79
Available for free at Connexions <http://cnx.org/content/col10713/1.1>
447
Double-click the Hough Algorithm block in the model. You should change it to select the two longest
lines.
Figure 3.80
You should change the conguration of the selector blocks as follows:
Available for free at Connexions <http://cnx.org/content/col10713/1.1>
448
CHAPTER 3.
VIDEO AND IMAGING
Figure 3.81
Add an Embedded MATLAB function block (from the Simulink/User-Dened Functions group).
Double-Click the block and enter the following MATLAB function:
function [Thetas, Rhos] = fcn( thetas,rhos)
% This block supports an embeddable subset of the MATLAB language.
% See the help menu for details.
%initialise a frame count
persistent count;
if isempty(count)
count = 0;
end
%remember previous outputs
persistent lastRhos;
persistent lastThetas;
%initialise to same as first input for first entry into function
if isempty(lastRhos)
lastRhos = rhos;
end
Available for free at Connexions <http://cnx.org/content/col10713/1.1>
449
if isempty(lastThetas)
lastThetas = thetas;
end
%Assume that all is OK initially
Rhos = rhos;
Thetas = thetas;
if count == 4
%after the 4th frame, engage the test logic
for I = 1:length(rhos)
if (abs(rhos(I) - lastRhos(I)) > 30) || (abs(thetas(I) - lastThetas(I)) > 10*(pi/180))
%too much change - just use the old values
% outR(I) = lastRhos(I);
% outT(I) = lastThetas(I);
Rhos(I) = lastRhos(I);
Thetas(I) = lastThetas(I);
end
end
else
%otherwise just output the computed values
count = count+1;
end
%assign outputs
%Rhos = outR;
%Thetas = outT;
%remember outputs for next time
lastRhos = Rhos;
lastThetas = Thetas;
Connect the block as shown in the following picture:
Available for free at Connexions <http://cnx.org/content/col10713/1.1>
450
CHAPTER 3.
VIDEO AND IMAGING
Figure 3.82
In the main model, double-click the Line Drawing and Image Construction block.
Change the conguration of the Draw Lines block as follows:
Available for free at Connexions <http://cnx.org/content/col10713/1.1>
451
Figure 3.83
Now, it will draw the polygon based on the two longest lines.
Add the following blocks to the subsystem:
Block
Library
Quantity
Concatenate
Simulink /Math Operations
2
Selector
Simulink / Signal Routing
3
Gain
Simulink / Math Operations
1
Relational Operator
Simulink / Logic and Bit Opera-
1
tions
continued on next page
Available for free at Connexions <http://cnx.org/content/col10713/1.1>
452
CHAPTER 3.
Logical Operator
Simulink / Logic and Bit Opera-
VIDEO AND IMAGING
1
tions
Submatrix
Signal Processing Toolbox:Math
1
Functions / Matrices and Linear
Algebra / Matrix Operations or
Signal Management / Indexing
Table 3.4
Connect the blocks as follows:
Figure 3.84
The blocks should be congured as follows:
•
Selector5:
Available for free at Connexions <http://cnx.org/content/col10713/1.1>
453
Figure 3.85
•
Selector4:
Available for free at Connexions <http://cnx.org/content/col10713/1.1>
454
CHAPTER 3.
VIDEO AND IMAGING
Figure 3.86
•
•
Selector3:
•
Vertices Matrix:
Available for free at Connexions <http://cnx.org/content/col10713/1.1>
455
•
Figure 3.87
Draw Lane
Available for free at Connexions <http://cnx.org/content/col10713/1.1>
456
CHAPTER 3.
VIDEO AND IMAGING
Figure 3.88
•
Superposition of Lane and Original Image
Available for free at Connexions <http://cnx.org/content/col10713/1.1>
457
Figure 3.89
•
Extraction
Available for free at Connexions <http://cnx.org/content/col10713/1.1>
458
CHAPTER 3.
VIDEO AND IMAGING
Figure 3.90
Rename the Line Detection to Lane Detection. Save the model as LaneDetection.mdl The model should
look as follows:
Available for free at Connexions <http://cnx.org/content/col10713/1.1>
459
Figure 3.91
Double Click the Lane Detection block. You may rename the blocks' names. It will look as follows:
Available for free at Connexions <http://cnx.org/content/col10713/1.1>
460
CHAPTER 3.
VIDEO AND IMAGING
Figure 3.92
Run your model.
Running this gives you the images in Figure 7.
Figure 3.93: Edge Detection on a Video Stream
Available for free at Connexions <http://cnx.org/content/col10713/1.1>
461
3.3.3.2 Real Time Implementation using TCP/IP
3.3.3.2.1 Procedure
43
Open the RW_dm6437_tcpip.mdl
44
with the DM6437 DVDP
Simulink model (generated in the "A Framework for Video Processing
" module).
Save the model as "lane_dm6437_tcpip.mdl".
Change the name of the R_W Algorithm block to Lane Algorithm.
Figure 3.94: The Real Time Implementation Model for Lane Detection
Right click on the "Build/Reload & Run" subsystem, choose Block Properties. Go to the Callbacks
tab, and under OpenFcn* enter: lane_tcpip_script('lane_pcl_tcpip');, as shown in the following picture:
43 http://cnx.org/Members/jfaing/m23999/RW_dm6437_tcpip.mdl
44 http://cnx.org/content/m23999/latest/
Available for free at Connexions <http://cnx.org/content/col10713/1.1>
462
CHAPTER 3.
VIDEO AND IMAGING
Figure 3.95
Double-click the Task block and make the same changes as shown:
Available for free at Connexions <http://cnx.org/content/col10713/1.1>
463
Figure 3.96
Double-Click the Lane Algorithm subsystem.
Copy "Lane Detection and Tracking" block from "LaneDetection.mdl" into this model as shown.
Available for free at Connexions <http://cnx.org/content/col10713/1.1>
464
CHAPTER 3.
VIDEO AND IMAGING
Figure 3.97
Congure the "TCP/IP Receive" block :
Available for free at Connexions <http://cnx.org/content/col10713/1.1>
465
Figure 3.98
Available for free at Connexions <http://cnx.org/content/col10713/1.1>
466
CHAPTER 3.
VIDEO AND IMAGING
Figure 3.99
Congure the "TCP/IP Send" block :
Available for free at Connexions <http://cnx.org/content/col10713/1.1>
467
Figure 3.100
Congure the "Byte Unpack" block :
Available for free at Connexions <http://cnx.org/content/col10713/1.1>
468
CHAPTER 3.
VIDEO AND IMAGING
Figure 3.101
Congure the "Byte Pack" block :
Available for free at Connexions <http://cnx.org/content/col10713/1.1>
469
Figure 3.102
Open the "RW_pcl_tcpip.mdl" model, created in the "Video R_W" directory.
Save the model as "lane_pcl_tcpip.mdl".
Available for free at Connexions <http://cnx.org/content/col10713/1.1>
470
CHAPTER 3.
VIDEO AND IMAGING
Figure 3.103
Double-click the Video Source block and make the same changes as shown:
Available for free at Connexions <http://cnx.org/content/col10713/1.1>
471
Figure 3.104
Congure the "TCP/IP Receive" block :
Available for free at Connexions <http://cnx.org/content/col10713/1.1>
472
CHAPTER 3.
VIDEO AND IMAGING
Figure 3.105
Double-click the Display block, Double-click the Data Unpack block and Congure the "Byte Unpack"
block as shown:
Available for free at Connexions <http://cnx.org/content/col10713/1.1>
473
Figure 3.106
function lane_tcpip_script(hostModelName)
% controls host-side TCP/IP processing for
% Video Surveillance demo:
%********** Initialization ********************
% Get model name
modelName = gcs;
% Connect to CCS
CCS_Obj = connectToCCS(modelName);
saved_visibility = CCS_Obj.isvisible;
CCS_Obj.visible(1);
% Load application
loadApp(modelName, CCS_Obj);
% Run application
fprintf('Running application: %s\n', modelName);
CCS_Obj.run;
Available for free at Connexions <http://cnx.org/content/col10713/1.1>
474
CHAPTER 3.
VIDEO AND IMAGING
% Allow some time for DHCP address acquisition
pause(3);
% Retrieve target's host name
boardType = get_param([modelName '/IP Config'], 'boardType');
userPrompt = sprintf('Enter the IP address or the host name of the %s board: ', boardType);
hostName = inputdlg(userPrompt, 'Target IP address');
if isempty(hostName)
errordlg('You have to provide a valid IP address or host name to run the demo.',
...'TCP/IP Surveillance Recording', 'modal');
return;
end
hostName = strtrim(hostName{1});
% Launch host side UDP receive / Video display model
fprintf('Launching host side application: %s\n', hostModelName);
open_system(hostModelName);
% Update host side TCP/IP blocks with target's IP address
set_param([hostModelName '/TCP//IP Send'], 'Host', hostName);
set_param([hostModelName '/TCP//IP Receive'], 'Host', hostName);
fprintf('Click on play button to start running the host side application!\n\n')
%[EOF] tcpip_surveil_script.m
Open a new m-le, copy the following code and save it as "lane_tcpip_script.m" at the same directory as
the model.
3.3.3.3 Running the Real-time Model
Build load and run the project from the "lane_dm6437l_tcpip.mdl" model. Double-click the "Build / Reload
& Run" block.
Running the script, you will see:
Figure 3.107: Real-Time Edge Detection through a TCP/IP Interface
Available for free at Connexions <http://cnx.org/content/col10713/1.1>
475
3.4 Edge Detection45
3.4.1 Introduction
This chapter will describe the use of the Edge Detection Simulink
® Block, both for stills images and video
les.
3.4.1.1 Related Files
•
•
•
•
•
•
•
•
•
•
Powerpoint Presentation Edge Detection.ppt
46
Simulink Model for Image Processing Simulation- EdgeDetectionPicture.mdl
47
MATLAB Script for Real-Time Image Processing - EdgeDetectionPicturescript.m
48
Simulink Model for Real-Time Image Processing - EdgeDetectionPictureDSK6416.mdl
Simulink Model for Video Processing Simulation- EdgeDetectionVideo.mdl
49
50
51
MATLAB Script for Real-Time Video Processing - EdgeDetectionVideoscript.m
52
Simulink Model for Real-Time Video Processing - EdgeDetectionVideoDM6437DVDP.mdl
53
Input Image - TMW2.jpg
54
Input Video File - vipmem_Y.avi
MATLAB Routine for AVI to RGB conversion - avi2rgb.m
55
3.4.2 The Edge Detection Block
The "Edge Detection" block from the "Analysis & Enhancement" group of the Video and Image Processing
Blockset (Please refer to Figure 1).
45 This content is available online at <http://cnx.org/content/m24423/1.2/>.
46 See the le at <http://cnx.org/content/m24423/latest/Edge Detection.ppt>
47 See the le at <http://cnx.org/content/m24423/latest/EdgeDetectionPicture.mdl>
48 See the le at <http://cnx.org/content/m24423/latest/EdgeDetectionPicturescript.m>
49 See the le at <http://cnx.org/content/m24423/latest/EdgeDetectionPictureDSK6416.mdl>
50 See the le at <http://cnx.org/content/m24423/latest/EdgeDetectionVideo.mdl>
51 See the le at <http://cnx.org/content/m24423/latest/EdgeDetectionVideoscript.m>
52 See the le at <http://cnx.org/content/m24423/latest/EdgeDetectionVideoDM6437DVDP.mdl>
53 See the le at <http://cnx.org/content/m24423/latest/TMW2.jpg>
54 See the le at <http://cnx.org/content/m24423/latest/vipmem_Y.avi>
55 See the le at <http://cnx.org/content/m24423/latest/avi2rgb.m>
Available for free at Connexions <http://cnx.org/content/col10713/1.1>
476
CHAPTER 3.
VIDEO AND IMAGING
Figure 3.108: The Edge Detection Block
This block will enable you to simulate the edge detection procedure in the input image using the Sobel,
Prewitt, Roberts, or Canny methods.
If the selected method is Sobel, Prewitt, or Roberts, the Edge Detection block nds the edges in an input
image by approximating the gradient magnitude of the image. The block convolves the input matrix with
the Sobel, Prewitt, or Roberts kernel. The block output can be either the result of this convolution operation
(two gradient components of the image) or a binary image, obtained by comparing the convolution result
against a threshold. If a pixel value is `1', in this binary image it is an edge. Please refer to Figure 2
Available for free at Connexions <http://cnx.org/content/col10713/1.1>
477
Figure 3.109: The Edge Detection Block Conguration Window for Sobel, Prewitt and Roberts Meth-
ods
If the selected method is Canny, the Edge Detection block nds edges by looking for the local maxima of
the gradient of the input image. It calculates the gradient using the derivative of the Gaussian lter. The
Canny method uses two thresholds to detect strong and weak edges. Please refer to Figure 3.
Available for free at Connexions <http://cnx.org/content/col10713/1.1>
478
CHAPTER 3.
VIDEO AND IMAGING
Figure 3.110: The Edge Detection Block Conguration Window for the Canny Method
3.4.3 Image (Stills) Processing
3.4.3.1 Simulation
56
1. Open the stills_R_W.mdl
with the DSK6416
57
Simulink model (generated in the "A Framework for Image Processing
" module).
2. Add the "Edge Detection" block from the "Analysis & Enhancement" group of the Video and Image
Processing Blockset (Please refer to section ).
3. Connect the various blocks as shown in Figure 4. Save your model.
56 http://cnx.org/Members/jfaing/m23996/stills_sim.mdl
57 http://cnx.org/content/m23996/latest/
Available for free at Connexions <http://cnx.org/content/col10713/1.1>
479
Figure 3.111: The Edge Detection Simulation Model for Stills
4. Running this gives you the images shown in Figure 5.
(a) Input Picture
(b) The Processed Picture
Figure 3.112: Edge Detection - Simulation Results
You may repeat the simulation here to experiment the various algorithms with dierent thresholds.
3.4.3.2 Real-Time
58
1. Open the stills_R_W.mdl
with the DSK6416
59
Simulink model (generated in the "A Framework for Image Processing
" module).
2. Add the "Edge Detection" block from from the "Analysis & Enhancement" group of the Video and
Image Processing Blockset, as it was done for the simulation.
3. Connect
the
various
blocks
as
shown
in
Figure
6.
Save
the
model
tureDSK6416.mdl).
58 http://cnx.org/Members/jfaing/m23996/stills_sim.mdl
59 http://cnx.org/content/m23996/latest/
Available for free at Connexions <http://cnx.org/content/col10713/1.1>
(EdgeDetectionPic-
480
CHAPTER 3.
VIDEO AND IMAGING
Figure 3.113: The Edge Detection Real Time Implementation Model
4. Generate code & create project. Double-click the " Generate code &.." block.
5. Build the project. Double-click the Build Project block.
6. Load the project. Double-click the Load Project block.
7. Run the target. Double-click the Run block.
8. Run the le EdgeDetectionPicturescript.m
60
, this should give you the images in gure 7.
60 http://cnx.org/Members/jfaing/module.2008-08-11.5404829390/EdgeDetectionPicturescript.m
Available for free at Connexions <http://cnx.org/content/col10713/1.1>
481
(a) The Original Color Picture
(b) The Original Grayscale Picture
Available for free at Connexions <http://cnx.org/content/col10713/1.1>
(c) The Received Image(After Edge Detection)
Figure 3.114: Edge Detection on the DSK6416
482
CHAPTER 3.
VIDEO AND IMAGING
3.4.4 Video Processing
3.4.4.1 Simulation
1. Open the model video_sim.mdl model
2. Add the "Edge Detection" block from from the "Analysis & Enhancement" group of the Video and
Image Processing Blockset
3. Add a second Video Viewer and connect the various blocks as shown in Figure 8. Save your model
(EdgeDetectionVideoDSK6416.mdl).
Figure 3.115: The Edge Detection Simulation Model for Video
4. Run the model. A single frame of the input and output video is shown in Figure 9.
Available for free at Connexions <http://cnx.org/content/col10713/1.1>
483
(a) Input Video
(b) Processed Video
Figure 3.116: Edge Detection on Video
You may repeat the simulation here to experiment the various algorithms with dierent thresholds.
3.4.4.2 Real-Time
61
1. Connect the camera and the display to the board and open the Video_R_W.mdl
A Framework for Video Processing with the DM6437 DVDP
62
module.).
61 http://cnx.org/content/m23999/latest/Video_R_W.mdl
62 http://cnx.org/content/m23999
Available for free at Connexions <http://cnx.org/content/col10713/1.1>
(placed in the
484
CHAPTER 3.
VIDEO AND IMAGING
Figure 3.117: The Edge Detection Real Time Implementation Model
2. Change the name of the Video Processing block to Edge Detection (Please refer to Figure 10). A
new window will be opened
3. Add the "Edge Detection" block from the "Analysis & Enhancement" group of the Video and Image
Processing Blockset, as it was done for the simulation.
4. Add the "Image Data Type Conversion" block from the " Conversion" group of the Video and Image
Processing Blockset.
5. Set the model in the Simulation->Conguration Parameters, as shown in Figure 11.
6. Generate code & create project. Double-click the " Generate code &.." block
7. Build the project. Double-click the Build Project block.
8. Load the project. Double-click the Load Project block.
9. Run the target. Double-click the Run block. The results will be diaplyed in the screen as shown in
Figure 12.
Available for free at Connexions <http://cnx.org/content/col10713/1.1>
485
Figure 3.118: Conguration Parameters for CCS
Available for free at Connexions <http://cnx.org/content/col10713/1.1>
486
CHAPTER 3.
VIDEO AND IMAGING
Figure 3.119: Edge Detection on Real-time Video
3.5 Video Surveillance63
3.5.1 Introduction
Continuous-scene monitoring applications, such as ATM booths, parking lots or trac monitoring systems,
generate large volumes of data. Recording and archiving such volumes of data is a real problem, and one
way to solve this is to reduce the size of the data stream right at the source.
In addition to traditional methods for compressing individual video images, we could identify and record
only interesting video images, such as those images with signicant amounts of motion in the eld of view.
That could signicantly help reduce the data rates for surveillance-specic applications.
In this section, we'll illustrate the design ow of a motion detection system based video surveillance
system. The system will be able to identify and record only interesting video frames containing motion.
The development process will follow the following three steps:
1. Functional Requirements
2. System modeling and simulation
3. Code generation and implementation
63 This
content is available online at <http://cnx.org/content/m24470/1.1/>.
Available for free at Connexions <http://cnx.org/content/col10713/1.1>
487
3.5.1.1 Hardware and Software Requirements
This laboratory was originally developed using the following hardware and software:
•
•
•
® R2008a
MATLAB
Code Composer Studio (CCS) v3.3
Texas Instruments DM6437 hardware.
3.5.1.2 Related Files
•
•
•
•
•
•
64
Powerpoint Presentation - Surveillance.ppt
65
Simulink Model for Simulation - surveillance.mdl
66
Video-clip viplane.avi
67
MATLAB script my_tcpip_surveil_script.m
Simulink Model for Real-Time (DM6437) - my_dm6437evmsurveil_tcpip.mdl
68
69
Simulink Model for Real-Time Lane Detection (PC) - my_pc_surveil_tcpip.mdl
3.5.2 Video Surveillance
In this session we will show how to create the line detection model, and how it can be integrated in Simulation
and Real-Time Implementations.
64 See
65 See
66 See
67 See
68 See
69 See
the le at <http://cnx.org/content/m24470/latest/Surveillance.ppt>
the le at <http://cnx.org/content/m24470/latest/surveillance.mdl>
the le at <http://cnx.org/content/m24470/latest/viplane.avi>
the le at <http://cnx.org/content/m24470/latest/my_tcpip_surveil_script.m>
the le at <http://cnx.org/content/m24470/latest/my_dm6437evmsurveil_tcpip.mdl>
the le at <http://cnx.org/content/m24470/latest/my_pc_surveil_tcpip.mdl>
Available for free at Connexions <http://cnx.org/content/col10713/1.1>
488
CHAPTER 3.
VIDEO AND IMAGING
Figure 3.120
Figure 1: The Motion Detection Process
3.5.2.1 The Motion Energy Estimation
The Motion Energy estimation is based on the calculation of the Sum of Absolute Dierences (SAD)
according to the following equation:
SAD
=
P P
i
j
| Ik (i, j) − Ik−1 (i, j) |
where:
Ik (i, j)
- Current Frame
Ik−1 (i, j)
- Previous Frame
Table 3.5
3.5.2.2 Functional Description
The Video Surveillance system block diagram is shown in Figure 2. The source video is displayed and played
back through the system. This incoming video stream is processed by a subsystem that estimates the motion
within the scene and captures the interesting video frames. The system can display either the recorded video
frame or the Absolute Dierences (AD) image.
The user can congure the motion energy threshold value and select which image will be displayed
(Display Control). The system outputs include, besides the displayed image, the following features:
•
A graph of the motion energy as a function of time. This graph displays the threshold value as well.
Available for free at Connexions <http://cnx.org/content/col10713/1.1>
489
•
•
The Frame count of the recorded image
An output signal triggered by motion detection (Trigger)
® model simultaneously sends video
—
While the generated code is running on the target, a host side Simulink
frames to the target via TCP/IP protocol using TCP/IP Blocks from Instrument Control Toolbox . The
target receives video frames sent by the host side Simulink model, computes the sum of the absolute value
of dierences (SAD) between successive video frames, and returns an estimate of motion. When the motion
estimate value exceeds a threshold, the target increments a counter and sends the corresponding frame back
to the host.
Figure 3.121: Video Surveillance Block Diagram
3.5.3 Simulation
1. Open a new Simulink model
2. Add the blocks shown in the following table (Please refer also to Figure 3):
Video Surveillance Simulink Blocks
Available for free at Connexions <http://cnx.org/content/col10713/1.1>
490
CHAPTER 3.
VIDEO AND IMAGING
Functionality
Block
Blockset
Quant.
SAD
Subsystem
Simulink / Ports & Sub-
1
systems
Delay
Signal Processing Block-
1
set / Signal Operations
Abs
Simulink / Math Opera-
1
tions
Matrix Sum
Signal Processing Block-
2
set / Math Functions /
Matrices and Linear Algebra / Matrix Operations
Data Type Conversion
Simulink
/
Signal
At-
1
Simulink / Math Opera-
1
tributes
Add Sum,
tions
Recording
Enabled Subsystem
Simulink / Ports & Sub-
1
systems
Add Sum,
Simulink / Math Opera-
1
tions
Delay
Signal Processing Block-
1
set / Signal Operations
counter
Subsystem
Simulink / Ports & Sub-
1
systems
Add Sum,
Simulink / Math Opera-
1
tions
Delay
Signal Processing Block-
1
set / Signal Operations
Generate data for motion en-
Matrix Concatenate
ergy and threshold display
Compare
Motion
against Threshold
Energy
Simulink / Math Opera-
2
tions
Relational Operator
Simulink / Logic and Bit
Operations
continued on next page
Available for free at Connexions <http://cnx.org/content/col10713/1.1>
1
491
Input Video
From Multimedia File
Signal Processing Block-
1
set / Signal Processing
Sources
Display Control
Constant
Signal Processing Block-
1
set / Signal Processing
Sources
Display Motion Energy and
Floating Scope
Simulink/Sinks
Insert Text
Video
1
Threshold
Draws formatted text on an
image or video stream
and
Image
Pro-
1
cessing Blockset / Text &
gure__
Connected to the trigger (not
Terminator
Simulink/Sinks
To Video Display
Video
1
used for simulation)
Images' Display
and
Image
Pro-
cessing Blockset / Sinks
Table 3.6
Figure 3.122: Simulink Blocks for Video Surveillance
Available for free at Connexions <http://cnx.org/content/col10713/1.1>
2
492
CHAPTER 3.
VIDEO AND IMAGING
3.5.3.1 Conguring the SAD blocks
1. Congure one of the Add block for subtraction, you may also change its icon shape to a circular form
as follows
70
:
Figure 3.123
2. Congure its xed point mode of operation Congure one of the Matrix Sum blocks for adding rows:
70 The
symbol | is used to place the + and - perpendicular to each other
Available for free at Connexions <http://cnx.org/content/col10713/1.1>
493
Figure 3.124
3. Congure its xed point mode of operation
Available for free at Connexions <http://cnx.org/content/col10713/1.1>
494
CHAPTER 3.
VIDEO AND IMAGING
Figure 3.125
4. Congure the xed point mode of operation for the second Matrix Column Add block:
Available for free at Connexions <http://cnx.org/content/col10713/1.1>
495
Figure 3.126
3.5.3.2 Conguring the Input blocks
1. Congure on of the Video Source "From Multimedia File" block for reading frames from the "vipmen.avi" le.
Available for free at Connexions <http://cnx.org/content/col10713/1.1>
496
CHAPTER 3.
VIDEO AND IMAGING
Table 3.7
2. Set the initial value of the "Constant" to 1e5.
Figure 3.127
Available for free at Connexions <http://cnx.org/content/col10713/1.1>
497
Figure 3.128
3. Congure "Data Type Conversion" block :
Figure 3.129
Available for free at Connexions <http://cnx.org/content/col10713/1.1>
498
CHAPTER 3.
VIDEO AND IMAGING
4. Congure " Relational Operator " block :
Figure 3.130
5. Congure one of the " Matrix Concatenate " block :
Figure 3.131
6. The Floating Scope will be used to display the motion energy and the threshold
71 The
71
as a function of
threshold is changed upon a user command. The simultaneous display of the threshold and motion energy will enable
Available for free at Connexions <http://cnx.org/content/col10713/1.1>
499
time. Double-Click the block. A cope screen will appear, you should then click the icon as shown in
the following picture:
Figure 3.132
You may keep the default conguration for "Data history".
7. Congure the " Insert Text " block :
the user to follow-up the process of recording frames.
Available for free at Connexions <http://cnx.org/content/col10713/1.1>
500
CHAPTER 3.
VIDEO AND IMAGING
Figure 3.133
8. Double-click on the "Enabled Subsystem" block, and build it as shown below:
Available for free at Connexions <http://cnx.org/content/col10713/1.1>
501
Figure 3.134
9. Double-click on one of the "Subsystem" block and build it as shown below:
Figure 3.135
Save the subsystem as: "Motion Energy"
10. Double-click on one the remaining "Subsystem" block,build it as shown below and name it "Frame
Counter":
Available for free at Connexions <http://cnx.org/content/col10713/1.1>
502
CHAPTER 3.
VIDEO AND IMAGING
Figure 3.136
3.5.3.3 Connecting the blocks:
1. Connect the blocks as shown in the following gure:
Figure 3.137: Video Surveillance model
2. Save the model as "surveillance_sim.mdl".
Available for free at Connexions <http://cnx.org/content/col10713/1.1>
503
3.5.3.4 Running the model
1. Run the model. You should observe the following images:
Current Frame
Recorded Frame
Table 3.8
2. Double click the scope and you will see:
Available for free at Connexions <http://cnx.org/content/col10713/1.1>
504
CHAPTER 3.
VIDEO AND IMAGING
Figure 3.138
In this scope display, yellow represents the motion estimate from each video frame, and magenta is the
threshold level. In the Motion Threshold scope here, we see that we identied ve frames with motion
above the threshold that were captured and recorded.
3.5.4 Real Time Implementation
3.5.4.1 Video Surveillance using TCP/IP
72
1. Open the video_sim.mdl
73
with the DM6437 DVDP
Simulink model (generated in the "A Framework for Video Processing
" module).
2. Rename the model "my_dm6437evmsurveil_tcpip.mdl".
3. Rename the R_W Algorithm subsystem to Surveillance Algorithm.
4. Double-click the Surveillance Algorithm block.
72 http://cnx.org/Members/jfaing/m23999/video_sim.mdl
73 http://cnx.org/content/m23999/latest/
Available for free at Connexions <http://cnx.org/content/col10713/1.1>
505
5. In this block, add a Add the Function- Call Subsystem from the Ports & Subsystems" group of the
"Simulink" Blockset.
6. Rename Function- Call Subsystem to Video Frame Capture Motion Threshold and Double-click it.
7. Open the model "surveillance_sim.mdl", created in section and copy it into Video Frame Capture
Motion Threshold .
8. Add three input ports "In1" from the "Sources" group of the "Simulink" blockset and three output
ports "Out1" from the "Sinks" group of the "Simulink" blockset.
9. Add a "Switch" from the "Signal Routing" group of the "Simulink" blockset and a "Gain" from the
"Math Operation" group of the "Simulink" blockset.
10. Double-click the Motion Energy block and add him another output port as shown:
Figure 3.139
11. Connect the blocks as shown:
Available for free at Connexions <http://cnx.org/content/col10713/1.1>
506
CHAPTER 3.
VIDEO AND IMAGING
Figure 3.140
12. Congure the "Gain" block :
Figure 3.141
Available for free at Connexions <http://cnx.org/content/col10713/1.1>
507
13. Congure the "Switch" block :
Figure 3.142
14. Double-click the Surveillance Algorithm subsystem.
15. Congure the "Byte Unpack" block :
Figure 3.143
16. Congure the "Byte Pack" block :
Available for free at Connexions <http://cnx.org/content/col10713/1.1>
508
CHAPTER 3.
VIDEO AND IMAGING
Figure 3.144
17. Congure the " TCP/IP Receive " block :
Figure 3.145
Available for free at Connexions <http://cnx.org/content/col10713/1.1>
509
Figure 3.146
18. Congure the " TCP/IP Send " block :
Figure 3.147
19. Connect the Video Frame Capture Motion Threshold block as shown:
Available for free at Connexions <http://cnx.org/content/col10713/1.1>
510
CHAPTER 3.
VIDEO AND IMAGING
Figure 3.148
20. Open the RW_pcl_tcpip.mdl model, created in the "Video R_W" le
21. Rename the model "my_pc_surveil_tcpip.mdl".
22. Add the "Manual Switch" from the "Signal Routing" group of the "Simulink" blockset and three
"Constant" blocks from the "Signal Processing" group of the "Signal Processing" blockset.
23. Congure the " Constant " blocks:
continued on next page
Available for free at Connexions <http://cnx.org/content/col10713/1.1>
511
Table 3.9
24. Congure the "Byte Unpack" block :
Figure 3.149
25. Connect the block as shown:
Available for free at Connexions <http://cnx.org/content/col10713/1.1>
512
CHAPTER 3.
VIDEO AND IMAGING
Figure 3.150
26. Congure the " TCP/IP Receive " block :
Available for free at Connexions <http://cnx.org/content/col10713/1.1>
513
Figure 3.151
27. Double-click the Display subsystem.
28. Double-click the Data Unpack subsystem.
29. Congure the "Byte Unpack" block :
Figure 3.152
30. Connect the block as shown:
Available for free at Connexions <http://cnx.org/content/col10713/1.1>
514
CHAPTER 3.
VIDEO AND IMAGING
Figure 3.153
31. Add to the "Display" subsystem the "Insert Text" from the " Text & gure__" group of the " Video
and Image Processing " blockset, " Floating Scope" from the "Sinks" group of the "Simulink" blockset.
32. Congure the " Insert Text " block :
Available for free at Connexions <http://cnx.org/content/col10713/1.1>
515
Figure 3.154
33. Add the Subsystem from the Ports & Subsystems" group of the "Simulink" Blockset
34. Rename it "Combine Count"
35. Add a "Frame Counter" subsystem as we did in paragraph 14 at the rst section.
Available for free at Connexions <http://cnx.org/content/col10713/1.1>
516
CHAPTER 3.
VIDEO AND IMAGING
Figure 3.155
36. Add a "Matrix Concatenate" from the "Math Operations" group of the "Simulink" blockset.
37. Connect the block as shown:
Figure 3.156
38. Congure the " Matrix Concatenate" block :
Available for free at Connexions <http://cnx.org/content/col10713/1.1>
517
Figure 3.157
39. Connect the "Display" subsystem as shown:
Figure 3.158
Available for free at Connexions <http://cnx.org/content/col10713/1.1>
518
CHAPTER 3.
VIDEO AND IMAGING
40. Open a new m-le, copy the following code and save it as "my_tcpip_surveil_script.m" at the same
directory as the model.
function my_tcpip_surveil_script(hostModelName)
%my_tcpip_surveil_script controls host-side TCP/IP processing for
% Video Surveillance demo:
% 1) Builds and runs the target application
%********** Initialization ********************
% Get model name
modelName = gcs;
% Connect to CCS
CCS_Obj = connectToCCS(modelName);
saved_visibility = CCS_Obj.isvisible;
CCS_Obj.visible(1);
% Load application
loadApp(modelName, CCS_Obj);
% Run application
fprintf('Running application: %s\n', modelName);
CCS_Obj.run;
% Allow some time for DHCP address acquisition
pause(3);
% Retrieve target's host name
boardType = get_param([modelName '/IP Config'], 'boardType');
userPrompt = sprintf('Enter the IP address or the host name of the %s board: ', boardType);
hostName = inputdlg(userPrompt, 'Target IP address');
if isempty(hostName)
errordlg('You have to provide a valid IP address or host name to run the demo.', ...
'TCP/IP Surveillance Recording', 'modal');
return;
end
hostName = strtrim(hostName{1});
% Launch host side UDP receive / Video display model
fprintf('Launching host side application: %s\n', hostModelName);
open_system(hostModelName);
% Update host side TCP/IP blocks with target's IP address
set_param([hostModelName '/TCP//IP Send'], 'Host', hostName);
set_param([hostModelName '/TCP//IP Receive'], 'Host', hostName);
fprintf('Click on play button to start running the host side application!\n\n')
%[EOF] tcpip_surveil_script.m
41. Open a new m-le, copy the following code and save it as "my_tcpip_surveil_script.m" at the same
directory as the model.
42. now we have two models ("my_pc_surveil_tcpip.mdl" and "my_dm6437evmsurveil_tcpip.mdl") and
Available for free at Connexions <http://cnx.org/content/col10713/1.1>
519
one MATLAB le ("my_tcpip_surveil_script.m")
3.5.4.2 Running the Real-time Model
1. Build load and run the project from the "my_dm6437evmsurveil_tcpip.mdl" model. Double-click the
" Build / Reload & Run" block.
2. Running the script, you will see:
Figure 3.159
Figure 3.160
If you want to display the Absolute Dierences Image, change the state of the switch from 0 to 1. You
will then see:
Available for free at Connexions <http://cnx.org/content/col10713/1.1>
520
CHAPTER 3.
VIDEO AND IMAGING
Figure 3.161
Available for free at Connexions <http://cnx.org/content/col10713/1.1>
Chapter 4
From MATLAB and SIMULINK to
Real-time Using TI DSPs
1
4.1 Overview
This course focuses on work-ow and application-based teaching rather than individual DSP algorithms
implementation. Each module starts from an algorithm that is prototyped step-by-step, and then deployed
on the hardware.
The course contains a suite of example applications in various elds such as Audio,
Video, Imaging, Communications and Control.
The basic examples enable students to experiment with
real-time DSP applications, showing how to create prototypes using the Mathworks and Texas Instruments
development tools (hardware and software).
Advanced level examples are also included, where the basic
tools are integrated with external dedicated hardware and/or software modules.
Platforms used:
TMS320F2808 eZdsp Starter Kit (DSK), TMS320F2812 eZdsp Start Kit (DSK),
TMS320C6713 DSP Starter Kit (DSK), TMS320C6416 DSP Starter Kit (DSK), DM6437 Digital Video
Development Platform (DVDP).
This material and more is available as a complete CD-ROM, that can be obtained from Texas Instruments
2
3
and Mathworks
1 This content is available online at <http://cnx.org/content/m24680/1.1/>.
2 See the le at <http://cnx.org/content/m24680/latest/http://www.ti.com/europe/docs/univ/index.htm>
3 See the le at <http://cnx.org/content/m24680/latest/http://www.mathworks.com/programs/mwti-cd/>
Available for free at Connexions <http://cnx.org/content/col10713/1.1>
521
522
INDEX
Index of Keywords and Terms
Keywords are listed by the section with that keyword (page numbers are in parentheses). Keywords
do not necessarily appear in the text of the page. They are merely associated with that section. Ex.
apples, Ÿ 1.1 (1)
A
Terms are referenced by the page they appear on.
Ex.
apples, 1
Acoustic Noise Cancellation, Ÿ 2.1(109)
Ÿ 1.4(85), Ÿ 2.2(148), Ÿ 2.3(191), Ÿ 2.5(244),
AM, Ÿ 2.2(148)
Ÿ 2.6(274), Ÿ 2.7(300), Ÿ 2.8(332), Ÿ 3.1(375),
Audio, Ÿ 1.3(62), Ÿ 2.3(191)
Ÿ 3.2(397), Ÿ 3.5(486), Ÿ 4(521)
Audio Eects, Ÿ 2.5(244)
Motion Detection, Ÿ 3.5(486)
Motor Control, Ÿ 1.2(34), Ÿ 1.4(85)
B
Burg, Ÿ 2.7(300)
C
Covariance, Ÿ 2.7(300)
Noise Reduction, Ÿ 2.8(332)
D
N
Digital Video Development Platform,
P
Periodogram, Ÿ 2.7(300)
Multichannel, Ÿ 2.3(191)
Ÿ 3.2(397)
Permanent Magnet Synchronous Motor,
DM6437, Ÿ 3.2(397), Ÿ 3.3(424), Ÿ 3.4(475),
Ÿ 3.5(486)
DSK6416, Ÿ 3.1(375), Ÿ 3.3(424), Ÿ 3.4(475)
Ÿ 1.4(85)
R
DSK6713, Ÿ 2.1(109), Ÿ 2.2(148), Ÿ 2.4(223),
Ÿ 2.5(244), Ÿ 2.6(274), Ÿ 2.7(300), Ÿ 2.8(332)
DSKF2812, Ÿ 1.2(34)
Reverberation, Ÿ 2.5(244)
S
Simulink, Ÿ 1.1(1), Ÿ 1.2(34), Ÿ 1.3(62),
Ÿ 2.5(244), Ÿ 4(521)
Ÿ 1.4(85), Ÿ 2.2(148), Ÿ 2.3(191), Ÿ 2.5(244),
DTMF, Ÿ 2.4(223)
Ÿ 2.6(274), Ÿ 2.7(300), Ÿ 2.8(332), Ÿ 3.1(375),
DVDP, Ÿ 3.2(397)
Ÿ 3.2(397), Ÿ 3.5(486), Ÿ 4(521)
Echo, Ÿ 2.5(244)
Spectrum Estimation, Ÿ 2.7(300)
Edge Detection, Ÿ 3.4(475)
Surveillance, Ÿ 3.5(486)
H
Hough Transform, Ÿ 3.3(424)
I
Image Processing, Ÿ 3.1(375), Ÿ 3.3(424),
T
TMS320F2808, Ÿ 1.3(62)
TMS320F2812, Ÿ 1.4(85)
TMS32F2812, Ÿ 1.1(1)
Lane Detection, Ÿ 3.3(424)
Line Detection, Ÿ 3.3(424), Ÿ 3.4(475)
LMS, Ÿ 2.1(109)
M
TLV320AIC24, Ÿ 2.3(191)
TMS320C6713, Ÿ 2.3(191)
Ÿ 3.4(475)
L
Signal to Noise Measurement, Ÿ 2.6(274)
Simulation, Ÿ 4(521)
DSP, Ÿ 2.1(109), Ÿ 2.3(191), Ÿ 2.4(223),
E
Real-Time, Ÿ 4(521)
V
Vehicle Dynamics, Ÿ 1.1(1)
Video Processing, Ÿ 3.2(397)
MATLAB, Ÿ 1.1(1), Ÿ 1.2(34), Ÿ 1.3(62),
W Wavelet, Ÿ 2.8(332)
Available for free at Connexions <http://cnx.org/content/col10713/1.1>
523
ATTRIBUTIONS
Attributions
Collection: From MATLAB and Simulink to Real-Time with TI DSP's
Edited by: Jacob Fainguelernt
URL: http://cnx.org/content/col10713/1.1/
License: http://creativecommons.org/licenses/by/2.0/
Module: "Vehicle Dynamics"
By: Jacob Fainguelernt
URL: http://cnx.org/content/m22943/1.1/
Pages: 1-33
Copyright: Cathy Wicks
License: http://creativecommons.org/licenses/by/2.0/
Module: "DC Motor Control"
By: Jacob Fainguelernt
URL: http://cnx.org/content/m22189/1.1/
Pages: 34-62
Copyright: Cathy Wicks
License: http://creativecommons.org/licenses/by/2.0/
Module: "A DSP Based Class D Audio Amplier"
By: Jacob Fainguelernt
URL: http://cnx.org/content/m22177/1.1/
Pages: 62-85
Copyright: Cathy Wicks
License: http://creativecommons.org/licenses/by/2.0/
Module: "Permanent Magnet Synchronous Motor Control"
By: Jacob Fainguelernt
URL: http://cnx.org/content/m24360/1.2/
Pages: 85-107
Copyright: Cathy Wicks
License: http://creativecommons.org/licenses/by/2.0/
Module: "Acoustic Noise Cancellation"
By: Jacob Fainguelernt
URL: http://cnx.org/content/m22178/1.1/
Pages: 109-147
Copyright: Cathy Wicks
License: http://creativecommons.org/licenses/by/2.0/
Module: "Amplitude Modulation"
By: Jacob Fainguelernt
URL: http://cnx.org/content/m22187/1.2/
Pages: 148-191
Copyright: Cathy Wicks
License: http://creativecommons.org/licenses/by/2.0/
Available for free at Connexions <http://cnx.org/content/col10713/1.1>
524
ATTRIBUTIONS
Module: "Audio Conference Bridge"
By: Jacob Fainguelernt
URL: http://cnx.org/content/m22185/1.2/
Pages: 191-223
Copyright: Cathy Wicks
License: http://creativecommons.org/licenses/by/2.0/
Module: "DTMF Detection"
By: Jacob Fainguelernt
URL: http://cnx.org/content/m22937/1.2/
Pages: 223-244
Copyright: Cathy Wicks
License: http://creativecommons.org/licenses/by/2.0/
Module: "Echo and Reverberation"
By: Jacob Fainguelernt
URL: http://cnx.org/content/m22940/1.1/
Pages: 244-274
Copyright: Cathy Wicks
License: http://creativecommons.org/licenses/by/2.0/
Module: "Signal to Noise Measurement"
By: Jacob Fainguelernt
URL: http://cnx.org/content/m22941/1.1/
Pages: 274-300
Copyright: Cathy Wicks
License: http://creativecommons.org/licenses/by/2.0/
Module: "Spectrum Estimation"
By: Jacob Fainguelernt
URL: http://cnx.org/content/m22942/1.1/
Pages: 300-332
Copyright: Cathy Wicks
License: http://creativecommons.org/licenses/by/2.0/
Module: "Wavelet Denoising"
By: Jacob Fainguelernt
URL: http://cnx.org/content/m23011/1.1/
Pages: 332-373
Copyright: Cathy Wicks
License: http://creativecommons.org/licenses/by/2.0/
Module: "A Framework for Image Processing with the DSK6416"
By: Jacob Fainguelernt
URL: http://cnx.org/content/m23996/1.1/
Pages: 375-396
Copyright: Cathy Wicks
License: http://creativecommons.org/licenses/by/2.0/
Module: "A Framework for Video Processing with the DM6437 DVDP"
By: Jacob Fainguelernt
URL: http://cnx.org/content/m23999/1.1/
Pages: 397-424
Copyright: Cathy Wicks
License: http://creativecommons.org/licenses/by/2.0/
Available for free at Connexions <http://cnx.org/content/col10713/1.1>
525
ATTRIBUTIONS
Module: "Finding Shapes in Images"
By: Jacob Fainguelernt
URL: http://cnx.org/content/m24404/1.2/
Pages: 424-475
Copyright: Cathy Wicks
License: http://creativecommons.org/licenses/by/2.0/
Module: "Edge Detection"
By: Jacob Fainguelernt
URL: http://cnx.org/content/m24423/1.2/
Pages: 475-486
Copyright: Cathy Wicks
License: http://creativecommons.org/licenses/by/2.0/
Module: "Video Surveillance"
By: Jacob Fainguelernt
URL: http://cnx.org/content/m24470/1.1/
Pages: 486-520
Copyright: Cathy Wicks
License: http://creativecommons.org/licenses/by/2.0/
Module: "From MATLAB and SIMULINK to Real-time Using TI DSPs"
By: Jacob Fainguelernt
URL: http://cnx.org/content/m24680/1.1/
Page: 521
Copyright: Cathy Wicks
License: http://creativecommons.org/licenses/by/3.0/
Available for free at Connexions <http://cnx.org/content/col10713/1.1>
From MATLAB and Simulink to Real-Time with TI DSP's
This collection focuses on work-ow and application-based teaching rather than individual DSP algorithms
implementation.
The idea is that you start from algorithm development and show how easily an idea is
step-by-step prototyped and deployed on the hardware. The collection contains a suite of example applications in various elds such as Audio, Video, Imaging, Communications and Control. The basic examples
enable students to experiment with real-time DSP applications, showing how to create prototypes using the
Mathworks and Texas Instruments infrastructure (hardware and software). Advanced level examples are also
included, where the basic tools are integrated with external dedicated hardware and/or software modules
(designed by the user).
About Connexions
Since 1999, Connexions has been pioneering a global system where anyone can create course materials and
make them fully accessible and easily reusable free of charge. We are a Web-based authoring, teaching and
learning environment open to anyone interested in education, including students, teachers, professors and
lifelong learners. We connect ideas and facilitate educational communities.
Connexions's modular, interactive courses are in use worldwide by universities, community colleges, K-12
schools, distance learners, and lifelong learners.
Connexions materials are in many languages, including
English, Spanish, Chinese, Japanese, Italian, Vietnamese, French, Portuguese, and Thai. Connexions is part
of an exciting new information distribution system that allows for
Print on Demand Books. Connexions
has partnered with innovative on-demand publisher QOOP to accelerate the delivery of printed course
materials and textbooks into classrooms worldwide at lower prices than traditional academic publishers.