Sine modulator example

This example takes you through the steps required to create a complete model.

Sine modulator example - Step 1

The first step is to create a library to group all the components. You will then create the system and module components.

Create Sine Modulator Library

  1. Right-click on My Libraries and choose New Model→Library to open the Create New Model dialog.
  2. Enter the Logical Name as Sine Modulator Library.
  3. Press the tab key to change the input focus, which causes the Physical Name to be filled in automatically.
  4. Leave the Library as it is.
  5. Type This library contains a sine modulator as Description.
  6. Click the OK button.

Now, you should have a new library with the name Sine Modulator Library as a subentry of the My Libraries entry.

Create Sine Modulator System

  1. Right-click on the newly created Sine Modulator Library and choose New Model→System to open the Create New Model dialog.
  2. Enter the Logical Name as Sine Modulator System.
  3. Click in the Description field and enter This is the sine modulator system model. You will notice that due to the change of input focus Physical Name was filled in automatically.
  4. Leave the Library as it is, it should already read Sine Modulator Library.
  5. Select SDF from the Modeling Domain drop-down menu.
  6. Click the OK button.

Now, you should see the new system with the name Sine Modulator System as a subentry of the previously created Sine Modulator Library. Also, you should notice that the newly created system was automatically opened in the Model Editor.

Create Sine Modulator and Sine Generator

  1. Right-click on the Sine Modulator Library and choose New Model→Module to open the Create New Model dialog.
  2. Enter the Logical Name as Sine Modulator.
  3. Enter This is the modulator model as Description.
  4. Click the OK button.
  5. Add another Module with the Logical Name Sine Generator and the Description This is the generator model.

Now, you have created the model components including the library needed for this example. Like it happened when you created the system, two additional Model Editor windows should have appeared containing the Sine Modulator and Sine Generator, respectively.

Sine modulator example - Step 2

The next step in this example is to create ports for Sine Modulator and the Sine Generator modules. Ports cannot be defined in the system model Sine Modulator System.

Add output to Sine Generator

  1. Select the Model Editor Window containing the Sine Generator module.
  2. Use the Add Output Port tool button to switch to port creation mode.
  3. Click on model background at the position where the port will be created.
  4. Click the right mouse button to switch back to normal selection mode.
  5. Select the created port. MLDesigner will show port properties in the property editor.
  6. Set the port name to Output.
  7. Select the data type float.
  8. Set the description to The sine signal output.
  9. Save the model using the tool button Save Model (Ignore construction error messages).

Add input and output to Sine Modulator

  1. Select the Model Editor Window that contains the Sine Modulator module.
  2. Use the Add Input Port tool button to switch to port creation mode.
  3. Click on model background at the position where the port will be created.
  4. Click the right mouse button to switch back to normal selection mode.
  5. Select the created port. MLDesigner will show port properties in the property editor.
  6. Set the port name to Input.
  7. Select the data type float.
  8. Set the description to The input signal.
  9. Remain in the Model Editor Window containing the Sine Modulator module.
  10. Use the Add Output Port tool button to switch to port creation mode.
  11. Click on model background at the position where the port will be created.
  12. Click the right mouse button to switch back to normal selection mode.
  13. Select the created port. MLDesigner will show port properties in the property editor.
  14. Set the port name to Output.
  15. Select the data type float.
  16. Set the description to The output signal.
  17. Save the model using the tool button Save Model (Ignore construction error messages).

Sine modulator example - Step 3

The next step in this example is the creation of parameters Frequency and SampleRate for our Sine Generator module. Switch to the Model Editor Window that contains the Sine Generator module and follow the steps below. Exporting parameters will be demonstrated for the creation of the parameters of the Sine Modulator module in Set parameters of model instances.

Add parameter Frequency to Sine Generator

  1. Select the Model Editor Window that contains the Sine Generator module.
  2. Right-click in the property editor and select the item New Parameter.
  3. Expand Parameter1 if necessary.
  4. Set the name to Frequency.
  5. Set the type to float.
  6. Set the default value to PI/50.
  7. Set the description to The frequency of the generated sine wave.
  8. Collapse the changed parameter Frequency.

Add parameter SampleRate to Sine Generator

  1. Right-click in the property editor and select the item New Parameter.
  2. Set the name to SampleRate.
  3. Set the type to float.
  4. Set the default value to 2*PI.
  5. Set the description to The sample rate of the module.
  6. Save the model using the tool button Save Model (Ignore error message).

Sine modulator example - Step 4

The next step is to include the model instances for the model components we need for the sine modulator example. Follow the steps below to add the instances for the Sine Generator, Sine Modulator, and Sine Modulator System.

Add model instances to Sine Generator

  1. Open the Sine Generator module.
  2. Expand the library MLD Libraries→SDF Domain→Sources.
  3. Drag the item Ramp into the Model Editor Window.
  4. Expand the library MLD Libraries→SDF Domain→Nonlinear.
  5. Drag the item Sin into the Model Editor Window.
  6. Arrange the components in the Model Editor Window as shown below.
  7. Save the model using the tool button Save Model.
    Ignore the construction errors. The error is displayed because there is no output/input port for the module and/or the ports are not connected or terminated.

Add model instances to Sine Modulator

  1. Open the Sine Modulator module.
  2. Expand the library MLD Libraries→SDF Domain→Arithmetic.
  3. Drag the item MpyFloat into the Model Editor Window.
  4. From the Select Special Primitive dialog select MpyFloat.Input=2.
  5. Expand your library Sine Modulator Library.
  6. Drag item Sine Generator into the Model Editor Window.
  7. Arrange the components as shown below and Save the model (Ignore construction error messages).

Add model instances to Sine Modulator System

  1. Open the Sine Modulator System.
  2. Expand the library MLD Libraries→SDF Domain→Sinks.
  3. Drag the item XMGraph.Input=1 into the Model Editor Window.
  4. Expand your library Sine Modulator Library.
  5. Drag the items Sine Generator and Sine Modulator into the Model Editor Window.
  6. Arrange the components as shown below and Save the model (Ignore construction error messages).

Sine modulator example - Step 5

To demonstrate parameter setting and linking mechanisms, let us set the model instance parameter values of our example. Different methods for achieving the same result are demonstrated here such as linking and export.

Set an actual parameter of the Ramp instance

First, you must set the actual parameters of the Ramp instance in the Sine Generator module.

  1. Select the Model Editor Window containing the Sine Generator module.
  2. Click on the Ramp model instance.
  3. Click on the value field of the parameter step.
  4. Set the value to 2*PI*$Frequency/$SampleRate.
  5. Save the model using the tool button Save Model (Ignore the construction errors).

You have now set the actual parameter step of the Ramp instance to an expression that contains the formal model parameter names. This realizes indirect linking between the Ramp parameter and the Sine Generator parameter.

(a) Sine Generator module properties (b) Ramp instance properties

Export actual parameters of the Sine Generator instance

The next step is to set the actual parameter of the Sine Generator instance in the Sine Modulator model. The Sine Generator has two actual parameters Frequency and SampleRate. Since the sample rate should be constant in the whole system model hierarchy it should be settable on the system model level. The Frequency of the sine modulator should be a parameter on the system model level. Therefore, it is necessary to export the SampleRate and Frequency parameters to the next higher model level. Follow the steps below to export these two parameters.

  1. Select the Model Editor Window that contains the Sine Modulator module.
  2. Click on the Sine Generator model instance in the Model Editor Window.
  3. Right-click on the parameter Frequency, and click Export.
  4. Right-click on the parameter SampleRate, and click Export.
  5. Save the model using the tool button Save Model (Ignore the construction error messages).

The green arrows in both fields indicate that these parameters are successfully exported.

By exporting the actual parameters Frequency and SampleRate of the Sine Generator instance, you have automatically created the two formal model parameters of the Sine Modulator module.

(a) Sine Modulator module properties (b) Sine Generator instance properties

Create system model parameters

The last step is to create the system model parameters. You need two different frequencies; one for the signal frequency, and a carrier frequency for the sine modulator as well as a system model parameter for the sample rate.

Export actual parameters of the second Sine Generator instance

  1. Select the Model Editor Window that contains the Sine Modulator System model.
  2. Click on the Sine Generator model instance.
  3. Right-click on the parameter Frequency, and click Export As.
  4. Set the name of exported parameter to SignalFrequency and click OK.
  5. Right-click on the parameter SampleRate, and click Export.

Export and link actual parameters of the Sine Modulator instance

  1. Click on the Sine Modulator model instance.
  2. Right-click on the parameter Frequency, and click Export As.
  3. Set the name of exported parameter to CarrierFrequency and click OK.
  4. Right-click on the parameter SampleRate, point to Link to, and click on SampleRate.

Set Sine Modulator System parameters

  1. Click on the Sine Modulator System model background.
  2. Click on the value field of the parameter SignalFrequency and enter the value PI/100
  3. Click on the value field of the parameter CarrierFrequency and enter the value 0.2*PI.
  4. Save the model using the tool button Save Model, ignore the construction error messages.

You have created the system parameters SignalFrequency, CarrierFrequency, and SampleRate by exporting the model instance parameter. However, the setting of the actual parameter SampleRate of the Sine Modulator model instance was realized by linking the parameter to the existing system model parameter SampleRate. Now you can control the whole model using system parameters. By setting their Scope to External in the System Properties window, you can control them directly in the Simulation Properties window (see Simulation with MLDesigner).

Sine modulator example - Step 6

The next step is to connect the model instances of the example models. Start with the creation of connections in the Sine Modulator model.

  1. Select the Model Editor Window that contains the Sine Modulator model.
  2. Double-click on the Output port of the Sine Generator instance to start a new connection.
  3. Click on Input#2 port of the MpyFloat.Input=2 instance to complete the connection.
  4. Double-click on the Input port of the module to start a new connection.
  5. Click on Input#1 port of the MpyFloat.Input=2 instance to complete the connection.
  6. Double-click on the Output port of the MpyFloat.Input=2 instance to start a new connection.
  7. Click on the Output port of the module to complete the connection.
  8. Save the model using the tool button Save Model.

Repeat these steps for the Sine Generator and Sine Modulator System. Your models should now look like this.

(a) Sine Generator module (b) Sine Modulator module
(c) Sine Generator System model

Unused ports must be terminated. This is achieved by choosing Terminate from the context menu while the relevant port is selected. In these cases the appropriate BlackHole primitive for output ports and the Const or NULL primitive for input ports for the domain are instantiated.

Sine modulator example - Step 7

The next step is to add a descriptive label to the Sine Modulator System.

  1. Select the Model Editor Window that contains the Sine Modulator System model.
  2. Click the Add Text Label toolbar button to switch to label creation mode.
  3. Click on the model background where you want the label to be.
  4. Right-click to leave label creation mode.
  5. Select the label and enter Sine wave modulator example system as Text in the Label Properties.
  6. Choose a Font for the label and increase the size of the font.
  7. Reposition the label if you have to and Save the model.

Sine modulator example - Step 8

The next step is to color the previously created model components.

  1. Select the Model Editor Window that contains the Sine Generator model.
  2. Click on the model background and set the Background Color in the Module Properties to #ffaa7f.
  3. Save the model.
  4. Select the Model Editor Window that contains the Sine Modulator model.
  5. Click on the model background and set the Background Color in the Module Properties to #aaffff.
  6. Select the Sine Generator instance and set the Color in the Instance Properties to #ffaa7f.
  7. Save the model.
  8. Select the Model Editor Window that contains the Sine Modulator System model.
  9. Select the Sine Generator instance and set the Color in the Instance Properties to #ffaa7f.
  10. Select the Sine Modulator instance and set the Color in the Instance Properties to #aaffff.
  11. Save the model.
(a) Sine Generator module (b) Sine Modulator module
(c) Sine Generator System model

Sine modulator example - Step 9

Follow the steps below to make SignalFrequency and CarrierFrequency visible within the Simulation Properties window.

  1. Select the Model Editor Window that contains the Sine Modulator System model.
  2. Click on the Sine Modulator System model background to activate the System Properties plane in the Property Editor.
  3. Set the Scope of SignalFrequency to External.
  4. Set the Scope of CarrierFrequency to External.
  5. Save the model using the tool button Save Model.

Sine modulator example - Step 10

Sine Modulator module

To demonstrate the using of Tk primitive modules we will modify the Sine Modulator model. Follow the steps below to modify the Sine Modulator module as shown in the figure.