Professional Documents
Culture Documents
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 3.1 3.2 3.3 3.4 3.5
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
4 From MATLAB and SIMULINK to Real-time Using TI DSPs . . . . . . . . . . . . . . . . . . . . . . . . . . . . 521 Index . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 522 Attributions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 523
iv
Chapter 1
Control
2 3 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>
CHAPTER 1.
CONTROL
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
Open VehicleDynamics.mdl .
6
6 See
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.
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.
CHAPTER 1.
CONTROL
Change the shape of the Power Transfer Function. You may wish to change the gradient or make the plateau wider. Run the model.
CHAPTER 1.
CONTROL
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
CHAPTER 1.
CONTROL
10
CHAPTER 1.
CONTROL
11
Available for free at Connexions <http://cnx.org/content/col10713/1.1> Figure 1.10: The Simulink Library Browser
12
CHAPTER 1.
CONTROL
13
Available for free at Connexions <http://cnx.org/content/col10713/1.1> Figure 1.12: Adding a Ramp Generator
14
CHAPTER 1.
CONTROL
15
16
CHAPTER 1.
CONTROL
17
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.
18
CHAPTER 1.
CONTROL
19
20
CHAPTER 1.
CONTROL
The values for the table can also be inserted as a table. Click on the Edit box.
21
22
CHAPTER 1.
CONTROL
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.
23
Select the Main tab. Change the Constant value to 0. Click on OK.
24
CHAPTER 1.
CONTROL
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
25
26
CHAPTER 1.
CONTROL
27
Available for free at Connexions <http://cnx.org/content/col10713/1.1> Figure 1.25: The Simulink Library Browser
28
CHAPTER 1.
CONTROL
Figure 1.26
Figure 26 Selecting Target Preferences When the following screen appears, it is important to select Yes.
29
30
CHAPTER 1.
CONTROL
Figure 1.28
31
32
CHAPTER 1.
CONTROL
33
1.1.6 References
1. Spectrum Digital Incorporated, "eZdspTM F2812 Technical Reference" Rev. (http://c2000.spectrumdigital.com/ezf2812/docs/ezf2812_techref.pdf
9
F, September 2003.
34
CHAPTER 1.
CONTROL
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
35
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:
(1.1)
V D Vss
36
CHAPTER 1.
CONTROL
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 )
37
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.
38
CHAPTER 1.
CONTROL
15
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.
15
volts, and common (ground). An ammeter is also included. The maximum current is 2 A. An 8-pin
39
11 12 13
40
CHAPTER 1.
CONTROL
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
41
1. The motor speed using a stroboscope 2. The tachometer output using a voltmeter The setup is shown in Figure 7.
Figure 8 shows the model that will be used to generate the control voltage.
42
CHAPTER 1.
CONTROL
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).
43
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.
44
CHAPTER 1.
CONTROL
45
46
CHAPTER 1.
CONTROL
47
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 ;
not linear (due to friction, for example), therefore the measured values were:
rise fall
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)
1 = Km 1+ .2s
(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.
49
50
CHAPTER 1.
CONTROL
51
The rst is LPF with an amplier (shown in Figure 18), The second block is an attenuator
connected between the PWM output and the servo amplier input. eZDSP.
(shown in Figure 19) connected between the tachometer output and the Analog to Digital Input of the
52
CHAPTER 1.
CONTROL
53
54
CHAPTER 1.
CONTROL
Procedure: 1. Navigate into the following directory: ..\MATLAB\R2006b\toolbox\rtw\targets\tic2000\tic2000demos 1. Copy the following les into your working directory:
14 The
c2812speedcontrolDC.mdl runc2812speedcontrolDC.m runc2812speedcontrolDC.m Open the c2812speedcontrolDC.mdl model and save it as "DCMotorControlc2812.mdl"(please refer to Figure 21
14
).
55
56
CHAPTER 1.
CONTROL
57
58
CHAPTER 1.
CONTROL
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:
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,
59
as shown:
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:
60
CHAPTER 1.
CONTROL
9. Activate the motor 10. Activate CCS. 11. Click the Build/Reload&Run box, the following window should appear:
61
12. You may change the speed of the motor using the slider in the right hand side and the Apply button.
62
CHAPTER 1.
CONTROL
1.2.5 References
1. "eZdspTM F2812 Technical Reference", Spectrum
15
Digital,
2003
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 Application Report SPRAA88 , September 2008 http://www.ti.com/litv/pdf/spraa88a
16
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.
18 19
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>
63
64
CHAPTER 1.
CONTROL
level. The ePWM coupled with a D-Class output stage and a second order passive RLC lter, provides a
65
Vin 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.
66
CHAPTER 1.
CONTROL
67
68
CHAPTER 1.
CONTROL
69
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.
70
CHAPTER 1.
CONTROL
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.
71
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.
72
CHAPTER 1.
CONTROL
2.
Figure 1.70: The "F2808 eZDSP" block
3.
Figure 1.71: The "Hardware Interrupt" Block
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.
4.
Figure 1.73: The Hardware Interrupt Conguration
74
CHAPTER 1.
CONTROL
5.
Figure 1.74: The "Function-Call Subsystem" Block
6.
20
20 You
may also change colors, and name the blocks as shown here.
75
76
CHAPTER 1.
CONTROL
1.
Figure 1.76
2.
Figure 1.77: The "ADC" Block
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)
3.
Figure 1.79: The "ePWM" block
78
CHAPTER 1.
CONTROL
(a)
(b)
79
(a)
(b)
80
CHAPTER 1.
CONTROL
4.
Figure 1.82: The "Shift Arithmetic" Block
81
82
CHAPTER 1.
CONTROL
5.
Figure 1.84: The Class D Amplier Model
83
1.
Figure 1.85: The System
84
CHAPTER 1.
CONTROL
Build and run the model "CTRL-B". 3. The amplier should start working, connect your audio source, and enjoy the music.
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
21
Digital,
2005
http://c2000.spectrumdigital.com/ezf2808/docs/2808_ezdspusb_techref_c.pdf
21 http://c2000.spectrumdigital.com/ezf2808/docs/2808_ezdspusb_techref_c.pdf
85
2. David M. Alter, " Using PWM Output as a Digital-to-Analog Converter on a TMS320F280x", TI Application Report SPRAA88 , September 2008 http://www.ti.com/litv/pdf/spraa88a
22
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
24
Simulink Model for Space vector generation Simulation - PMS_Motor_level1.mdl Simulink Model for Open Loop Simulation - PMS_Motor_level2.mdl
27 28 29
26
Simulink Model for Encoder Verication Simulation - PMS_Motor_level4.mdl Simulink Model for Closed Loop Simulation - PMS_Motor_level5.mdl
30
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
31
Simulink Model for current loop - Real Time - PMS_Motor_level3eZDSPF2812.mdl Simulink Model for Closed Loop - Real Time PMS_Motor_level5eZDSPF2812.mdl
34
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>
87
1.4.3 Simulation
The simulation process will be based on a simulation model for the PMS Motor.
88
CHAPTER 1.
CONTROL
Available for free at Connexions <http://cnx.org/content/col10713/1.1> Figure 1.88: Permanent Magnet Synchronous Motor (PMSM) Simulink Model
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
operation of peripheral and target independent modules on forward control path and the code framework.
At this very rst stage the goal is to generate a sawtooth waveform with a varying frequency. to check the correct computation of the Space Vector PWM needed for the Field Oriented Control.
This
waveform is an emulation of the rotor angle, which is then passed into the Park transformation allowing us
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. angle is then used for the Inverse PARK transformation.
module is rg1.rmp_freq . The rotating angle we generate (saw-tooth waveform) is rg1.rmp_out. This
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 This module takes the output of the magnitude via the variables ipark1.de and ipark1.qe.
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
%Mechanical system %Electrical part DC_voltage = 200; encoder_resolution = 2000; %PWM freq_max=75e6; %Controller Ts=5e-5;
1. Open the PMS_Motor_level1
37
Simulink
model.
36 See 37 See
91
Vd Testing 1. Run the model and double-click the Stator Current and Rotor Speed scopes.
92
CHAPTER 1.
CONTROL
93
94
CHAPTER 1.
CONTROL
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:
ADC to start automatic conversions of channels selected by the user on timer 1 underow. conversion results are automatically formatted and stored into dedicated variables.
CLARKE (Clarke transform module): coordinates in the reference frame (, Open the PMS_Motor_level2
38
). )
coordinates into two DC quantities.
38 See
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.
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.
97
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
Simulink model.
39 See
98
CHAPTER 1.
CONTROL
Vd Testing 1. Run the model and double-click the Stator Current and Rotor Speed (same as previous section) and Vd/Vq scopes.
99
100
CHAPTER 1.
CONTROL
101
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.
102
CHAPTER 1.
CONTROL
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 The QEP module also takes care of the capture unit instance speed1. Based 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. initialization.
on system information (number of poles pairs for instance), this module outputs the motor speed
103
40
Simulink model.
1. Run the model and double-click the PWM dutycycles and Rotor Speed scopes.
40 See
104
CHAPTER 1.
CONTROL
105
106
CHAPTER 1.
CONTROL
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.
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.
107
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!
Halt;
108
CHAPTER 1.
CONTROL
Chapter 2
Signal Processing and Communication
2.1.1.1 Objectives
Design a model of LMS Noise Reduction for the Texas Instruments C6000 family of DSP devices using MATLAB
and Simulink.
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. standing of matrices and the LMS algorithm. It also requires a theoretical under-
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
109
110
CHAPTER 2.
2 3 4
2.1.2 Simulation
You will now start with a simple Simulink model and run it to see how it works.
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>
111
112
CHAPTER 2.
113
Double-click on the LMS Filter block and change the Step size (mu) to 0.1 Run the model.
114
CHAPTER 2.
Figure 2.5: Input and LMS Filter Outputs for Step size (mu) = 0.1
115
Figure 2.6: LMS Filter Weights for Step size (mu) = 0.1
116
CHAPTER 2.
Experiment with dierent values of delay to see how it eects the operation of the LMS Filter.
117
118
CHAPTER 2.
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.
119
120
CHAPTER 2.
121
Highlight Embedded Target for TI C6000 DSP then Audio. Click on Wavelet Denoising. We are going to use this as our template.
122
CHAPTER 2.
123
124
CHAPTER 2.
125
126
CHAPTER 2.
127
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.
128
CHAPTER 2.
129
130
CHAPTER 2.
131
block onto
6 Since
we are working with frames, the delay from Discrete Components library will not work!
132
CHAPTER 2.
133
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.
134
CHAPTER 2.
135
136
CHAPTER 2.
137
138
CHAPTER 2.
139
140
CHAPTER 2.
141
142
CHAPTER 2.
143
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:
144
CHAPTER 2.
The microphone is fed directly to the loudspeakers. There is no LMS noise reduction.
145
146
CHAPTER 2.
147
Figure 40 MATLAB and Simulink are registered trademarks of The MathWorks, Inc. See www.mathworks.com/trademarks for a list of additional trademarks. may be trademarks or registered trademarks of their respective holders. Other product or brand names
148
CHAPTER 2.
Powerpoint Presentation - Amplitude Modulation.ppt Simulink Model for Simulation - AM_Simulation.mdl MATLAB GUI for Real-Time - AM.g GUI m-leAM.m
11 10
12 13 14
Simulink Model for Square Root (SQRT) Detection AM_Sqrt.mdl Congurable Carrier Simulink Model Congurable_Carrier.mdl
15
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>
149
m (t)
150
CHAPTER 2.
Open the Simulink library browser and add the DSP sine-wave to your model. This blocks will represent
151
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.
152
CHAPTER 2.
it form the Simulink library. Set the carrier frequency to 15,000 Hz. The remaining parameters are
153
identical to the ones of the information signal. Change its label to carrier
Double-click on the constant object and set its constant value to 1.5:
154
CHAPTER 2.
155
Add a new multiplexer from the same directory as the adder (choose product). Add a new scope object:
156
CHAPTER 2.
157
158
CHAPTER 2.
Run the model, pause the simulation and activate the scope window. The modulated signal should be displayed as follows:
159
160
CHAPTER 2.
Add the new math function block to your model. This block can be congured to implement various mathematical functions.
161
162
CHAPTER 2.
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. FDATool. This block enables you to design lters using the MATLAB
163
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).
164
CHAPTER 2.
16
block.
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: ++
165
166
CHAPTER 2.
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).
167
168
CHAPTER 2.
You may change the simulation parameters, and check their inuence.
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.
169
170
CHAPTER 2.
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.
171
Remove the scope and the information signal (the 1,000 Hz). Open the Simulink library browser and add the "C6713DSK".
Add the Analog to Digital and Digital to Analog converters (ADC and DAC) to your model:
172
CHAPTER 2.
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.
173
1. Congure the ADC and DAC blocks to a sampling rate to 96 KHZ and 16-bit samples.
174
CHAPTER 2.
175
You should congure the DSP constants as shown in Figure 28. The frame period for all constants should be -1
176
CHAPTER 2.
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.
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.
177
Replace the constant modulation index by an RTDX input (Please refer to Figure 30), and name it InputModulation.
178
CHAPTER 2.
Replace the sine wave block used for the carrier by the congurable carrier blocks (you may nd them
179
17
le)
18
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.
180
CHAPTER 2.
181
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
19 The
182
CHAPTER 2.
Push the OK button and close the Conguration Parameters window. Rebuild *.out le using ctrl+B.
20
You now have two load les each one corresponding to a dierent AM scheme.
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:
the le at <http://cnx.org/content/m22187/latest/AM_Coherent.mdl>
20 See
183
Now, double click on the list-box and change the string eld:
184
CHAPTER 2.
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.
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.
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.
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);
186
CHAPTER 2.
%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
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);
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);
188
CHAPTER 2.
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: cosc t
= Re ejc t
(2.1)
cosc nTs
= cos2
(2.2)
189
The following model implements the last equation. Please note that a feedback path was included for phase continuity
21 See
190
CHAPTER 2.
191
MATLAB
and
Simulink
are
registered
trademarks
of
The
MathWorks,
Inc.
See
www.mathworks.com/trademarks for a list of additional trademarks. may be trademarks or registered trademarks of their respective holders.
>2)
1. The algorithm monitors the voice signals from all attendants, and creates the signals to be transmitted
22 This
192
CHAPTER 2.
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
23
Simulink Model for Audio Conference Bridge and Legacy Driver Files - C67_Simulink_conference.rar
25
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
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 interfaces between the
193
TLV320AIC24 can be gluelessly cascaded to any SMARTDM-based device to form a multichannel CODEC, and up to eight TLV320AIC2x CODECs can be cascaded 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.
27
The SMARTDM port is connected to the Multichannel Buered Serial Port (McBSP) in the DSP as
27 We
194
CHAPTER 2.
195
196
CHAPTER 2.
197
(a) Frame #n
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
198
CHAPTER 2.
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.
199
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.
200
CHAPTER 2.
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
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
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.
28 The 29 This
CODEC can operate in DATAMODE or PROGRAMMING mode. is not mandatory. You may add the les from any directory.
For a detailed
201
2.3.3.5 An example
The example creates two audio paths as follows:
0 2
DSP DSP
CODEC#2/OUTP1
The example is illustrated in Figure 9. A user dened function test.c was created for this application.
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.
#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.
void copyData Int16 *inbuf, Int16 *outbuf, Int16 length { Int16 i = 0; for } }
// 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 Starts the AIC24
30
After this step, the program will enter in an endless loop. Samples will be processed each time an EDMA interrupt occurs.
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);
204
CHAPTER 2.
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.
Buers Denitions:
// // // //
206
CHAPTER 2.
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.
207
Figure 2.91: The Simulink demo for Device Driver/Legacy Code Integration
208
CHAPTER 2.
Double-click the "AIC23 Codec Driver" box. Rename it (TLV320AIC24EVM). Delete the EDMA related boxes
31
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. Figure 17 summarizes the driver blocks conguration
31 The
EDMA and interrupts congurations are handled as in the original CCS driver.
209
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 wiring them appropriately. Double click on each terminator and set its dimension to 64
32
(except for
32 The
terminator dimension should match the value of the DATANUM constant in the aic24link.c le
210
CHAPTER 2.
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.
The model is now ready to generate real-time code for processing of 4 audio channels. AN example is shown in the next chapter.
211
conference. The DSP monitors the 3 input signals, and routes the loudest input signal to the three outputs.
33 The
TLV320AIC24 contains three analog interfaces for headsets. The use of an additional channel requires minor hardware
212
CHAPTER 2.
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
.
requirement for a threshold amount of wining rounds was set in order to prevent random noise or occasional spikes algorithm is implemented for 4 channels, however we will use only three of them.
34 The 35 The
from interfering with the algorithms function. This threshold is congurable. In this example it was set to 10.
213
The block diagram shown in Figure 20 is translated to the model shown in the following gures.
214
CHAPTER 2.
215
The 4 level values compose a 4 element vector. This vector is fed to the Max abs value block:
216
CHAPTER 2.
The index of the Maximum level enters the index selection block. incremented and compared to the threshold.
If the counter value equals the threshold, the index is selected as input to the conference block
36
2.3.6 References
1. "TLV320AIC20K/24KEVM User's Guide ",
37
TI )
Document
SLAU088A,
April
2005
2. "DSPCODEC Development Platform User's Guide", TI Document SLAU090, September 2002 ) 16-Bit March 26-KSPS 2002 Dual Channel April 2005 Revised Programmable SLAS363D,
39
trademarks
www.mathworks.com/trademarks for a list of additional trademarks. may be trademarks or registered trademarks of their respective holders.
217
Figure 2.102
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. If, for example, the input samples of channel 0 in the CODEC should be received from INP3 conguration should be as follows:
40
The
218
CHAPTER 2.
2.3.7.1.2 Switches and Jumpers Jumper settings for the AIC24 EVM
Table 2.2
Table 2.3
41 Other
entries were reset ('0'), as they should not be connected to the channel's input.
219
2.3.7.2 DSP 2.3.7.2.1 EDMA Conguration EDMA Receive Channel Conguration (Register Values)
Remarks
Low Priority (Allows other DMAs rst) 16 bits elements Source not using 2D option Source Address is xed (The MCBSP rcv register)
EDMA_OPT_2DD_NO EDMA_OPT_DUM_IDX
Destination not using 2D option Destination address is in double index (sort) mode
EDMA_OPT_TCINT_YES EDMA_OPT_TCC_OF(0)
Cause interrupt Transfer Complete Code (given to the interrupt, set later)
EDMA_OPT_LINK_YES EDMA_OPT_FS_NO
Use linking to another EDMA record Don't use frame sync The address of the McBSP recv register
src cnt
MCBSP_getRcvAddr(hAIC->hMcbsp)
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 idx
The address of the buer to write to Negative Frame Index to move us back to the next position in the rst channel after each frame
EDMA_IDX_ELEIDX_OF((ChannelBuerSize Positive Element Index to move us to the next * 2) position in channel after every elemnt
rld
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
220
CHAPTER 2.
Remarks
Low Priority (Allows other DMAs rst) 16 bits elements Source not using 2D option Source address is in double index (sort) Destination not using 2D option Destination Address is xed (The MCBSP xmt register)
EDMA_OPT_TCINT_YES EDMA_OPT_TCC_OF(0)
Cause interrupt Transfer Complete Code (given to the interrupt, set later)
EDMA_OPT_LINK_YES EDMA_OPT_FS_NO
Use linking to another EDMA record Don't use frame sync The address of the buer read from
src cnt
EDMA_SRC_OF(WriteAddr)
EDMA_CNT_FRMCNT_OF(ChannelBuerSize Each frame has NumChannel elements 1) EDMA_CNT_ELECNT_OF(TotalNumChannels) Each frame has NumChannel elements
dst idx
The address of the McBSP transmit register Negative Frame Index to move us back to the next position in the rst channel after each frame
EDMA_IDX_ELEIDX_OF((ChannelBuerSize Positive Element Index to move us to the next * 2)) position in channel after every elemnt
rld
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
221
Remarks
Used for emulation
Used for emulation Frame sync generator is in reset (generated by master CODEC)
MCBSP_SPCR_GRST_YES
MCBSP_SPCR_XINTM_FRM
MCBSP_SPCR_XSYNCERR_NO MCBSP_SPCR_XRST_YES
No synchronization error detected The serial port transmitter is disabled and in reset state
MCBSP_SPCR_DLB_OFF MCBSP_SPCR_RJUST_RZF
Digital Loopback mode o Receive data right-justied and zero-ll MSBSs in DRR
The Clock stop mode is disabled Disable extra delay of DX Receive interrupt on new frame synch No synchronization error detected The serial port receiver is disabled and in reset state
222
CHAPTER 2.
Don't Care. Phase 2 is not used Don't Care. Phase 2 is not used No companding, data transfer starts with MSB rst
MCBSP_RCR_RFIG_NO MCBSP_RCR_RDATDLY_1BIT
MCBSP_RCR_RFRLEN1_OF(NumChannels- Each frame contains an element for each chan1) MCBSP_RCR_RWDLEN1_16BIT MCBSP_RCR_RWDREVRS_DISABLE nel Each sample is 16 bit Don't Care. Only 16 bit elements are used Transmit one phase only
Don't Care. Phase 2 is not used Don't Care. Phase 2 is not used No companding, data transfer starts with MSB rst
MCBSP_XCR_XFIG_NO MCBSP_XCR_XDATDLY_1BIT
MCBSP_XCR_XFRLEN1_OF(NumChannels- Each frame contains an element for each chan1) MCBSP_XCR_XWDLEN1_16BIT MCBSP_XCR_XWDREVRS_DISABLE nel Each sample is 16bit Does not matter, we use 16 bit elements Not used, clock and frame sync are generated by the master CODEC (The source code contains the ags but they are 0)
223
All pins are dedicated for MCBSP (Not GPIO) Transmit frame sync is generated by the master CODEC
MCBSP_PCR_FSRM_EXTERNAL
MCBSP_PCR_CLKXM_INPUT
MCBSP_PCR_CLKRM_INPUT
Does not matter (used in GPIO) Does not matter (used in GPIO) Transmit frame sync is active high for AIC24 Receive frame sync is active high for AIC24 Transmit data driven on rising edge Receive data sampled on falling edge Unused Unused Unused
(Dial
) and loop disconnect (LD) signaling methods to dial numbers, in order to shorten
45
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). When any key is pressed the tone of the column and the tone of the row are no frequency is a multiple of another, the dierence between any two
generated. As an example, pressing the '5' button generates the tones 770 Hz and 1336 Hz. The frequencies were chosen to avoid harmonics: the frequencies. frequencies does not equal any of the frequencies, and the sum of any two frequencies does not equal any of
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
224
CHAPTER 2.
1209 Hz 1 4 7 *
1336 Hz 2 5 8 0
1477 Hz 3 6 9 #
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.
46 47
Simulink Model for Simulation - DTMF.mdl MATLAB GUI for Real-Time - DTMF.g GUI m-le - DTMF.m
49 48
50
2.4.2 Simulation
2.4.2.1 The Simulation Model
Figure 1 shows the model used to simulate DTMF detection and generation.
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>
225
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). activated. Upon selection of a digit to be transmitted, the correspondent oscillators are
226
CHAPTER 2.
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.
227
228
CHAPTER 2.
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:
229
230
CHAPTER 2.
RTDX. A graphic user interface (GUI) will be built to activate the transmitter, and display the reported
231
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 Digits will be reported through RTDX. Addition of the DSK6713 target preference
51
DSP.
Open the simulation model DTMF.mdl, remove all the blocks besides the DTMF receiver block. Open the Simulink
51 This
block is necessary to convert the unipolar format of the samples to a 2's complement format for processing by the
232
CHAPTER 2.
233
234
CHAPTER 2.
The TO RTDX will be used to report the detected digits to the PC. Add it to your model:
235
236
CHAPTER 2.
237
238
CHAPTER 2.
239
Initialization: Initialize the RTDX interface and loading the DTMF Receiver program we have built in the last section to the DSK. Generate the DTMF signal samples: The GUI will enable the user to select a sequence of 11 digits them to the sound card.
52
to be transmitted. It will create the samples of the DTMF signal based on this selection, and send
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'.
240
CHAPTER 2.
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 Send: Create the DTMF signal from the digits selected the sound command in MATLAB.
53
digit. Silence will be inserted between consecutive digits. This signal is sent to the sound blaster using
Display: Digits reported by the DSK will be displayed under the Detected Digits label.
Activate the GUIDE (Graphic User Interface Integrated Development Environment in MATLAB.
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
53 The
MATLAB.
241
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):
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:
242
CHAPTER 2.
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);
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.
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:
244
CHAPTER 2.
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.5.1.1 Objectives
Design models of Echo and Reverberation for the Texas Instruments C6000 family of DSP devices using MATLAB
and Simulink.
Modify an existing Simulink model. Run the model in real-time on the Texas Instruments C6713 DSK.
54 This
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.
MATLAB R2006b with Embedded Target for TI C6000. Code Composer Studio (CCS) v3.1 Texas Instruments C6713 DSK hardware Microphone and computer loudspeakers/headphones
55 56 57
Simulink Model for Reverberation Simulation - ReverberationUsingWav.mdl Simulink Model for Real-Time - EchoAndReverberationDSKC6713.mdl Audio Template for the DSK6713C6713_Audio_Template.mdl
59 58
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
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>
246
CHAPTER 2.
247
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
248
CHAPTER 2.
249
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?
250
CHAPTER 2.
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.
251
252
CHAPTER 2.
253
254
CHAPTER 2.
255
You will now drag-and-drop some library components onto the model.
256
CHAPTER 2.
From Commonly Used Blocks, drag-and-drop a Gain block, a Sum block and two Data Type Conversion blocks onto the model.
257
258
CHAPTER 2.
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.
259
260
CHAPTER 2.
261
262
CHAPTER 2.
263
Note that the reverberation subsystem is very similar to that of echo. We will cut-and-paste from the Echo Subsystem
264
CHAPTER 2.
265
266
CHAPTER 2.
267
268
CHAPTER 2.
269
270
CHAPTER 2.
271
272
CHAPTER 2.
The microphone is fed directly to the loudspeakers without any digital signal processing.
273
274
CHAPTER 2.
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
Intermediate - Assumes prior knowledge of MATLAB
and Simulink.
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
275
61 62 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
276
CHAPTER 2.
277
278
CHAPTER 2.
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.
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.
279
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
280
CHAPTER 2.
band.
281
282
CHAPTER 2.
283
Figure 2.162: Adjusting the Frame Size for the Random Source
284
CHAPTER 2.
Run the model again. Question: How does this change to the frame size aect performance?
Run the model again and make a note of the accuracy of the measurement. Change Delay (samples)
64
Question: How does the value of delay (samples) aect the accuracy of the model?
64 The
Delay (samples) should be smaller than the frame size, otherwise the frames do not overlap.
285
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.
286
CHAPTER 2.
287
288
CHAPTER 2.
Run the model. Question: Does the model produce better results with 8000Hz sampling or 48000 Hz sampling? Make a note of the answer.
289
290
CHAPTER 2.
291
292
CHAPTER 2.
293
294
CHAPTER 2.
295
296
CHAPTER 2.
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:
297
Note that when you are not speaking, there is no audio output at all just silence.
298
CHAPTER 2.
299
300
CHAPTER 2.
Periodogram
Figure 2.180
The Periodogram block computes a nonparametric estimate of the spectrum. average by the square of the sum of the window samples.
squared magnitude of the FFT computed over windowed sections of the input and normalizes the spectral
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. recursion. 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
Powerpoint Presentation - SpectrumEstimation.ppt MATLAB GUI for Real-Time - Spectrum.g GUI m-leSpectrum.m
69 68
66 67
m-le for Selection of estimation method SelectModel.m Simulink Model for Burg Estimation Method Burg.mdl
70
71 72 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>
302
CHAPTER 2.
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.
SpectrumEstimation.mdl
2. Open the Simulink library browser and add a random source object:
303
3. Double click on the random source object, and congure its parameters to t the white noise characteristics we want to achieve:
304
CHAPTER 2.
305
74
74 The
Auto-Regressive process is represented by an all-pole IIR lter. The AR coecients are the ones in the Denominator
coecients label.
306
CHAPTER 2.
307
75
75 The
308
CHAPTER 2.
309
310
CHAPTER 2.
10. Add a magnitude FFT block in order to get the spectrum from the AR coecients:
311
312
CHAPTER 2.
13. The Math Function block should be congured to calculate the reciprocal:
313
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:
314
CHAPTER 2.
15. In order to display the Real and Estimated spectra simultaneously, you need to add a new concatenate object:
315
316
CHAPTER 2.
317
318
CHAPTER 2.
76
76 You
319
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).
320
CHAPTER 2.
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:
321
322
CHAPTER 2.
323
5. Congure the DAC block to a sampling rate to 8 KHZ and 16-bit samples.
324
CHAPTER 2.
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).
325
8. Congure the ADC blocks to a sampling rate to 8 KHZ and 16-bit samples.
326
CHAPTER 2.
327
10. Set the AR-coecients data type to single. 11. Congure the Model to generate and build (without executing) the CCS code as shown:
328
CHAPTER 2.
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:
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:
330
CHAPTER 2.
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.
331
command line.
2. Choose a new GUI, and name it Spectrum 3. Add a list-box to your GUI with the string:
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.
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.
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:
77 This
333
2.8.1.1 Objectives
Design a model of Wavelet Noise Reduction for the Texas Instruments C6000 family of DSP devices using MATLAB
and Simulink.
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-
MATLAB R2006b with Embedded Target for TI C6000. Code Composer Studio (CCS) v3.1 Texas Instruments C6713 DSK hardware. Microphone and computer loudspeakers / headphones.
78 79 80
2.8.2 Simulation
2.8.2.1 Simulink Model
The Simulink model described here is based on a MATLAB Demo.
334
CHAPTER 2.
335
336
CHAPTER 2.
337
338
CHAPTER 2.
339
Here Out1 has been given a threshold of 3. This means that only values The output is shown in Figure 6. reduced.
>
Out2, Out3 and Out4 have been given the value of 0. This means the whole signal is let through. Note that the noise associated with Out2 and Out3 have not been
340
CHAPTER 2.
341
342
CHAPTER 2.
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.
343
344
CHAPTER 2.
Highlight Embedded Target for TI C6000 DSP then Audio. Click on Wavelet Denoising.
345
346
CHAPTER 2.
347
348
CHAPTER 2.
You will now update the existing model by dragging-and-dropping some library components onto the model.
349
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.
350
CHAPTER 2.
351
Available for free at Connexions <http://cnx.org/content/col10713/1.1> Figure 2.233: Adding a Switch and LED
352
CHAPTER 2.
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.
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.
354
CHAPTER 2.
Available for free at Connexions <http://cnx.org/content/col10713/1.1> Figure 2.235: Selecting the Commonly Used Blocks
355
356
CHAPTER 2.
357
358
CHAPTER 2.
359
360
CHAPTER 2.
361
362
CHAPTER 2.
363
364
CHAPTER 2.
365
366
CHAPTER 2.
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:
367
368
CHAPTER 2.
369
370
CHAPTER 2.
371
372
CHAPTER 2.
373
374
CHAPTER 2.
Chapter 3
Video and Imaging
MATLAB script for Real-Time - Picture_script.m Simulink Model for Real-Time - stills_R_W.mdl
5
This section will show you how to activate CCS under the Simulink.
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>
375
376
CHAPTER 3.
3. Set the model to Generate a CCS Project in the Simulation->Conguration Parameters -> Build Action, as shown in the following picture:
377
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:
378
CHAPTER 3.
Figure 3.3: Creating the Generate Code & Create Project Simulink block
379
380
CHAPTER 3.
381
6 See
382
CHAPTER 3.
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.
383
384
CHAPTER 3.
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).
385
7. Double Click and select the "R'G'B' to intensity" conversion scheme as shown in Figure 11.
386
CHAPTER 3.
9. Run the model, you should get the image shown in Figure 13
387
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
388
CHAPTER 3.
389
2. Congure the block to receive data from a channel named "inputimage" as shown in Figure 16
8
. For
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
block.
you are using the XDS560 or the Blackhawk USB560, you will need to enable High Speed RTDX in the "C61416DSK" "Output Dimensions" should contain the Frame size
8 The
390
CHAPTER 3.
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.
391
Congure the block to send data through a channel named "outputimage" as shown in Figure 9.
392
CHAPTER 3.
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.
393
5. Save your model (We used the name stills_R_W.mdl). Your model should look as shown in Figure 21.
394
CHAPTER 3.
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. 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: This object
9 If
you do so, the build will fail at compilation in CCS due to an ISRAM space issue.
redening the location for .far as SDRAM rather than ISRAM (the default) in the board properties box. Rebuild, and it should compile ne.
395 This media object is a downloadable le. Please view or download it at <g22.JPG>
Figure 3.22: CCS Compilation Display
%% 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:
396
CHAPTER 3.
397
MATLAB
R2008a
Code Composer Studio (CCS) v3.3 Texas Instruments DM6437 Digital Video Development Platform (DVDP) . Video camera and screen.
11
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 Real-Time
15 14
13
Video
Processing
through
the
TCP/IP
Interface
RW_dm6437_tcpip.mdl RW_pcl_tcpip.mdl
16
Simulink Model for PC Control of Real-Time Video Processing through the TCP/IP Interface -
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>
398
CHAPTER 3.
17
17 See
399
3. In order to display the picture the "Video Viewer" from the "Sinks" group of the Video and Image Processing Blockset will be used.
400
CHAPTER 3.
401
5. Run the model, you should see the video clip. A single frame is shown mage shown in Figure 6.
6. Save your model (We used the name Video_sim.mdl", that you may nd it here
18
).
18 See
402
CHAPTER 3.
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).
403
5. Rename Function- Call Subsystem to Video Processing and connect it to the Task block. 6. Save the model as Video_R_W.mdl. Your model should look as follows
19
19 You
may add a title to the model, as done here ( Video Processing Template)
404
CHAPTER 3.
7. Double-click the Task block and make the same changes as shown in Figure 34.
405
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.
406
CHAPTER 3.
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.
407
11. Double-click the Video Display block and change the Video capture mode only if you are using the components in the PAL
20
20 If
the camera video capture mode is NTSC you should choose this option
408
CHAPTER 3.
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. 16. Run the target. Double-click the Run block. This model can be found here
21
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.
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).
410
CHAPTER 3.
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:
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).
412
CHAPTER 3.
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 11. Save the model as RW_dm6437_tcpip.mdl. Your model should look as follows:
413
12. Double-click the Task block and make the same changes as shown in Figure 20.
414
CHAPTER 3.
13. Double-click the IP Cong block and make the same changes as shown in Figure 21.
415
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.
416
CHAPTER 3.
417
17. Double-click the TCP/IP Receive block and make the same changes as shown in Figure 24.
418
CHAPTER 3.
(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:
419
19. Double-click the Byte Unpack block and congure it as shown in Figure 26.
420
CHAPTER 3.
20. Double-click the Byte pack block and congure it as shown in Figure 27.
21. Open a new m-le, copy the following code and save it as "RW_tcpip_script.m" at the same directory
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
422
CHAPTER 3.
(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:
423
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
424
CHAPTER 3.
23
MATLAB
R2008a
25 26 27
Simulink Model for Line Detection Simulation - LineDetection.mdl Source Image for Line - circuit.tif
28 29 30
Simulink Model for Lane Detection Simulation - LaneDetection.mdl Video-clip for Lane Detection - viplane.avi
Simulink Model for Real-Time Line Detection - LineDetectionDSK6416.mdl Simulink Model for Real-Time Lane Detection - LaneDetection.mdl MATLAB script for Lane Detection - lane_tcpip_script.m
33 32
31
Simulink Model for Real-Time Lane Detection (DM6437) - lane_dm6437_tcpip.mdl Simulink Model for Real-Time Lane Detection (PC) - lane_pcl_tcpip.mdl
35
34
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>
425
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).
36 http://cnx.org/Members/jfaing/m23996/stills_sim.mdl 37 http://cnx.org/content/m23996/latest/
426
CHAPTER 3.
Block Edge Detection Hough Transform Find Local Maxima Selector Variable Selector Terminator Hough Lines Draw Shapes
Library Video and Image Processing Blockset / Analysis & Enhancement Video and Image Processing Blockset / Transforms Video and Image Processing Blockset / Statistics Simulink
Quantity 1 1 1 2 2 1 1 1
/ Signal Routing
Signal Processing Blockset / Signal Management / Indexing Simulink / Sinks Video and Image Processing Blockset / Transforms Video and Image Processing Blockset / Text & Graphics
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:
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.
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.
428
CHAPTER 3.
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. follows: Set the Selector block parameters as
Index mode = Zero-based Elements (-1 for all elements) = 0 Input port width = 2
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:
429
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:
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. Connect the blocks as shown in the gure below. Use the le circuit.tif
38
as input.
Figure 3.58
Create a Subsystem for the Hough algorithm. Select the blocks as shown in the following picture:
38 See
430
CHAPTER 3.
Figure 3.59
In the main menu, click on Edit/Create Subsystem (you may also enter Ctrl+G), as follows:
431
Figure 3.60
432
CHAPTER 3.
Figure 3.61
433
Figure 3.62
Create a Subsystem for the Line Drawing and Image Construction. Select the blocks as shown in the following picture:
434
CHAPTER 3.
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
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:
436
CHAPTER 3.
Figure 3.66
Figure 3.67
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.
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.
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/
438
CHAPTER 3.
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 :
439
440
CHAPTER 3.
3.3.3.1 Simulation
Open the video_sim.mdl the DM6437 DVDP
42 41
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,
41 http://cnx.org/Members/jfaing/m23999/video_sim.mdl 42 http://cnx.org/content/m23999/latest/
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:
442
CHAPTER 3.
Figure 3.73
Figure 3.74
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
444
CHAPTER 3.
Figure 3.76
Double Click the Enhanced Edge Detection block. Rename the Input port to ROI, and the output port to Binary Image
445
Figure 3.77
Block 2-D Histogram Maximum Data Type Conversion Bias Gain Relational Operator Logical Operator
Library Video and Image Processing Blockset / Statistics Signal Processing Blockset/ Statistics Simulink/ Signal Attributes Simulink / Math Operations Simulink / Math Operations Simulink / Logic and Bit Operations Simulink / Logic and Bit Operations
Table 3.3
Quantity 1 1 1 1 1 1 1
Place the blocks so that your model resembles the following gure. based on histogram with the selected blocks.
446
CHAPTER 3.
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
447
Double-click the Hough Algorithm block in the model. You should change it to select the two longest lines.
Figure 3.80
448
CHAPTER 3.
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:
450
CHAPTER 3.
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:
451
Figure 3.83
Now, it will draw the polygon based on the two longest lines. Add the following blocks to the subsystem:
Library Simulink /Math Operations Simulink / Signal Routing Simulink / Math Operations Simulink / Logic and Bit Operations
Quantity 2 3 1 1
452
CHAPTER 3.
Logical Operator
Submatrix
Signal Processing Toolbox:Math Functions / Matrices and Linear Algebra / Matrix Operations or Signal Management / Indexing
Table 3.4
Figure 3.84
Selector5:
453
Figure 3.85
Selector4:
454
CHAPTER 3.
Figure 3.86
Selector3:
Vertices Matrix:
455
Figure 3.87
Draw Lane
456
CHAPTER 3.
Figure 3.88
457
Figure 3.89
Extraction
458
CHAPTER 3.
Figure 3.90
Rename the Line Detection to Lane Detection. Save the model as LaneDetection.mdl The model should look as follows:
459
Figure 3.91
Double Click the Lane Detection block. You may rename the blocks' names. It will look as follows:
460
CHAPTER 3.
Figure 3.92
Run your model. Running this gives you the images in Figure 7.
461
" 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/
462
CHAPTER 3.
Figure 3.95
Double-click the Task block and make the same changes as shown:
463
Figure 3.96
Double-Click the Lane Algorithm subsystem. Copy "Lane Detection and Tracking" block from "LaneDetection.mdl" into this model as shown.
464
CHAPTER 3.
Figure 3.97
465
Figure 3.98
466
CHAPTER 3.
Figure 3.99
467
Figure 3.100
468
CHAPTER 3.
Figure 3.101
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".
470
CHAPTER 3.
Figure 3.103
Double-click the Video Source block and make the same changes as shown:
471
Figure 3.104
472
CHAPTER 3.
Figure 3.105
Double-click the Display block, Double-click the Data Unpack block and Congure the "Byte Unpack" block as shown:
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;
474
CHAPTER 3.
% 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.
475
46 47 48 49
MATLAB Script for Real-Time Image Processing - EdgeDetectionPicturescript.m Simulink Model for Video Processing Simulation- EdgeDetectionVideo.mdl
50 51
Simulink Model for Real-Time Image Processing - EdgeDetectionPictureDSK6416.mdl MATLAB Script for Real-Time Video Processing - EdgeDetectionVideoscript.m Input Image - TMW2.jpg
53 54 55
Simulink Model for Real-Time Video Processing - EdgeDetectionVideoDM6437DVDP.mdl Input Video File - vipmem_Y.avi
52
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>
476
CHAPTER 3.
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
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.
478
CHAPTER 3.
Figure 3.110: The Edge Detection Block Conguration Window for the Canny Method
" 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/
479
You may repeat the simulation here to experiment the various algorithms with dierent thresholds.
3.4.3.2 Real-Time
1. Open the stills_R_W.mdl with the DSK6416
59 58
" 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 (EdgeDetectionPictureDSK6416.mdl).
58 http://cnx.org/Members/jfaing/m23996/stills_sim.mdl 59 http://cnx.org/content/m23996/latest/
480
CHAPTER 3.
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
60 http://cnx.org/Members/jfaing/module.2008-08-11.5404829390/EdgeDetectionPicturescript.m
481
Available for free at Connexions <http://cnx.org/content/col10713/1.1> (c) The Received Image(After Edge Detection)
482
CHAPTER 3.
4. Run the model. A single frame of the input and output video is shown in Figure 9.
483
You may repeat the simulation here to experiment the various algorithms with dierent thresholds.
3.4.4.2 Real-Time
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 61
(placed in the
module.).
61 http://cnx.org/content/m23999/latest/Video_R_W.mdl 62 http://cnx.org/content/m23999
484
CHAPTER 3.
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.
485
486
CHAPTER 3.
63 This
487
MATLAB
R2008a
64 65
68 69
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>
488
CHAPTER 3.
Figure 3.120
SAD
where:
A graph of the motion energy as a function of time. This graph displays the threshold value as well.
489
The Frame count of the recorded image An output signal triggered by motion detection (Trigger)
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.
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):
490
CHAPTER 3.
Functionality SAD
Block Subsystem
Quant. 1
Delay
Abs
Matrix Sum
Signal Processing Blockset / Math Functions / Matrices and Linear Algebra / Matrix Operations
Simulink tributes
Signal
At-
Add Sum,
Recording
Enabled Subsystem
Add Sum,
Delay
counter
Subsystem
Add Sum,
Delay
Generate data for motion energy and threshold display Compare Motion Energy
Matrix Concatenate
Relational Operator
against Threshold
491
Input Video
Display Control
Constant
Display Motion Energy and Threshold Draws formatted text on an image or video stream
Floating Scope
Simulink/Sinks
Insert Text
Video
and
Image
Pro-
Terminator
Simulink/Sinks
To Video Display
Video
and
Image
Pro-
492
CHAPTER 3.
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
493
Figure 3.124
494
CHAPTER 3.
Figure 3.125
4. Congure the xed point mode of operation for the second Matrix Column Add block:
495
Figure 3.126
496
CHAPTER 3.
Table 3.7
Figure 3.127
497
Figure 3.128
Figure 3.129
498
CHAPTER 3.
Figure 3.130
Figure 3.131
6. The Floating Scope will be used to display the motion energy and the threshold
71
as a function of
71 The
threshold is changed upon a user command. The simultaneous display of the threshold and motion energy will enable
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.
500
CHAPTER 3.
Figure 3.133
501
Figure 3.134
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":
502
CHAPTER 3.
Figure 3.136
503
Current Frame
Recorded Frame
Table 3.8
504
CHAPTER 3.
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.
73
" 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/
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
506
CHAPTER 3.
Figure 3.140
Figure 3.141
507
Figure 3.142
14. Double-click the Surveillance Algorithm subsystem. 15. Congure the "Byte Unpack" block :
Figure 3.143
508
CHAPTER 3.
Figure 3.144
Figure 3.145
509
Figure 3.146
Figure 3.147
19. Connect the Video Frame Capture Motion Threshold block as shown:
510
CHAPTER 3.
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:
511
Table 3.9
Figure 3.149
512
CHAPTER 3.
Figure 3.150
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
514
CHAPTER 3.
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 :
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.
516
CHAPTER 3.
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
517
Figure 3.157
Figure 3.158
518
CHAPTER 3.
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
519
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:
520
CHAPTER 3.
Figure 3.161
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, The basic examples enable students to experiment with Video, Imaging, Communications and Control. development tools (hardware and software). Platforms used:
real-time DSP applications, showing how to create prototypes using the Mathworks and Texas Instruments Advanced level examples are also included, where the basic tools are integrated with external dedicated hardware and/or software modules. 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
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
Ex.
apples, 1
Acoustic Noise Cancellation, 2.1(109) AM, 2.2(148) Audio, 1.3(62), 2.3(191) Audio Eects, 2.5(244)
1.4(85), 2.2(148), 2.3(191), 2.5(244), 2.6(274), 2.7(300), 2.8(332), 3.1(375), 3.2(397), 3.5(486), 4(521) Motion Detection, 3.5(486) Motor Control, 1.2(34), 1.4(85) Multichannel, 2.3(191)
B C D
Burg, 2.7(300) Covariance, 2.7(300) Digital Video Development Platform, 3.2(397) DM6437, 3.2(397), 3.3(424), 3.4(475), 3.5(486) DSK6416, 3.1(375), 3.3(424), 3.4(475) 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) DSP, 2.1(109), 2.3(191), 2.4(223), 2.5(244), 4(521) DTMF, 2.4(223) DVDP, 3.2(397)
N P R S
Noise Reduction, 2.8(332) Periodogram, 2.7(300) Permanent Magnet Synchronous Motor, 1.4(85) Real-Time, 4(521) Reverberation, 2.5(244) Signal to Noise Measurement, 2.6(274) Simulation, 4(521) Simulink, 1.1(1), 1.2(34), 1.3(62), 1.4(85), 2.2(148), 2.3(191), 2.5(244), 2.6(274), 2.7(300), 2.8(332), 3.1(375), 3.2(397), 3.5(486), 4(521) Spectrum Estimation, 2.7(300) Surveillance, 3.5(486)
E H I L M
Echo, 2.5(244) Edge Detection, 3.4(475) Hough Transform, 3.3(424) Image Processing, 3.1(375), 3.3(424), 3.4(475) Lane Detection, 3.3(424) Line Detection, 3.3(424), 3.4(475) LMS, 2.1(109) MATLAB, 1.1(1), 1.2(34), 1.3(62),
TLV320AIC24, 2.3(191) TMS320C6713, 2.3(191) TMS320F2808, 1.3(62) TMS320F2812, 1.4(85) TMS32F2812, 1.1(1)
W Wavelet, 2.8(332)
ATTRIBUTIONS
523
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/
524 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>
ATTRIBUTIONS
ATTRIBUTIONS
525
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/
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
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.