Amplitude Modulation
Introduction
This chapter presents the use of the DSK6713 to demonstrate the features of Amplitude Modulation (AM) transmission and reception. The model runs in real-time and enables the use to select:
- The AM algorithm
- The transmission and reception parameters (modulation index and carrier frequency).
The process comprises:
- Creating a simulation model (not R-T) for the AM transmitter/receiver.
- Migration to Real-time of the Simulation Model
- Building a Graphic Users Interface (GUI) to operate the real-time implementation.
Related Files
- Powerpoint Presentation - Amplitude Modulation.ppt
- Simulink Model for Simulation - AM_Simulation.mdl
- MATLAB GUI for Real-Time - AM.fig
- GUI m-fileAM.m
- m-file for Selection of AM Reception ChangeModel.m
- Simulink Model for Coherent Detection AM_Coherent.mdl
- Simulink Model for Square Root (SQRT) Detection AM_Sqrt.mdl
- Configurable Carrier Simulink Model Configurable_Carrier.mdl
Simulation
The Environment
Figure 1 shows the data flow for the AM modulation simulation. The AM modulation model receives an input signal from an external signal generator, modulates it and displays the modulation on the scope.
The Procedure
Building the Transmitter
The basic modulation mathematical description is given by:
y(t)=[1+m(t)]cos(2πfct) | |
Where: | |
cos(2πfct) | - The carrier signal |
m(t) | - The modulation index |
- Start by creating a new model in Simulink ®
- Open the Simulink library browser and add the DSP sine-wave to your model. This blocks will represent the information signal m(t).
- Configure the Sine Wave Generator Block (Double click on the DSP sine object). Set the sine frequency to 1000 Hz, sample time to 1/96000, samples per frame to 64 and close the box, and change its label to “information”.
- Use the same block to create the carrier signal. You may copy the block already created or select it form the Simulink library. Set the carrier frequency to 15,000 Hz. The remaining parameters are identical to the ones of the information signal. Change its label to “carrier”
- Add new DSP-constant to your model:
- Double-click on the constant object and set its constant value to 1.5:
- Add a new adder object from:
- Add a new multiplexer from the same directory as the adder (choose “product”).
- Add a new scope object:
- Set the number of frames parameter to 5. This parameter determines the horizontal scaling of the presented signal.
- Place the objects in the following way:
- Run the model, pause the simulation and activate the scope window. The modulated signal should be displayed as follows:
The AM Receiver (Square Root Demodulator)
In this section you will create the model for an AM receiver based on Square Root (SQRT) demodulation. The principle of operation is shown Figure 1.
- Add the new math function block to your model. This block can be configured to implement various mathematical functions.
- Configure the block to calculate the square:
- 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 filter design block. This block enables you to design filters using the MATLAB® FDATool.
- Configure the filter to be Low-Pass Filter. Since the carrier frequency (fc) is 15 KHz and the maximal frequency of the information is 1 KHz, the filter will be designed to pass frequencies below 5 KHz, and rejects frequencies higher than 10 KHz (please refer to Figure 16).
- Add a "Multiplier" and a "Subtract"1 block.
- Add two "DSP Constant" blocks.
- Add the matrices concatenation object. This object will enable the modulated and the de-modulated signals to be displayed simultaneously in the scope:
- The blocks should be connected as shown in Figure 18.
- Run the simulation (push the “play” button). Double click on the scope. Scale the display to fit the scope window (Choose from the menus: Axes=>Autoscale). Choose a different color for each signal (Please refer to Figure 19).
You should get the signals presented bellow:
- You may change the simulation parameters, and check their influence.
Real Time Implementation
The Environment
The real-time implementation model will be created upon the simulation model, after the following changes:
- The signal generator block will be replaced by the CODEC of the DSK6713
- The virtual scope will be replaced also by the CODEC
- A target definition block (DSK6713) will be added.
Figure 21 shows the block-diagram for the real time implementation.
Equipment Used (shown in Figure 22):
- DSK6713
- Dual Channel Oscilloscope
- Signal Generator
We have 4 signals (4 cables):
- Information- the signal to be modulated
- Modulated- the DSK creates a modulation of the given information
- Feedback- since the transmitter and the receiver are running on the same platform, we need to perform a loopback from the transmitter to the receiver and this is exactly the feedback signal, the modulated signal that is broadcasted by the transmitter and used as input for the receiver.
- Demodulated- the signal that the receiver outputs after the demodulation process.
The Procedure
- Open the model created in the previous chapter
- 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:
- Add the multi-port selector, in order to split the stereo input.
- 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.
- Configure the ADC and DAC blocks to a sampling rate to 96 KHZ and 16-bit samples.
- The final model should look as follows:
- You should configure the DSP constants as shown in Figure 28. The frame period for all constants should be -1
- 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.
Model Extensions
In this section we will extend the functionality of the example. Adding two more features:
- A variable frequency carrier generator (Please refer to secion "A Configurable Carrier Wave Generator" in the Appendix)
- An additional model for AM detection (Please refer to secion "The Coherent Detector (in brief)" in the Appendix).
- Build GUI that we will enable:
- Changing the modulation index
- Changing the carrier frequency
- Selecting the detection scheme
The modulation index and carrier frequency will be changed through RTDX.
- Open the model created in the previous section
- Replace the constant modulation index by an RTDX input (Please refer to Figure 30), and name it InputModulation.
- Configure the RTDX input object to the values described bellow:
- Replace the sine wave block used for the carrier by the configurable carrier blocks (you may find them in the Configurable_Carrier.mdl file)2, and create a subsystem for the carrier generator as shown in Figure 32.
Your model should look as shown in Figure 33.
Figure 32 – Inserting a Configurable Carrier
- Enter the Configuration Parameters menu (ctrl+E). Choose Real-Time Workshop=>TIC6000 Code-Generator, In The Run-Time box change the Build Action to “Build”3:
Push the OK button and close the “Configuration Parameters” window.
Rebuild *.out file using ctrl+B.
- Open the AM_Coherent.mdl file, and repeat step for this file.
You now have two load files each one corresponding to a different AM scheme.
Creating the GUI
- Open a new GUI (Enter GUIDE in the MATLAB command line)
- Add 2 sliders and one list box to the GUI, so it would look like:
- Now, double click on the list-box and change the string field:
Change the string field to:
Coherent
SQRT
- In the Modulation index slider set: Min=0.75, Max=1.5.
- In the Carrier Frequency slider set: Min=1, Max=4.
- Press the “play” button so you can save your GUI and open the GUI script m-file.
The script file
In the script we have to perform the following tasks:
- When the GUI is launched the DSK should be loaded with a default model (SQRT)
- When the user selects a new model> Its correspondent *.out file should be loaded to the DSP.
- When the modulation index is changed, its new value should be written to the DSP through the correspondent RTDX channel.
- When the carrier frequency modulation index is changed, its new value should be written to the DSP through the correspondent RTDX channel.
The following steps describe this implementation.
- The initialization routine “AM_OpeningFcn”:
function AM_OpeningFcn(hObject, eventdata, handles, varargin) last_model=1; handles.last_model=last_model; modelName = gcs; %connect to the board CCS_Obj = connectToCCS(modelName); % Identify RTDX channel names/modes chan_struct(1).name = 'InputModulation'; chan_struct(1).mode = 'w'; chan_struct(2).name = 'freq'; chan_struct(2).mode = 'w'; handles.rtdx_chan1=chan_struct(1); handles.rtdx_chan2=chan_struct(2); % Identify RTDX host buffer parameters RTDX_config_struct.Buffsize= 32768; RTDX_config_struct.Nbuffers = 4; RTDX_config_struct.Mode = 'continuous'; %building the full path of the file to be loaded CodegenDir = fullfile(pwd, ['AM_Coherent' '_c6000_rtw']); OutFile = fullfile(CodegenDir, ['AM_Coherent' '.out']); %Load is needed for rtdx setup CCS_Obj.load(OutFile,20); % Set up RTDX r = setupRTDX(CCS_Obj, chan_struct, RTDX_config_struct); handles.pipe=r; handles.CCS_Obj=CCS_Obj; %last_x and last_y are the initial values of %the Index and the carrier respectively last_x=1; last_y=15000; handles.last_x=last_x; handles.last_y=last_y; handles.output = hObject; % Enable all RTDX channels r.enable('all'); % Update handles structure guidata(hObject, handles); %use the change-model function in order to load the current model. %this function loads a model to the DSK after initiallization (= the code %above) ChangeModel(handles.last_model,handles.CCS_Obj,handles.pipe,handles.last_x,handles.last_y); )
- When you select a new model, the following code is invoked:
function listbox1_Callback(hObject, eventdata, handles) handles.last_model=get(hObject,'Value') ; ChangeModel(handles.last_model,handles.CCS_Obj,handles.pipe,handles.last_x,handles.last_y);
An external function (written in the ChangeModel.m file) will be used to select the model:
%1. halts the current model %2. free the rtdx channel %3. redefine the rtdx channel %4. loads the current model %5. binds the rtdx to the current model %6. run the CCS and enable the rtdx. %7.writes the last given index modulation to the rtdx %parameters: %m - flag that tells if the model is coherential or sqrt %CCS_Obj - the target %r_old - the old rtdx channel %last_x - to keep the current Index %last_y - to keep the current carrier frequency function r=ChangeModel(m,CCS_Obj,r_old,last_x,last_y) %halt the current model CCS_Obj.halt; %free the curent rtdx channel cleanupRTDX(CCS_Obj,r_old); %redefine the rtdx: chan_struct(1).name = 'InputModulation'; chan_struct(1).mode = 'w'; chan_struct(2).name = 'freq'; chan_struct(2).mode = 'w'; handles.rtdx_chan1=chan_struct(1); handles.rtdx_chan2=chan_struct(2); % Identify RTDX host buffer parameters RTDX_config_struct.Buffsize= 32768; RTDX_config_struct.Nbuffers = 4; RTDX_config_struct.Mode = 'continuous'; %reload the new model switch m case 1 model='AM_Coherent'; case 2 model='AM_Sqrt'; end CodegenDir = fullfile(pwd, [model '_c6000_rtw']); OutFile = fullfile(CodegenDir, [model '.out']); CCS_Obj.load(OutFile,20); % set up the new rtdx channel and run the target r = setupRTDX(CCS_Obj, chan_struct, RTDX_config_struct); CCS_Obj.run; r.enable('all'); % keep the last Index and carrier frequency: if last_x~=1 r.writemsg(chan_struct(2).name,1/last_x); end
- Changing the modulation index:
function slider1_Callback(hObject, eventdata, handles) last_x=handles.last_x; r=handles.pipe; x=single(get(hObject,'Value')); if or (ylast_y) %if the Index was changed: r.writemsg(handles.rtdx_chan1.name,1/x); %the Index increases when the added amplitude decreases %and thats the reason that we write 1/x to the rtdx handles.last_x=x; end guidata(hObject, handles);
- Changing the carrier frequency:
function slider2_Callback(hObject, eventdata, handles) last_y=handles.last_y; r=handles.pipe; y=single(get(hObject,'Value')); if or (ylast_y) r.writemsg(handles.rtdx_chan2.name,y); handles.last_y=y; end guidata(hObject, handles);
You may change the modulation index and frequency for both models, and observe its influence on the modulated and demodulated signals.
Appendix
A Configurable Carrier Wave Generator
The Simulink sine wave block cannot be configured during run-time; its frequency is a parameter that should be set in advance. We will introduce the implementation of a block where the frequency is a variable that can be set in real-time (In this case using RTDX). The block is based on the following relationship:
cosωct=Re[ejωct](1)
In the discrete case the following relationship applies:
cosωcnTs=cos2π
n=Re[ej2π
n](2)
fc |
fs |
fc |
fs |
The following model implements the last equation. Please note that a feedback path was included for phase continuity
The Coherent Detector (in brief)
The coherent detector principle of operation is in Figure 39. The AM example model (AM_Coherent.mdl) is shown in Figure 40.
MATLAB and Simulink are registered trademarks of The MathWorks, Inc. See www.mathworks.com/trademarks for a list of additional trademarks. Other product or brand names may be trademarks or registered trademarks of their respective holders.
FOOTNOTES
- The subtraction is created by reconfiguring the adder block, and choosing “+-“ instead of: “++”
- The principle of operation of the Configurable Carrier Module is described in the Appendix.
- The models will be loaded by the GUI script.
Amplitude Modulation
Introduction
This chapter presents the use of the DSK6713 to demonstrate the features of Amplitude Modulation (AM) transmission and reception. The model runs in real-time and enables the use to select:- The AM algorithm
- The transmission and reception parameters (modulation index and carrier frequency).
The process comprises:- Creating a simulation model (not R-T) for the AM transmitter/receiver.
- Migration to Real-time of the Simulation Model
- Building a Graphic Users Interface (GUI) to operate the real-time implementation.
Related Files
- Powerpoint Presentation - Amplitude Modulation.ppt
- Simulink Model for Simulation - AM_Simulation.mdl
- MATLAB GUI for Real-Time - AM.fig
- GUI m-fileAM.m
- m-file for Selection of AM Reception ChangeModel.m
- Simulink Model for Coherent Detection AM_Coherent.mdl
- Simulink Model for Square Root (SQRT) Detection AM_Sqrt.mdl
- Configurable Carrier Simulink Model Configurable_Carrier.mdl
Simulation
The Environment
Figure 1 shows the data flow for the AM modulation simulation. The AM modulation model receives an input signal from an external signal generator, modulates it and displays the modulation on the scope.Figure 1: Simulation Environment The Procedure
Building the Transmitter
The basic modulation mathematical description is given by:TABLE 1 y(t)=[1+m(t)]cos(2πfct) Where: cos(2πfct) - The carrier signal m(t) - The modulation index Figure 2: AM Transmission Principle - Start by creating a new model in Simulink ®
- Open the Simulink library browser and add the DSP sine-wave to your model. This blocks will represent the information signal m(t).
Figure 3: The Sine Wave Generator Block - Configure the Sine Wave Generator Block (Double click on the DSP sine object). Set the sine frequency to 1000 Hz, sample time to 1/96000, samples per frame to 64 and close the box, and change its label to “information”.
Figure 4: Information Signal Configuration Parameters - Use the same block to create the carrier signal. You may copy the block already created or select it form the Simulink library. Set the carrier frequency to 15,000 Hz. The remaining parameters are identical to the ones of the information signal. Change its label to “carrier”
- Add new DSP-constant to your model:
Figure 5: Adding a DSP constant - Double-click on the constant object and set its constant value to 1.5:
Figure 6: Set a constant value - Add a new adder object from:
Figure 7: Addes - Add a new multiplexer from the same directory as the adder (choose “product”).
- Add a new scope object:
Figure 8: Scope - Set the number of frames parameter to 5. This parameter determines the horizontal scaling of the presented signal.
Figure 9: Vector Scope Configuration - Place the objects in the following way:
Figure 10: The Transmitter Model - Run the model, pause the simulation and activate the scope window. The modulated signal should be displayed as follows:
Figure 11: AM Modulation Signal The AM Receiver (Square Root Demodulator)
In this section you will create the model for an AM receiver based on Square Root (SQRT) demodulation. The principle of operation is shown Figure 1.Figure 12: SQRT Demodulation Principle of Operation - Add the new math function block to your model. This block can be configured to implement various mathematical functions.
Figure 13: Square Function - Configure the block to calculate the square:
Figure 14: Select Math Function - Use the math function block to create the Square root function. You may retrieve it from the library or copy the “square” block.
- Add a digital filter design block. This block enables you to design filters using the MATLAB® FDATool.
Figure 15: Digital Filter Design - Configure the filter to be Low-Pass Filter. Since the carrier frequency (fc) is 15 KHz and the maximal frequency of the information is 1 KHz, the filter will be designed to pass frequencies below 5 KHz, and rejects frequencies higher than 10 KHz (please refer to Figure 16).
Figure 16: LPF Design Window - Add a "Multiplier" and a "Subtract"1 block.
- Add two "DSP Constant" blocks.
- Add the matrices concatenation object. This object will enable the modulated and the de-modulated signals to be displayed simultaneously in the scope:
Figure 17: Matrix Concatenate - The blocks should be connected as shown in Figure 18.
Figure 18: AM Simulation Model - Run the simulation (push the “play” button). Double click on the scope. Scale the display to fit the scope window (Choose from the menus: Axes=>Autoscale). Choose a different color for each signal (Please refer to Figure 19).
Figure 19: Displaying the Modulated and Demodulated Signals You should get the signals presented bellow:Figure 20: The Video Viewer Display - You may change the simulation parameters, and check their influence.
Real Time Implementation
The Environment
The real-time implementation model will be created upon the simulation model, after the following changes:- The signal generator block will be replaced by the CODEC of the DSK6713
- The virtual scope will be replaced also by the CODEC
- A target definition block (DSK6713) will be added.
Figure 21 shows the block-diagram for the real time implementation.Figure 21: Real Time Implementation Environment Equipment Used (shown in Figure 22):- DSK6713
- Dual Channel Oscilloscope
- Signal Generator
Figure 22: Equipment Used We have 4 signals (4 cables):- Information- the signal to be modulated
- Modulated- the DSK creates a modulation of the given information
- Feedback- since the transmitter and the receiver are running on the same platform, we need to perform a loopback from the transmitter to the receiver and this is exactly the feedback signal, the modulated signal that is broadcasted by the transmitter and used as input for the receiver.
- Demodulated- the signal that the receiver outputs after the demodulation process.
The Procedure
- Open the model created in the previous chapter
- Remove the scope and the “information” signal (the 1,000 Hz).
- Open the Simulink library browser and add the "C6713DSK".
Figure 23: The C6713DSK Block - Add the “Analog to Digital” and “Digital to Analog” converters (ADC and DAC) to your model:
Figure 24: A/D and D/A converters - Add the multi-port selector, in order to split the stereo input.
Figure 25: Multiport Selector - After placing the selector, double-click to open the dialog box and choose “columns” in the “select” label and “{1,2}” in the “indices to output label.
Figure 26: Multiport Configuration - Configure the ADC and DAC blocks to a sampling rate to 96 KHZ and 16-bit samples.
Figure 27: DAC and ADC Configuration - The final model should look as follows:
Figure 28: AM (SQRT) Real Time Model - You should configure the DSP constants as shown in Figure 28. The frame period for all constants should be -1
Figure 29: Constant Value Parameters - Build the project and load the program to the DSK memory using ctrl+B.
- Make sure that the signals generator amplitude is set to 1 Volt and frequency of [0.1,5] kHz.
- Display the modulated and demodulated signals in the scope.
Model Extensions
In this section we will extend the functionality of the example. Adding two more features:- A variable frequency carrier generator (Please refer to secion "A Configurable Carrier Wave Generator" in the Appendix)
- An additional model for AM detection (Please refer to secion "The Coherent Detector (in brief)" in the Appendix).
- Build GUI that we will enable:
- Changing the modulation index
- Changing the carrier frequency
- Selecting the detection scheme
The modulation index and carrier frequency will be changed through RTDX.- Open the model created in the previous section
- Replace the constant modulation index by an RTDX input (Please refer to Figure 30), and name it InputModulation.
Figure 30: RTDX input - Configure the RTDX input object to the values described bellow:
Figure 31: RTDX Input Configuration - Replace the sine wave block used for the carrier by the configurable carrier blocks (you may find them in the Configurable_Carrier.mdl file)2, and create a subsystem for the carrier generator as shown in Figure 32.
Your model should look as shown in Figure 33.Figure 32: Inserting a Configurable Carrier Figure 32 – Inserting a Configurable CarrierFigure 33: AM (SQRT) Model with Configurable Carrier - Enter the Configuration Parameters menu (ctrl+E). Choose Real-Time Workshop=>TIC6000 Code-Generator, In The Run-Time box change the Build Action to “Build”3:
Figure 34: Simulation Parameters Push the OK button and close the “Configuration Parameters” window.Rebuild *.out file using ctrl+B.- Open the AM_Coherent.mdl file, and repeat step for this file.
You now have two load files each one corresponding to a different AM scheme.Creating the GUI
- Open a new GUI (Enter GUIDE in the MATLAB command line)
- Add 2 sliders and one list box to the GUI, so it would look like:
Figure 35: GUI Design Screen - Now, double click on the list-box and change the string field:
Figure 36: List Box Configuration Screen Change the string field to:CoherentSQRT- 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-file.
The script file
In the script we have to perform the following tasks:- When the GUI is launched the DSK should be loaded with a default model (SQRT)
- When the user selects a new model> Its correspondent *.out file should be loaded to the DSP.
- When the modulation index is changed, its new value should be written to the DSP through the correspondent RTDX channel.
- When the carrier frequency modulation index is changed, its new value should be written to the DSP through the correspondent RTDX channel.
The following steps describe this implementation.- The initialization routine “AM_OpeningFcn”:
function AM_OpeningFcn(hObject, eventdata, handles, varargin) last_model=1; handles.last_model=last_model; modelName = gcs; %connect to the board CCS_Obj = connectToCCS(modelName); % Identify RTDX channel names/modes chan_struct(1).name = 'InputModulation'; chan_struct(1).mode = 'w'; chan_struct(2).name = 'freq'; chan_struct(2).mode = 'w'; handles.rtdx_chan1=chan_struct(1); handles.rtdx_chan2=chan_struct(2); % Identify RTDX host buffer parameters RTDX_config_struct.Buffsize= 32768; RTDX_config_struct.Nbuffers = 4; RTDX_config_struct.Mode = 'continuous'; %building the full path of the file to be loaded CodegenDir = fullfile(pwd, ['AM_Coherent' '_c6000_rtw']); OutFile = fullfile(CodegenDir, ['AM_Coherent' '.out']); %Load is needed for rtdx setup CCS_Obj.load(OutFile,20); % Set up RTDX r = setupRTDX(CCS_Obj, chan_struct, RTDX_config_struct); handles.pipe=r; handles.CCS_Obj=CCS_Obj; %last_x and last_y are the initial values of %the Index and the carrier respectively last_x=1; last_y=15000; handles.last_x=last_x; handles.last_y=last_y; handles.output = hObject; % Enable all RTDX channels r.enable('all'); % Update handles structure guidata(hObject, handles); %use the change-model function in order to load the current model. %this function loads a model to the DSK after initiallization (= the code %above) ChangeModel(handles.last_model,handles.CCS_Obj,handles.pipe,handles.last_x,handles.last_y); )
- When you select a new model, the following code is invoked:
function listbox1_Callback(hObject, eventdata, handles) handles.last_model=get(hObject,'Value') ; ChangeModel(handles.last_model,handles.CCS_Obj,handles.pipe,handles.last_x,handles.last_y);
An external function (written in the ChangeModel.m file) will be used to select the model:%1. halts the current model %2. free the rtdx channel %3. redefine the rtdx channel %4. loads the current model %5. binds the rtdx to the current model %6. run the CCS and enable the rtdx. %7.writes the last given index modulation to the rtdx %parameters: %m - flag that tells if the model is coherential or sqrt %CCS_Obj - the target %r_old - the old rtdx channel %last_x - to keep the current Index %last_y - to keep the current carrier frequency function r=ChangeModel(m,CCS_Obj,r_old,last_x,last_y) %halt the current model CCS_Obj.halt; %free the curent rtdx channel cleanupRTDX(CCS_Obj,r_old); %redefine the rtdx: chan_struct(1).name = 'InputModulation'; chan_struct(1).mode = 'w'; chan_struct(2).name = 'freq'; chan_struct(2).mode = 'w'; handles.rtdx_chan1=chan_struct(1); handles.rtdx_chan2=chan_struct(2); % Identify RTDX host buffer parameters RTDX_config_struct.Buffsize= 32768; RTDX_config_struct.Nbuffers = 4; RTDX_config_struct.Mode = 'continuous'; %reload the new model switch m case 1 model='AM_Coherent'; case 2 model='AM_Sqrt'; end CodegenDir = fullfile(pwd, [model '_c6000_rtw']); OutFile = fullfile(CodegenDir, [model '.out']); CCS_Obj.load(OutFile,20); % set up the new rtdx channel and run the target r = setupRTDX(CCS_Obj, chan_struct, RTDX_config_struct); CCS_Obj.run; r.enable('all'); % keep the last Index and carrier frequency: if last_x~=1 r.writemsg(chan_struct(2).name,1/last_x); end
- Changing the modulation index:
function slider1_Callback(hObject, eventdata, handles) last_x=handles.last_x; r=handles.pipe; x=single(get(hObject,'Value')); if or (y
last_y) %if the Index was changed: r.writemsg(handles.rtdx_chan1.name,1/x); %the Index increases when the added amplitude decreases %and thats the reason that we write 1/x to the rtdx handles.last_x=x; end guidata(hObject, handles); - Changing the carrier frequency:
function slider2_Callback(hObject, eventdata, handles) last_y=handles.last_y; r=handles.pipe; y=single(get(hObject,'Value')); if or (y
last_y) r.writemsg(handles.rtdx_chan2.name,y); handles.last_y=y; end guidata(hObject, handles); Figure 37: AM Model Graphic User Interface You may change the modulation index and frequency for both models, and observe its influence on the modulated and demodulated signals.Appendix
A Configurable Carrier Wave Generator
The Simulink sine wave block cannot be configured during run-time; its frequency is a parameter that should be set in advance. We will introduce the implementation of a block where the frequency is a variable that can be set in real-time (In this case using RTDX). The block is based on the following relationship:cosωct=Re[ejωct](1)In the discrete case the following relationship applies:cosωcnTs=cos2πfc fs fc fs The following model implements the last equation. Please note that a feedback path was included for phase continuityFigure 38: Carrier Wave Generator The Coherent Detector (in brief)
The coherent detector principle of operation is in Figure 39. The AM example model (AM_Coherent.mdl) is shown in Figure 40.Figure 39: Coherent SQRT Demodulation Principle of Operation Figure 40: Amplitude Modulation Example with Coherent Detection MATLAB and Simulink are registered trademarks of The MathWorks, Inc. See www.mathworks.com/trademarks for a list of additional trademarks. Other product or brand names may be trademarks or registered trademarks of their respective holders.FOOTNOTES
- The subtraction is created by reconfiguring the adder block, and choosing “+-“ instead of: “++”
- The principle of operation of the Configurable Carrier Module is described in the Appendix.
- The models will be loaded by the GUI script.
Amplitude Modulation
Introduction
This chapter presents the use of the DSK6713 to demonstrate the features of Amplitude Modulation (AM) transmission and reception. The model runs in real-time and enables the use to select:- The AM algorithm
- The transmission and reception parameters (modulation index and carrier frequency).
The process comprises:- Creating a simulation model (not R-T) for the AM transmitter/receiver.
- Migration to Real-time of the Simulation Model
- Building a Graphic Users Interface (GUI) to operate the real-time implementation.
Related Files
- Powerpoint Presentation - Amplitude Modulation.ppt
- Simulink Model for Simulation - AM_Simulation.mdl
- MATLAB GUI for Real-Time - AM.fig
- GUI m-fileAM.m
- m-file for Selection of AM Reception ChangeModel.m
- Simulink Model for Coherent Detection AM_Coherent.mdl
- Simulink Model for Square Root (SQRT) Detection AM_Sqrt.mdl
- Configurable Carrier Simulink Model Configurable_Carrier.mdl
Simulation
The Environment
Figure 1 shows the data flow for the AM modulation simulation. The AM modulation model receives an input signal from an external signal generator, modulates it and displays the modulation on the scope.Figure 1: Simulation Environment The Procedure
Building the Transmitter
The basic modulation mathematical description is given by:TABLE 1 y(t)=[1+m(t)]cos(2πfct) Where: cos(2πfct) - The carrier signal m(t) - The modulation index Figure 2: AM Transmission Principle - Start by creating a new model in Simulink ®
- Open the Simulink library browser and add the DSP sine-wave to your model. This blocks will represent the information signal m(t).
Figure 3: The Sine Wave Generator Block - Configure the Sine Wave Generator Block (Double click on the DSP sine object). Set the sine frequency to 1000 Hz, sample time to 1/96000, samples per frame to 64 and close the box, and change its label to “information”.
Figure 4: Information Signal Configuration Parameters - Use the same block to create the carrier signal. You may copy the block already created or select it form the Simulink library. Set the carrier frequency to 15,000 Hz. The remaining parameters are identical to the ones of the information signal. Change its label to “carrier”
- Add new DSP-constant to your model:
Figure 5: Adding a DSP constant - Double-click on the constant object and set its constant value to 1.5:
Figure 6: Set a constant value - Add a new adder object from:
Figure 7: Addes - Add a new multiplexer from the same directory as the adder (choose “product”).
- Add a new scope object:
Figure 8: Scope - Set the number of frames parameter to 5. This parameter determines the horizontal scaling of the presented signal.
Figure 9: Vector Scope Configuration - Place the objects in the following way:
Figure 10: The Transmitter Model - Run the model, pause the simulation and activate the scope window. The modulated signal should be displayed as follows:
Figure 11: AM Modulation Signal The AM Receiver (Square Root Demodulator)
In this section you will create the model for an AM receiver based on Square Root (SQRT) demodulation. The principle of operation is shown Figure 1.Figure 12: SQRT Demodulation Principle of Operation - Add the new math function block to your model. This block can be configured to implement various mathematical functions.
Figure 13: Square Function - Configure the block to calculate the square:
Figure 14: Select Math Function - Use the math function block to create the Square root function. You may retrieve it from the library or copy the “square” block.
- Add a digital filter design block. This block enables you to design filters using the MATLAB® FDATool.
Figure 15: Digital Filter Design - Configure the filter to be Low-Pass Filter. Since the carrier frequency (fc) is 15 KHz and the maximal frequency of the information is 1 KHz, the filter will be designed to pass frequencies below 5 KHz, and rejects frequencies higher than 10 KHz (please refer to Figure 16).
Figure 16: LPF Design Window - Add a "Multiplier" and a "Subtract"1 block.
- Add two "DSP Constant" blocks.
- Add the matrices concatenation object. This object will enable the modulated and the de-modulated signals to be displayed simultaneously in the scope:
Figure 17: Matrix Concatenate - The blocks should be connected as shown in Figure 18.
Figure 18: AM Simulation Model - Run the simulation (push the “play” button). Double click on the scope. Scale the display to fit the scope window (Choose from the menus: Axes=>Autoscale). Choose a different color for each signal (Please refer to Figure 19).
Figure 19: Displaying the Modulated and Demodulated Signals You should get the signals presented bellow:Figure 20: The Video Viewer Display - You may change the simulation parameters, and check their influence.
Real Time Implementation
The Environment
The real-time implementation model will be created upon the simulation model, after the following changes:- The signal generator block will be replaced by the CODEC of the DSK6713
- The virtual scope will be replaced also by the CODEC
- A target definition block (DSK6713) will be added.
Figure 21 shows the block-diagram for the real time implementation.Figure 21: Real Time Implementation Environment Equipment Used (shown in Figure 22):- DSK6713
- Dual Channel Oscilloscope
- Signal Generator
Figure 22: Equipment Used We have 4 signals (4 cables):- Information- the signal to be modulated
- Modulated- the DSK creates a modulation of the given information
- Feedback- since the transmitter and the receiver are running on the same platform, we need to perform a loopback from the transmitter to the receiver and this is exactly the feedback signal, the modulated signal that is broadcasted by the transmitter and used as input for the receiver.
- Demodulated- the signal that the receiver outputs after the demodulation process.
The Procedure
- Open the model created in the previous chapter
- Remove the scope and the “information” signal (the 1,000 Hz).
- Open the Simulink library browser and add the "C6713DSK".
Figure 23: The C6713DSK Block - Add the “Analog to Digital” and “Digital to Analog” converters (ADC and DAC) to your model:
Figure 24: A/D and D/A converters - Add the multi-port selector, in order to split the stereo input.
Figure 25: Multiport Selector - After placing the selector, double-click to open the dialog box and choose “columns” in the “select” label and “{1,2}” in the “indices to output label.
Figure 26: Multiport Configuration - Configure the ADC and DAC blocks to a sampling rate to 96 KHZ and 16-bit samples.
Figure 27: DAC and ADC Configuration - The final model should look as follows:
Figure 28: AM (SQRT) Real Time Model - You should configure the DSP constants as shown in Figure 28. The frame period for all constants should be -1
Figure 29: Constant Value Parameters - Build the project and load the program to the DSK memory using ctrl+B.
- Make sure that the signals generator amplitude is set to 1 Volt and frequency of [0.1,5] kHz.
- Display the modulated and demodulated signals in the scope.
Model Extensions
In this section we will extend the functionality of the example. Adding two more features:- A variable frequency carrier generator (Please refer to secion "A Configurable Carrier Wave Generator" in the Appendix)
- An additional model for AM detection (Please refer to secion "The Coherent Detector (in brief)" in the Appendix).
- Build GUI that we will enable:
- Changing the modulation index
- Changing the carrier frequency
- Selecting the detection scheme
The modulation index and carrier frequency will be changed through RTDX.- Open the model created in the previous section
- Replace the constant modulation index by an RTDX input (Please refer to Figure 30), and name it InputModulation.
Figure 30: RTDX input - Configure the RTDX input object to the values described bellow:
Figure 31: RTDX Input Configuration - Replace the sine wave block used for the carrier by the configurable carrier blocks (you may find them in the Configurable_Carrier.mdl file)2, and create a subsystem for the carrier generator as shown in Figure 32.
Your model should look as shown in Figure 33.Figure 32: Inserting a Configurable Carrier Figure 32 – Inserting a Configurable CarrierFigure 33: AM (SQRT) Model with Configurable Carrier - Enter the Configuration Parameters menu (ctrl+E). Choose Real-Time Workshop=>TIC6000 Code-Generator, In The Run-Time box change the Build Action to “Build”3:
Figure 34: Simulation Parameters Push the OK button and close the “Configuration Parameters” window.Rebuild *.out file using ctrl+B.- Open the AM_Coherent.mdl file, and repeat step for this file.
You now have two load files each one corresponding to a different AM scheme.Creating the GUI
- Open a new GUI (Enter GUIDE in the MATLAB command line)
- Add 2 sliders and one list box to the GUI, so it would look like:
Figure 35: GUI Design Screen - Now, double click on the list-box and change the string field:
Figure 36: List Box Configuration Screen Change the string field to:CoherentSQRT- 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-file.
The script file
In the script we have to perform the following tasks:- When the GUI is launched the DSK should be loaded with a default model (SQRT)
- When the user selects a new model> Its correspondent *.out file should be loaded to the DSP.
- When the modulation index is changed, its new value should be written to the DSP through the correspondent RTDX channel.
- When the carrier frequency modulation index is changed, its new value should be written to the DSP through the correspondent RTDX channel.
The following steps describe this implementation.- The initialization routine “AM_OpeningFcn”:
function AM_OpeningFcn(hObject, eventdata, handles, varargin) last_model=1; handles.last_model=last_model; modelName = gcs; %connect to the board CCS_Obj = connectToCCS(modelName); % Identify RTDX channel names/modes chan_struct(1).name = 'InputModulation'; chan_struct(1).mode = 'w'; chan_struct(2).name = 'freq'; chan_struct(2).mode = 'w'; handles.rtdx_chan1=chan_struct(1); handles.rtdx_chan2=chan_struct(2); % Identify RTDX host buffer parameters RTDX_config_struct.Buffsize= 32768; RTDX_config_struct.Nbuffers = 4; RTDX_config_struct.Mode = 'continuous'; %building the full path of the file to be loaded CodegenDir = fullfile(pwd, ['AM_Coherent' '_c6000_rtw']); OutFile = fullfile(CodegenDir, ['AM_Coherent' '.out']); %Load is needed for rtdx setup CCS_Obj.load(OutFile,20); % Set up RTDX r = setupRTDX(CCS_Obj, chan_struct, RTDX_config_struct); handles.pipe=r; handles.CCS_Obj=CCS_Obj; %last_x and last_y are the initial values of %the Index and the carrier respectively last_x=1; last_y=15000; handles.last_x=last_x; handles.last_y=last_y; handles.output = hObject; % Enable all RTDX channels r.enable('all'); % Update handles structure guidata(hObject, handles); %use the change-model function in order to load the current model. %this function loads a model to the DSK after initiallization (= the code %above) ChangeModel(handles.last_model,handles.CCS_Obj,handles.pipe,handles.last_x,handles.last_y); )
- When you select a new model, the following code is invoked:
function listbox1_Callback(hObject, eventdata, handles) handles.last_model=get(hObject,'Value') ; ChangeModel(handles.last_model,handles.CCS_Obj,handles.pipe,handles.last_x,handles.last_y);
An external function (written in the ChangeModel.m file) will be used to select the model:%1. halts the current model %2. free the rtdx channel %3. redefine the rtdx channel %4. loads the current model %5. binds the rtdx to the current model %6. run the CCS and enable the rtdx. %7.writes the last given index modulation to the rtdx %parameters: %m - flag that tells if the model is coherential or sqrt %CCS_Obj - the target %r_old - the old rtdx channel %last_x - to keep the current Index %last_y - to keep the current carrier frequency function r=ChangeModel(m,CCS_Obj,r_old,last_x,last_y) %halt the current model CCS_Obj.halt; %free the curent rtdx channel cleanupRTDX(CCS_Obj,r_old); %redefine the rtdx: chan_struct(1).name = 'InputModulation'; chan_struct(1).mode = 'w'; chan_struct(2).name = 'freq'; chan_struct(2).mode = 'w'; handles.rtdx_chan1=chan_struct(1); handles.rtdx_chan2=chan_struct(2); % Identify RTDX host buffer parameters RTDX_config_struct.Buffsize= 32768; RTDX_config_struct.Nbuffers = 4; RTDX_config_struct.Mode = 'continuous'; %reload the new model switch m case 1 model='AM_Coherent'; case 2 model='AM_Sqrt'; end CodegenDir = fullfile(pwd, [model '_c6000_rtw']); OutFile = fullfile(CodegenDir, [model '.out']); CCS_Obj.load(OutFile,20); % set up the new rtdx channel and run the target r = setupRTDX(CCS_Obj, chan_struct, RTDX_config_struct); CCS_Obj.run; r.enable('all'); % keep the last Index and carrier frequency: if last_x~=1 r.writemsg(chan_struct(2).name,1/last_x); end
- Changing the modulation index:
function slider1_Callback(hObject, eventdata, handles) last_x=handles.last_x; r=handles.pipe; x=single(get(hObject,'Value')); if or (y
last_y) %if the Index was changed: r.writemsg(handles.rtdx_chan1.name,1/x); %the Index increases when the added amplitude decreases %and thats the reason that we write 1/x to the rtdx handles.last_x=x; end guidata(hObject, handles); - Changing the carrier frequency:
function slider2_Callback(hObject, eventdata, handles) last_y=handles.last_y; r=handles.pipe; y=single(get(hObject,'Value')); if or (y
last_y) r.writemsg(handles.rtdx_chan2.name,y); handles.last_y=y; end guidata(hObject, handles); Figure 37: AM Model Graphic User Interface You may change the modulation index and frequency for both models, and observe its influence on the modulated and demodulated signals.Appendix
A Configurable Carrier Wave Generator
The Simulink sine wave block cannot be configured during run-time; its frequency is a parameter that should be set in advance. We will introduce the implementation of a block where the frequency is a variable that can be set in real-time (In this case using RTDX). The block is based on the following relationship:cosωct=Re[ejωct](1)In the discrete case the following relationship applies:cosωcnTs=cos2πfc fs fc fs The following model implements the last equation. Please note that a feedback path was included for phase continuityFigure 38: Carrier Wave Generator The Coherent Detector (in brief)
The coherent detector principle of operation is in Figure 39. The AM example model (AM_Coherent.mdl) is shown in Figure 40.Figure 39: Coherent SQRT Demodulation Principle of Operation Figure 40: Amplitude Modulation Example with Coherent Detection MATLAB and Simulink are registered trademarks of The MathWorks, Inc. See www.mathworks.com/trademarks for a list of additional trademarks. Other product or brand names may be trademarks or registered trademarks of their respective holders.FOOTNOTES
- The subtraction is created by reconfiguring the adder block, and choosing “+-“ instead of: “++”
- The principle of operation of the Configurable Carrier Module is described in the Appendix.
- The models will be loaded by the GUI script.
Amplitude Modulation
Introduction
This chapter presents the use of the DSK6713 to demonstrate the features of Amplitude Modulation (AM) transmission and reception. The model runs in real-time and enables the use to select:- The AM algorithm
- The transmission and reception parameters (modulation index and carrier frequency).
The process comprises:- Creating a simulation model (not R-T) for the AM transmitter/receiver.
- Migration to Real-time of the Simulation Model
- Building a Graphic Users Interface (GUI) to operate the real-time implementation.
Related Files
- Powerpoint Presentation - Amplitude Modulation.ppt
- Simulink Model for Simulation - AM_Simulation.mdl
- MATLAB GUI for Real-Time - AM.fig
- GUI m-fileAM.m
- m-file for Selection of AM Reception ChangeModel.m
- Simulink Model for Coherent Detection AM_Coherent.mdl
- Simulink Model for Square Root (SQRT) Detection AM_Sqrt.mdl
- Configurable Carrier Simulink Model Configurable_Carrier.mdl
Simulation
The Environment
Figure 1 shows the data flow for the AM modulation simulation. The AM modulation model receives an input signal from an external signal generator, modulates it and displays the modulation on the scope.Figure 1: Simulation Environment The Procedure
Building the Transmitter
The basic modulation mathematical description is given by:TABLE 1 y(t)=[1+m(t)]cos(2πfct) Where: cos(2πfct) - The carrier signal m(t) - The modulation index Figure 2: AM Transmission Principle - Start by creating a new model in Simulink ®
- Open the Simulink library browser and add the DSP sine-wave to your model. This blocks will represent the information signal m(t).
Figure 3: The Sine Wave Generator Block - Configure the Sine Wave Generator Block (Double click on the DSP sine object). Set the sine frequency to 1000 Hz, sample time to 1/96000, samples per frame to 64 and close the box, and change its label to “information”.
Figure 4: Information Signal Configuration Parameters - Use the same block to create the carrier signal. You may copy the block already created or select it form the Simulink library. Set the carrier frequency to 15,000 Hz. The remaining parameters are identical to the ones of the information signal. Change its label to “carrier”
- Add new DSP-constant to your model:
Figure 5: Adding a DSP constant - Double-click on the constant object and set its constant value to 1.5:
Figure 6: Set a constant value - Add a new adder object from:
Figure 7: Addes - Add a new multiplexer from the same directory as the adder (choose “product”).
- Add a new scope object:
Figure 8: Scope - Set the number of frames parameter to 5. This parameter determines the horizontal scaling of the presented signal.
Figure 9: Vector Scope Configuration - Place the objects in the following way:
Figure 10: The Transmitter Model - Run the model, pause the simulation and activate the scope window. The modulated signal should be displayed as follows:
Figure 11: AM Modulation Signal The AM Receiver (Square Root Demodulator)
In this section you will create the model for an AM receiver based on Square Root (SQRT) demodulation. The principle of operation is shown Figure 1.Figure 12: SQRT Demodulation Principle of Operation - Add the new math function block to your model. This block can be configured to implement various mathematical functions.
Figure 13: Square Function - Configure the block to calculate the square:
Figure 14: Select Math Function - Use the math function block to create the Square root function. You may retrieve it from the library or copy the “square” block.
- Add a digital filter design block. This block enables you to design filters using the MATLAB® FDATool.
Figure 15: Digital Filter Design - Configure the filter to be Low-Pass Filter. Since the carrier frequency (fc) is 15 KHz and the maximal frequency of the information is 1 KHz, the filter will be designed to pass frequencies below 5 KHz, and rejects frequencies higher than 10 KHz (please refer to Figure 16).
Figure 16: LPF Design Window - Add a "Multiplier" and a "Subtract"1 block.
- Add two "DSP Constant" blocks.
- Add the matrices concatenation object. This object will enable the modulated and the de-modulated signals to be displayed simultaneously in the scope:
Figure 17: Matrix Concatenate - The blocks should be connected as shown in Figure 18.
Figure 18: AM Simulation Model - Run the simulation (push the “play” button). Double click on the scope. Scale the display to fit the scope window (Choose from the menus: Axes=>Autoscale). Choose a different color for each signal (Please refer to Figure 19).
Figure 19: Displaying the Modulated and Demodulated Signals You should get the signals presented bellow:Figure 20: The Video Viewer Display - You may change the simulation parameters, and check their influence.
Real Time Implementation
The Environment
The real-time implementation model will be created upon the simulation model, after the following changes:- The signal generator block will be replaced by the CODEC of the DSK6713
- The virtual scope will be replaced also by the CODEC
- A target definition block (DSK6713) will be added.
Figure 21 shows the block-diagram for the real time implementation.Figure 21: Real Time Implementation Environment Equipment Used (shown in Figure 22):- DSK6713
- Dual Channel Oscilloscope
- Signal Generator
Figure 22: Equipment Used We have 4 signals (4 cables):- Information- the signal to be modulated
- Modulated- the DSK creates a modulation of the given information
- Feedback- since the transmitter and the receiver are running on the same platform, we need to perform a loopback from the transmitter to the receiver and this is exactly the feedback signal, the modulated signal that is broadcasted by the transmitter and used as input for the receiver.
- Demodulated- the signal that the receiver outputs after the demodulation process.
The Procedure
- Open the model created in the previous chapter
- Remove the scope and the “information” signal (the 1,000 Hz).
- Open the Simulink library browser and add the "C6713DSK".
Figure 23: The C6713DSK Block - Add the “Analog to Digital” and “Digital to Analog” converters (ADC and DAC) to your model:
Figure 24: A/D and D/A converters - Add the multi-port selector, in order to split the stereo input.
Figure 25: Multiport Selector - After placing the selector, double-click to open the dialog box and choose “columns” in the “select” label and “{1,2}” in the “indices to output label.
Figure 26: Multiport Configuration - Configure the ADC and DAC blocks to a sampling rate to 96 KHZ and 16-bit samples.
Figure 27: DAC and ADC Configuration - The final model should look as follows:
Figure 28: AM (SQRT) Real Time Model - You should configure the DSP constants as shown in Figure 28. The frame period for all constants should be -1
Figure 29: Constant Value Parameters - Build the project and load the program to the DSK memory using ctrl+B.
- Make sure that the signals generator amplitude is set to 1 Volt and frequency of [0.1,5] kHz.
- Display the modulated and demodulated signals in the scope.
Model Extensions
In this section we will extend the functionality of the example. Adding two more features:- A variable frequency carrier generator (Please refer to secion "A Configurable Carrier Wave Generator" in the Appendix)
- An additional model for AM detection (Please refer to secion "The Coherent Detector (in brief)" in the Appendix).
- Build GUI that we will enable:
- Changing the modulation index
- Changing the carrier frequency
- Selecting the detection scheme
The modulation index and carrier frequency will be changed through RTDX.- Open the model created in the previous section
- Replace the constant modulation index by an RTDX input (Please refer to Figure 30), and name it InputModulation.
Figure 30: RTDX input - Configure the RTDX input object to the values described bellow:
Figure 31: RTDX Input Configuration - Replace the sine wave block used for the carrier by the configurable carrier blocks (you may find them in the Configurable_Carrier.mdl file)2, and create a subsystem for the carrier generator as shown in Figure 32.
Your model should look as shown in Figure 33.Figure 32: Inserting a Configurable Carrier Figure 32 – Inserting a Configurable CarrierFigure 33: AM (SQRT) Model with Configurable Carrier - Enter the Configuration Parameters menu (ctrl+E). Choose Real-Time Workshop=>TIC6000 Code-Generator, In The Run-Time box change the Build Action to “Build”3:
Figure 34: Simulation Parameters Push the OK button and close the “Configuration Parameters” window.Rebuild *.out file using ctrl+B.- Open the AM_Coherent.mdl file, and repeat step for this file.
You now have two load files each one corresponding to a different AM scheme.Creating the GUI
- Open a new GUI (Enter GUIDE in the MATLAB command line)
- Add 2 sliders and one list box to the GUI, so it would look like:
Figure 35: GUI Design Screen - Now, double click on the list-box and change the string field:
Figure 36: List Box Configuration Screen Change the string field to:CoherentSQRT- 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-file.
The script file
In the script we have to perform the following tasks:- When the GUI is launched the DSK should be loaded with a default model (SQRT)
- When the user selects a new model> Its correspondent *.out file should be loaded to the DSP.
- When the modulation index is changed, its new value should be written to the DSP through the correspondent RTDX channel.
- When the carrier frequency modulation index is changed, its new value should be written to the DSP through the correspondent RTDX channel.
The following steps describe this implementation.- The initialization routine “AM_OpeningFcn”:
function AM_OpeningFcn(hObject, eventdata, handles, varargin) last_model=1; handles.last_model=last_model; modelName = gcs; %connect to the board CCS_Obj = connectToCCS(modelName); % Identify RTDX channel names/modes chan_struct(1).name = 'InputModulation'; chan_struct(1).mode = 'w'; chan_struct(2).name = 'freq'; chan_struct(2).mode = 'w'; handles.rtdx_chan1=chan_struct(1); handles.rtdx_chan2=chan_struct(2); % Identify RTDX host buffer parameters RTDX_config_struct.Buffsize= 32768; RTDX_config_struct.Nbuffers = 4; RTDX_config_struct.Mode = 'continuous'; %building the full path of the file to be loaded CodegenDir = fullfile(pwd, ['AM_Coherent' '_c6000_rtw']); OutFile = fullfile(CodegenDir, ['AM_Coherent' '.out']); %Load is needed for rtdx setup CCS_Obj.load(OutFile,20); % Set up RTDX r = setupRTDX(CCS_Obj, chan_struct, RTDX_config_struct); handles.pipe=r; handles.CCS_Obj=CCS_Obj; %last_x and last_y are the initial values of %the Index and the carrier respectively last_x=1; last_y=15000; handles.last_x=last_x; handles.last_y=last_y; handles.output = hObject; % Enable all RTDX channels r.enable('all'); % Update handles structure guidata(hObject, handles); %use the change-model function in order to load the current model. %this function loads a model to the DSK after initiallization (= the code %above) ChangeModel(handles.last_model,handles.CCS_Obj,handles.pipe,handles.last_x,handles.last_y); )
- When you select a new model, the following code is invoked:
function listbox1_Callback(hObject, eventdata, handles) handles.last_model=get(hObject,'Value') ; ChangeModel(handles.last_model,handles.CCS_Obj,handles.pipe,handles.last_x,handles.last_y);
An external function (written in the ChangeModel.m file) will be used to select the model:%1. halts the current model %2. free the rtdx channel %3. redefine the rtdx channel %4. loads the current model %5. binds the rtdx to the current model %6. run the CCS and enable the rtdx. %7.writes the last given index modulation to the rtdx %parameters: %m - flag that tells if the model is coherential or sqrt %CCS_Obj - the target %r_old - the old rtdx channel %last_x - to keep the current Index %last_y - to keep the current carrier frequency function r=ChangeModel(m,CCS_Obj,r_old,last_x,last_y) %halt the current model CCS_Obj.halt; %free the curent rtdx channel cleanupRTDX(CCS_Obj,r_old); %redefine the rtdx: chan_struct(1).name = 'InputModulation'; chan_struct(1).mode = 'w'; chan_struct(2).name = 'freq'; chan_struct(2).mode = 'w'; handles.rtdx_chan1=chan_struct(1); handles.rtdx_chan2=chan_struct(2); % Identify RTDX host buffer parameters RTDX_config_struct.Buffsize= 32768; RTDX_config_struct.Nbuffers = 4; RTDX_config_struct.Mode = 'continuous'; %reload the new model switch m case 1 model='AM_Coherent'; case 2 model='AM_Sqrt'; end CodegenDir = fullfile(pwd, [model '_c6000_rtw']); OutFile = fullfile(CodegenDir, [model '.out']); CCS_Obj.load(OutFile,20); % set up the new rtdx channel and run the target r = setupRTDX(CCS_Obj, chan_struct, RTDX_config_struct); CCS_Obj.run; r.enable('all'); % keep the last Index and carrier frequency: if last_x~=1 r.writemsg(chan_struct(2).name,1/last_x); end
- Changing the modulation index:
function slider1_Callback(hObject, eventdata, handles) last_x=handles.last_x; r=handles.pipe; x=single(get(hObject,'Value')); if or (y
last_y) %if the Index was changed: r.writemsg(handles.rtdx_chan1.name,1/x); %the Index increases when the added amplitude decreases %and thats the reason that we write 1/x to the rtdx handles.last_x=x; end guidata(hObject, handles); - Changing the carrier frequency:
function slider2_Callback(hObject, eventdata, handles) last_y=handles.last_y; r=handles.pipe; y=single(get(hObject,'Value')); if or (y
last_y) r.writemsg(handles.rtdx_chan2.name,y); handles.last_y=y; end guidata(hObject, handles); Figure 37: AM Model Graphic User Interface You may change the modulation index and frequency for both models, and observe its influence on the modulated and demodulated signals.Appendix
A Configurable Carrier Wave Generator
The Simulink sine wave block cannot be configured during run-time; its frequency is a parameter that should be set in advance. We will introduce the implementation of a block where the frequency is a variable that can be set in real-time (In this case using RTDX). The block is based on the following relationship:cosωct=Re[ejωct](1)In the discrete case the following relationship applies:cosωcnTs=cos2πfc fs fc fs The following model implements the last equation. Please note that a feedback path was included for phase continuityFigure 38: Carrier Wave Generator The Coherent Detector (in brief)
The coherent detector principle of operation is in Figure 39. The AM example model (AM_Coherent.mdl) is shown in Figure 40.Figure 39: Coherent SQRT Demodulation Principle of Operation Figure 40: Amplitude Modulation Example with Coherent Detection MATLAB and Simulink are registered trademarks of The MathWorks, Inc. See www.mathworks.com/trademarks for a list of additional trademarks. Other product or brand names may be trademarks or registered trademarks of their respective holders.FOOTNOTES
- The subtraction is created by reconfiguring the adder block, and choosing “+-“ instead of: “++”
- The principle of operation of the Configurable Carrier Module is described in the Appendix.
- The models will be loaded by the GUI script.
Amplitude Modulation
Introduction
This chapter presents the use of the DSK6713 to demonstrate the features of Amplitude Modulation (AM) transmission and reception. The model runs in real-time and enables the use to select:- The AM algorithm
- The transmission and reception parameters (modulation index and carrier frequency).
The process comprises:- Creating a simulation model (not R-T) for the AM transmitter/receiver.
- Migration to Real-time of the Simulation Model
- Building a Graphic Users Interface (GUI) to operate the real-time implementation.
Related Files
- Powerpoint Presentation - Amplitude Modulation.ppt
- Simulink Model for Simulation - AM_Simulation.mdl
- MATLAB GUI for Real-Time - AM.fig
- GUI m-fileAM.m
- m-file for Selection of AM Reception ChangeModel.m
- Simulink Model for Coherent Detection AM_Coherent.mdl
- Simulink Model for Square Root (SQRT) Detection AM_Sqrt.mdl
- Configurable Carrier Simulink Model Configurable_Carrier.mdl
Simulation
The Environment
Figure 1 shows the data flow for the AM modulation simulation. The AM modulation model receives an input signal from an external signal generator, modulates it and displays the modulation on the scope.Figure 1: Simulation Environment The Procedure
Building the Transmitter
The basic modulation mathematical description is given by:TABLE 1 y(t)=[1+m(t)]cos(2πfct) Where: cos(2πfct) - The carrier signal m(t) - The modulation index Figure 2: AM Transmission Principle - Start by creating a new model in Simulink ®
- Open the Simulink library browser and add the DSP sine-wave to your model. This blocks will represent the information signal m(t).
Figure 3: The Sine Wave Generator Block - Configure the Sine Wave Generator Block (Double click on the DSP sine object). Set the sine frequency to 1000 Hz, sample time to 1/96000, samples per frame to 64 and close the box, and change its label to “information”.
Figure 4: Information Signal Configuration Parameters - Use the same block to create the carrier signal. You may copy the block already created or select it form the Simulink library. Set the carrier frequency to 15,000 Hz. The remaining parameters are identical to the ones of the information signal. Change its label to “carrier”
- Add new DSP-constant to your model:
Figure 5: Adding a DSP constant - Double-click on the constant object and set its constant value to 1.5:
Figure 6: Set a constant value - Add a new adder object from:
Figure 7: Addes - Add a new multiplexer from the same directory as the adder (choose “product”).
- Add a new scope object:
Figure 8: Scope - Set the number of frames parameter to 5. This parameter determines the horizontal scaling of the presented signal.
Figure 9: Vector Scope Configuration - Place the objects in the following way:
Figure 10: The Transmitter Model - Run the model, pause the simulation and activate the scope window. The modulated signal should be displayed as follows:
Figure 11: AM Modulation Signal The AM Receiver (Square Root Demodulator)
In this section you will create the model for an AM receiver based on Square Root (SQRT) demodulation. The principle of operation is shown Figure 1.Figure 12: SQRT Demodulation Principle of Operation - Add the new math function block to your model. This block can be configured to implement various mathematical functions.
Figure 13: Square Function - Configure the block to calculate the square:
Figure 14: Select Math Function - Use the math function block to create the Square root function. You may retrieve it from the library or copy the “square” block.
- Add a digital filter design block. This block enables you to design filters using the MATLAB® FDATool.
Figure 15: Digital Filter Design - Configure the filter to be Low-Pass Filter. Since the carrier frequency (fc) is 15 KHz and the maximal frequency of the information is 1 KHz, the filter will be designed to pass frequencies below 5 KHz, and rejects frequencies higher than 10 KHz (please refer to Figure 16).
Figure 16: LPF Design Window - Add a "Multiplier" and a "Subtract"1 block.
- Add two "DSP Constant" blocks.
- Add the matrices concatenation object. This object will enable the modulated and the de-modulated signals to be displayed simultaneously in the scope:
Figure 17: Matrix Concatenate - The blocks should be connected as shown in Figure 18.
Figure 18: AM Simulation Model - Run the simulation (push the “play” button). Double click on the scope. Scale the display to fit the scope window (Choose from the menus: Axes=>Autoscale). Choose a different color for each signal (Please refer to Figure 19).
Figure 19: Displaying the Modulated and Demodulated Signals You should get the signals presented bellow:Figure 20: The Video Viewer Display - You may change the simulation parameters, and check their influence.
Real Time Implementation
The Environment
The real-time implementation model will be created upon the simulation model, after the following changes:- The signal generator block will be replaced by the CODEC of the DSK6713
- The virtual scope will be replaced also by the CODEC
- A target definition block (DSK6713) will be added.
Figure 21 shows the block-diagram for the real time implementation.Figure 21: Real Time Implementation Environment Equipment Used (shown in Figure 22):- DSK6713
- Dual Channel Oscilloscope
- Signal Generator
Figure 22: Equipment Used We have 4 signals (4 cables):- Information- the signal to be modulated
- Modulated- the DSK creates a modulation of the given information
- Feedback- since the transmitter and the receiver are running on the same platform, we need to perform a loopback from the transmitter to the receiver and this is exactly the feedback signal, the modulated signal that is broadcasted by the transmitter and used as input for the receiver.
- Demodulated- the signal that the receiver outputs after the demodulation process.
The Procedure
- Open the model created in the previous chapter
- Remove the scope and the “information” signal (the 1,000 Hz).
- Open the Simulink library browser and add the "C6713DSK".
Figure 23: The C6713DSK Block - Add the “Analog to Digital” and “Digital to Analog” converters (ADC and DAC) to your model:
Figure 24: A/D and D/A converters - Add the multi-port selector, in order to split the stereo input.
Figure 25: Multiport Selector - After placing the selector, double-click to open the dialog box and choose “columns” in the “select” label and “{1,2}” in the “indices to output label.
Figure 26: Multiport Configuration - Configure the ADC and DAC blocks to a sampling rate to 96 KHZ and 16-bit samples.
Figure 27: DAC and ADC Configuration - The final model should look as follows:
Figure 28: AM (SQRT) Real Time Model - You should configure the DSP constants as shown in Figure 28. The frame period for all constants should be -1
Figure 29: Constant Value Parameters - Build the project and load the program to the DSK memory using ctrl+B.
- Make sure that the signals generator amplitude is set to 1 Volt and frequency of [0.1,5] kHz.
- Display the modulated and demodulated signals in the scope.
Model Extensions
In this section we will extend the functionality of the example. Adding two more features:- A variable frequency carrier generator (Please refer to secion "A Configurable Carrier Wave Generator" in the Appendix)
- An additional model for AM detection (Please refer to secion "The Coherent Detector (in brief)" in the Appendix).
- Build GUI that we will enable:
- Changing the modulation index
- Changing the carrier frequency
- Selecting the detection scheme
The modulation index and carrier frequency will be changed through RTDX.- Open the model created in the previous section
- Replace the constant modulation index by an RTDX input (Please refer to Figure 30), and name it InputModulation.
Figure 30: RTDX input - Configure the RTDX input object to the values described bellow:
Figure 31: RTDX Input Configuration - Replace the sine wave block used for the carrier by the configurable carrier blocks (you may find them in the Configurable_Carrier.mdl file)2, and create a subsystem for the carrier generator as shown in Figure 32.
Your model should look as shown in Figure 33.Figure 32: Inserting a Configurable Carrier Figure 32 – Inserting a Configurable CarrierFigure 33: AM (SQRT) Model with Configurable Carrier - Enter the Configuration Parameters menu (ctrl+E). Choose Real-Time Workshop=>TIC6000 Code-Generator, In The Run-Time box change the Build Action to “Build”3:
Figure 34: Simulation Parameters Push the OK button and close the “Configuration Parameters” window.Rebuild *.out file using ctrl+B.- Open the AM_Coherent.mdl file, and repeat step for this file.
You now have two load files each one corresponding to a different AM scheme.Creating the GUI
- Open a new GUI (Enter GUIDE in the MATLAB command line)
- Add 2 sliders and one list box to the GUI, so it would look like:
Figure 35: GUI Design Screen - Now, double click on the list-box and change the string field:
Figure 36: List Box Configuration Screen Change the string field to:CoherentSQRT- 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-file.
The script file
In the script we have to perform the following tasks:- When the GUI is launched the DSK should be loaded with a default model (SQRT)
- When the user selects a new model> Its correspondent *.out file should be loaded to the DSP.
- When the modulation index is changed, its new value should be written to the DSP through the correspondent RTDX channel.
- When the carrier frequency modulation index is changed, its new value should be written to the DSP through the correspondent RTDX channel.
The following steps describe this implementation.- The initialization routine “AM_OpeningFcn”:
function AM_OpeningFcn(hObject, eventdata, handles, varargin) last_model=1; handles.last_model=last_model; modelName = gcs; %connect to the board CCS_Obj = connectToCCS(modelName); % Identify RTDX channel names/modes chan_struct(1).name = 'InputModulation'; chan_struct(1).mode = 'w'; chan_struct(2).name = 'freq'; chan_struct(2).mode = 'w'; handles.rtdx_chan1=chan_struct(1); handles.rtdx_chan2=chan_struct(2); % Identify RTDX host buffer parameters RTDX_config_struct.Buffsize= 32768; RTDX_config_struct.Nbuffers = 4; RTDX_config_struct.Mode = 'continuous'; %building the full path of the file to be loaded CodegenDir = fullfile(pwd, ['AM_Coherent' '_c6000_rtw']); OutFile = fullfile(CodegenDir, ['AM_Coherent' '.out']); %Load is needed for rtdx setup CCS_Obj.load(OutFile,20); % Set up RTDX r = setupRTDX(CCS_Obj, chan_struct, RTDX_config_struct); handles.pipe=r; handles.CCS_Obj=CCS_Obj; %last_x and last_y are the initial values of %the Index and the carrier respectively last_x=1; last_y=15000; handles.last_x=last_x; handles.last_y=last_y; handles.output = hObject; % Enable all RTDX channels r.enable('all'); % Update handles structure guidata(hObject, handles); %use the change-model function in order to load the current model. %this function loads a model to the DSK after initiallization (= the code %above) ChangeModel(handles.last_model,handles.CCS_Obj,handles.pipe,handles.last_x,handles.last_y); )
- When you select a new model, the following code is invoked:
function listbox1_Callback(hObject, eventdata, handles) handles.last_model=get(hObject,'Value') ; ChangeModel(handles.last_model,handles.CCS_Obj,handles.pipe,handles.last_x,handles.last_y);
An external function (written in the ChangeModel.m file) will be used to select the model:%1. halts the current model %2. free the rtdx channel %3. redefine the rtdx channel %4. loads the current model %5. binds the rtdx to the current model %6. run the CCS and enable the rtdx. %7.writes the last given index modulation to the rtdx %parameters: %m - flag that tells if the model is coherential or sqrt %CCS_Obj - the target %r_old - the old rtdx channel %last_x - to keep the current Index %last_y - to keep the current carrier frequency function r=ChangeModel(m,CCS_Obj,r_old,last_x,last_y) %halt the current model CCS_Obj.halt; %free the curent rtdx channel cleanupRTDX(CCS_Obj,r_old); %redefine the rtdx: chan_struct(1).name = 'InputModulation'; chan_struct(1).mode = 'w'; chan_struct(2).name = 'freq'; chan_struct(2).mode = 'w'; handles.rtdx_chan1=chan_struct(1); handles.rtdx_chan2=chan_struct(2); % Identify RTDX host buffer parameters RTDX_config_struct.Buffsize= 32768; RTDX_config_struct.Nbuffers = 4; RTDX_config_struct.Mode = 'continuous'; %reload the new model switch m case 1 model='AM_Coherent'; case 2 model='AM_Sqrt'; end CodegenDir = fullfile(pwd, [model '_c6000_rtw']); OutFile = fullfile(CodegenDir, [model '.out']); CCS_Obj.load(OutFile,20); % set up the new rtdx channel and run the target r = setupRTDX(CCS_Obj, chan_struct, RTDX_config_struct); CCS_Obj.run; r.enable('all'); % keep the last Index and carrier frequency: if last_x~=1 r.writemsg(chan_struct(2).name,1/last_x); end
- Changing the modulation index:
function slider1_Callback(hObject, eventdata, handles) last_x=handles.last_x; r=handles.pipe; x=single(get(hObject,'Value')); if or (y
last_y) %if the Index was changed: r.writemsg(handles.rtdx_chan1.name,1/x); %the Index increases when the added amplitude decreases %and thats the reason that we write 1/x to the rtdx handles.last_x=x; end guidata(hObject, handles); - Changing the carrier frequency:
function slider2_Callback(hObject, eventdata, handles) last_y=handles.last_y; r=handles.pipe; y=single(get(hObject,'Value')); if or (y
last_y) r.writemsg(handles.rtdx_chan2.name,y); handles.last_y=y; end guidata(hObject, handles); Figure 37: AM Model Graphic User Interface You may change the modulation index and frequency for both models, and observe its influence on the modulated and demodulated signals.Appendix
A Configurable Carrier Wave Generator
The Simulink sine wave block cannot be configured during run-time; its frequency is a parameter that should be set in advance. We will introduce the implementation of a block where the frequency is a variable that can be set in real-time (In this case using RTDX). The block is based on the following relationship:cosωct=Re[ejωct](1)In the discrete case the following relationship applies:cosωcnTs=cos2πfc fs fc fs The following model implements the last equation. Please note that a feedback path was included for phase continuityFigure 38: Carrier Wave Generator The Coherent Detector (in brief)
The coherent detector principle of operation is in Figure 39. The AM example model (AM_Coherent.mdl) is shown in Figure 40.Figure 39: Coherent SQRT Demodulation Principle of Operation Figure 40: Amplitude Modulation Example with Coherent Detection MATLAB and Simulink are registered trademarks of The MathWorks, Inc. See www.mathworks.com/trademarks for a list of additional trademarks. Other product or brand names may be trademarks or registered trademarks of their respective holders.FOOTNOTES
- The subtraction is created by reconfiguring the adder block, and choosing “+-“ instead of: “++”
- The principle of operation of the Configurable Carrier Module is described in the Appendix.
- The models will be loaded by the GUI script.
Amplitude Modulation
Introduction
This chapter presents the use of the DSK6713 to demonstrate the features of Amplitude Modulation (AM) transmission and reception. The model runs in real-time and enables the use to select:- The AM algorithm
- The transmission and reception parameters (modulation index and carrier frequency).
The process comprises:- Creating a simulation model (not R-T) for the AM transmitter/receiver.
- Migration to Real-time of the Simulation Model
- Building a Graphic Users Interface (GUI) to operate the real-time implementation.
Related Files
- Powerpoint Presentation - Amplitude Modulation.ppt
- Simulink Model for Simulation - AM_Simulation.mdl
- MATLAB GUI for Real-Time - AM.fig
- GUI m-fileAM.m
- m-file for Selection of AM Reception ChangeModel.m
- Simulink Model for Coherent Detection AM_Coherent.mdl
- Simulink Model for Square Root (SQRT) Detection AM_Sqrt.mdl
- Configurable Carrier Simulink Model Configurable_Carrier.mdl
Simulation
The Environment
Figure 1 shows the data flow for the AM modulation simulation. The AM modulation model receives an input signal from an external signal generator, modulates it and displays the modulation on the scope.Figure 1: Simulation Environment The Procedure
Building the Transmitter
The basic modulation mathematical description is given by:TABLE 1 y(t)=[1+m(t)]cos(2πfct) Where: cos(2πfct) - The carrier signal m(t) - The modulation index Figure 2: AM Transmission Principle - Start by creating a new model in Simulink ®
- Open the Simulink library browser and add the DSP sine-wave to your model. This blocks will represent the information signal m(t).
Figure 3: The Sine Wave Generator Block - Configure the Sine Wave Generator Block (Double click on the DSP sine object). Set the sine frequency to 1000 Hz, sample time to 1/96000, samples per frame to 64 and close the box, and change its label to “information”.
Figure 4: Information Signal Configuration Parameters - Use the same block to create the carrier signal. You may copy the block already created or select it form the Simulink library. Set the carrier frequency to 15,000 Hz. The remaining parameters are identical to the ones of the information signal. Change its label to “carrier”
- Add new DSP-constant to your model:
Figure 5: Adding a DSP constant - Double-click on the constant object and set its constant value to 1.5:
Figure 6: Set a constant value - Add a new adder object from:
Figure 7: Addes - Add a new multiplexer from the same directory as the adder (choose “product”).
- Add a new scope object:
Figure 8: Scope - Set the number of frames parameter to 5. This parameter determines the horizontal scaling of the presented signal.
Figure 9: Vector Scope Configuration - Place the objects in the following way:
Figure 10: The Transmitter Model - Run the model, pause the simulation and activate the scope window. The modulated signal should be displayed as follows:
Figure 11: AM Modulation Signal The AM Receiver (Square Root Demodulator)
In this section you will create the model for an AM receiver based on Square Root (SQRT) demodulation. The principle of operation is shown Figure 1.Figure 12: SQRT Demodulation Principle of Operation - Add the new math function block to your model. This block can be configured to implement various mathematical functions.
Figure 13: Square Function - Configure the block to calculate the square:
Figure 14: Select Math Function - Use the math function block to create the Square root function. You may retrieve it from the library or copy the “square” block.
- Add a digital filter design block. This block enables you to design filters using the MATLAB® FDATool.
Figure 15: Digital Filter Design - Configure the filter to be Low-Pass Filter. Since the carrier frequency (fc) is 15 KHz and the maximal frequency of the information is 1 KHz, the filter will be designed to pass frequencies below 5 KHz, and rejects frequencies higher than 10 KHz (please refer to Figure 16).
Figure 16: LPF Design Window - Add a "Multiplier" and a "Subtract"1 block.
- Add two "DSP Constant" blocks.
- Add the matrices concatenation object. This object will enable the modulated and the de-modulated signals to be displayed simultaneously in the scope:
Figure 17: Matrix Concatenate - The blocks should be connected as shown in Figure 18.
Figure 18: AM Simulation Model - Run the simulation (push the “play” button). Double click on the scope. Scale the display to fit the scope window (Choose from the menus: Axes=>Autoscale). Choose a different color for each signal (Please refer to Figure 19).
Figure 19: Displaying the Modulated and Demodulated Signals You should get the signals presented bellow:Figure 20: The Video Viewer Display - You may change the simulation parameters, and check their influence.
Real Time Implementation
The Environment
The real-time implementation model will be created upon the simulation model, after the following changes:- The signal generator block will be replaced by the CODEC of the DSK6713
- The virtual scope will be replaced also by the CODEC
- A target definition block (DSK6713) will be added.
Figure 21 shows the block-diagram for the real time implementation.Figure 21: Real Time Implementation Environment Equipment Used (shown in Figure 22):- DSK6713
- Dual Channel Oscilloscope
- Signal Generator
Figure 22: Equipment Used We have 4 signals (4 cables):- Information- the signal to be modulated
- Modulated- the DSK creates a modulation of the given information
- Feedback- since the transmitter and the receiver are running on the same platform, we need to perform a loopback from the transmitter to the receiver and this is exactly the feedback signal, the modulated signal that is broadcasted by the transmitter and used as input for the receiver.
- Demodulated- the signal that the receiver outputs after the demodulation process.
The Procedure
- Open the model created in the previous chapter
- Remove the scope and the “information” signal (the 1,000 Hz).
- Open the Simulink library browser and add the "C6713DSK".
Figure 23: The C6713DSK Block - Add the “Analog to Digital” and “Digital to Analog” converters (ADC and DAC) to your model:
Figure 24: A/D and D/A converters - Add the multi-port selector, in order to split the stereo input.
Figure 25: Multiport Selector - After placing the selector, double-click to open the dialog box and choose “columns” in the “select” label and “{1,2}” in the “indices to output label.
Figure 26: Multiport Configuration - Configure the ADC and DAC blocks to a sampling rate to 96 KHZ and 16-bit samples.
Figure 27: DAC and ADC Configuration - The final model should look as follows:
Figure 28: AM (SQRT) Real Time Model - You should configure the DSP constants as shown in Figure 28. The frame period for all constants should be -1
Figure 29: Constant Value Parameters - Build the project and load the program to the DSK memory using ctrl+B.
- Make sure that the signals generator amplitude is set to 1 Volt and frequency of [0.1,5] kHz.
- Display the modulated and demodulated signals in the scope.
Model Extensions
In this section we will extend the functionality of the example. Adding two more features:- A variable frequency carrier generator (Please refer to secion "A Configurable Carrier Wave Generator" in the Appendix)
- An additional model for AM detection (Please refer to secion "The Coherent Detector (in brief)" in the Appendix).
- Build GUI that we will enable:
- Changing the modulation index
- Changing the carrier frequency
- Selecting the detection scheme
The modulation index and carrier frequency will be changed through RTDX.- Open the model created in the previous section
- Replace the constant modulation index by an RTDX input (Please refer to Figure 30), and name it InputModulation.
Figure 30: RTDX input - Configure the RTDX input object to the values described bellow:
Figure 31: RTDX Input Configuration - Replace the sine wave block used for the carrier by the configurable carrier blocks (you may find them in the Configurable_Carrier.mdl file)2, and create a subsystem for the carrier generator as shown in Figure 32.
Your model should look as shown in Figure 33.Figure 32: Inserting a Configurable Carrier Figure 32 – Inserting a Configurable CarrierFigure 33: AM (SQRT) Model with Configurable Carrier - Enter the Configuration Parameters menu (ctrl+E). Choose Real-Time Workshop=>TIC6000 Code-Generator, In The Run-Time box change the Build Action to “Build”3:
Figure 34: Simulation Parameters Push the OK button and close the “Configuration Parameters” window.Rebuild *.out file using ctrl+B.- Open the AM_Coherent.mdl file, and repeat step for this file.
You now have two load files each one corresponding to a different AM scheme.Creating the GUI
- Open a new GUI (Enter GUIDE in the MATLAB command line)
- Add 2 sliders and one list box to the GUI, so it would look like:
Figure 35: GUI Design Screen - Now, double click on the list-box and change the string field:
Figure 36: List Box Configuration Screen Change the string field to:CoherentSQRT- 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-file.
The script file
In the script we have to perform the following tasks:- When the GUI is launched the DSK should be loaded with a default model (SQRT)
- When the user selects a new model> Its correspondent *.out file should be loaded to the DSP.
- When the modulation index is changed, its new value should be written to the DSP through the correspondent RTDX channel.
- When the carrier frequency modulation index is changed, its new value should be written to the DSP through the correspondent RTDX channel.
The following steps describe this implementation.- The initialization routine “AM_OpeningFcn”:
function AM_OpeningFcn(hObject, eventdata, handles, varargin) last_model=1; handles.last_model=last_model; modelName = gcs; %connect to the board CCS_Obj = connectToCCS(modelName); % Identify RTDX channel names/modes chan_struct(1).name = 'InputModulation'; chan_struct(1).mode = 'w'; chan_struct(2).name = 'freq'; chan_struct(2).mode = 'w'; handles.rtdx_chan1=chan_struct(1); handles.rtdx_chan2=chan_struct(2); % Identify RTDX host buffer parameters RTDX_config_struct.Buffsize= 32768; RTDX_config_struct.Nbuffers = 4; RTDX_config_struct.Mode = 'continuous'; %building the full path of the file to be loaded CodegenDir = fullfile(pwd, ['AM_Coherent' '_c6000_rtw']); OutFile = fullfile(CodegenDir, ['AM_Coherent' '.out']); %Load is needed for rtdx setup CCS_Obj.load(OutFile,20); % Set up RTDX r = setupRTDX(CCS_Obj, chan_struct, RTDX_config_struct); handles.pipe=r; handles.CCS_Obj=CCS_Obj; %last_x and last_y are the initial values of %the Index and the carrier respectively last_x=1; last_y=15000; handles.last_x=last_x; handles.last_y=last_y; handles.output = hObject; % Enable all RTDX channels r.enable('all'); % Update handles structure guidata(hObject, handles); %use the change-model function in order to load the current model. %this function loads a model to the DSK after initiallization (= the code %above) ChangeModel(handles.last_model,handles.CCS_Obj,handles.pipe,handles.last_x,handles.last_y); )
- When you select a new model, the following code is invoked:
function listbox1_Callback(hObject, eventdata, handles) handles.last_model=get(hObject,'Value') ; ChangeModel(handles.last_model,handles.CCS_Obj,handles.pipe,handles.last_x,handles.last_y);
An external function (written in the ChangeModel.m file) will be used to select the model:%1. halts the current model %2. free the rtdx channel %3. redefine the rtdx channel %4. loads the current model %5. binds the rtdx to the current model %6. run the CCS and enable the rtdx. %7.writes the last given index modulation to the rtdx %parameters: %m - flag that tells if the model is coherential or sqrt %CCS_Obj - the target %r_old - the old rtdx channel %last_x - to keep the current Index %last_y - to keep the current carrier frequency function r=ChangeModel(m,CCS_Obj,r_old,last_x,last_y) %halt the current model CCS_Obj.halt; %free the curent rtdx channel cleanupRTDX(CCS_Obj,r_old); %redefine the rtdx: chan_struct(1).name = 'InputModulation'; chan_struct(1).mode = 'w'; chan_struct(2).name = 'freq'; chan_struct(2).mode = 'w'; handles.rtdx_chan1=chan_struct(1); handles.rtdx_chan2=chan_struct(2); % Identify RTDX host buffer parameters RTDX_config_struct.Buffsize= 32768; RTDX_config_struct.Nbuffers = 4; RTDX_config_struct.Mode = 'continuous'; %reload the new model switch m case 1 model='AM_Coherent'; case 2 model='AM_Sqrt'; end CodegenDir = fullfile(pwd, [model '_c6000_rtw']); OutFile = fullfile(CodegenDir, [model '.out']); CCS_Obj.load(OutFile,20); % set up the new rtdx channel and run the target r = setupRTDX(CCS_Obj, chan_struct, RTDX_config_struct); CCS_Obj.run; r.enable('all'); % keep the last Index and carrier frequency: if last_x~=1 r.writemsg(chan_struct(2).name,1/last_x); end
- Changing the modulation index:
function slider1_Callback(hObject, eventdata, handles) last_x=handles.last_x; r=handles.pipe; x=single(get(hObject,'Value')); if or (y
last_y) %if the Index was changed: r.writemsg(handles.rtdx_chan1.name,1/x); %the Index increases when the added amplitude decreases %and thats the reason that we write 1/x to the rtdx handles.last_x=x; end guidata(hObject, handles); - Changing the carrier frequency:
function slider2_Callback(hObject, eventdata, handles) last_y=handles.last_y; r=handles.pipe; y=single(get(hObject,'Value')); if or (y
last_y) r.writemsg(handles.rtdx_chan2.name,y); handles.last_y=y; end guidata(hObject, handles); Figure 37: AM Model Graphic User Interface You may change the modulation index and frequency for both models, and observe its influence on the modulated and demodulated signals.Appendix
A Configurable Carrier Wave Generator
The Simulink sine wave block cannot be configured during run-time; its frequency is a parameter that should be set in advance. We will introduce the implementation of a block where the frequency is a variable that can be set in real-time (In this case using RTDX). The block is based on the following relationship:cosωct=Re[ejωct](1)In the discrete case the following relationship applies:cosωcnTs=cos2πfc fs fc fs The following model implements the last equation. Please note that a feedback path was included for phase continuityFigure 38: Carrier Wave Generator The Coherent Detector (in brief)
The coherent detector principle of operation is in Figure 39. The AM example model (AM_Coherent.mdl) is shown in Figure 40.Figure 39: Coherent SQRT Demodulation Principle of Operation Figure 40: Amplitude Modulation Example with Coherent Detection MATLAB and Simulink are registered trademarks of The MathWorks, Inc. See www.mathworks.com/trademarks for a list of additional trademarks. Other product or brand names may be trademarks or registered trademarks of their respective holders.
No comments:
Post a Comment