Main Content

Generate Wireless Waveform in Simulink Using App-Generated Block

This example shows how to configure and use the block that is generated using the Export to Simulink capability that is available in the Wireless Waveform Generator app.

Introduction

The Wireless Waveform Generator app is an interactive tool for creating, impairing, visualizing, and exporting waveforms. You can export the waveform to your workspace or to a .mat or .bb file. You can also export the waveform generation parameters to a runnable MATLAB® script or a Simulink® block. You can use the exported Simulink block to reproduce your waveform in Simulink. This example shows how to use the Export to Simulink capability of the app and how to configure the exported block to generate waveforms in Simulink.

Although this example focuses on exporting an OFDM waveform, the same process applies for all of the supported waveform types.

Export Wireless Waveform Configuration to Simulink

Open the Wireless Waveform Generator app by clicking the app icon on the Apps tab, under Signal Processing and Communications. Alternatively, enter wirelessWaveformGenerator at the MATLAB command prompt.

In the Waveform Type section, select an OFDM waveform by clicking OFDM. In the left-most pane of the app, adjust any configuration parameters for the selected waveform. Then export the configuration by clicking Export in the app toolstrip and selecting Export to Simulink.

The Export to Simulink option creates a Simulink block, which outputs the selected waveform when you run the Simulink model. The block is exported to a new model if no open models exist.

modelName = 'WWGExport2SimulinkBlock';
open_system(modelName);

The Form output after final data value by block parameter specifies the output after all of the specified signal samples are generated. The value options for this parameter are Cyclic repetition and Setting to zero. The Cyclic repetition option repeats the signal from the beginning after it reaches the last sample in the signal. The Setting to zero option generates zero-valued outputs for the duration of the simulation after generating the last frame of the signal. The Waveform sample rate (Fs) and Waveform length block parameters are derived from the waveform configuration that is available in the Initialization tab of the Mask Editor dialog box. For further information about the block parameters, see Waveform From Wireless Waveform Generator App. This figure shows the parameters of the exported block.

close_system(modelName);

Connect a Spectrum Analyzer block to the exported block.

modelName = 'WWGExport2SimulinkModel';
open_system(modelName);

Simulate the model to visualize the waveform using the current configuration.

sim(modelName);

The Spectrum Analyzer block inherits the Waveform sample rate (Fs) parameter, which is 64 MHz.

close_system(modelName);

Modify Wireless Waveform Configuration

When you run the Simulink model, the exported block outputs the waveform generated in the Initialization tab of the Mask Editor dialog box for the block. The MATLAB code that initializes the waveform in this tab corresponds to the configuration that you selected in the Wireless Waveform Generator app before exporting the block. To modify the configuration of the waveform, choose one of these options:

  • Open the Wireless Waveform Generator app, select the configuration of your choice, and export a new block. This option provides interaction with an app interface instead of MATLAB code, parameter range validation during the parameterization process, and visualization of the waveform before running the Simulink model.

  • Update the configuration parameters that are available in the Initialization tab of the Mask Editor dialog box of the exported block. This option requires modifying the MATLAB code available in this tab so that the parameter range validation occurs only when you apply the changes. This option does not provide visualization of the waveform before running the Simulink model. Modifying the waveform parameters using this option is not recommended if you are not familiar with the MATLAB code that generates the selected waveform.

If you choose to modify the configuration by using the Initialization tab, you can open it by clicking the exported block, pressing Ctrl+M to open the Mask Editor dialog, and clicking the Initialization tab.

Use the MATLAB code that is available in the Initialization tab to update the parameters of your choice. For example, set the subcarrier spacing, scs, to 1,500,000 Hz.

Click OK to apply the changes and close the Mask Editor dialog box. Simulate the model to visualize the updated waveform.

modelName = 'WWGExport2SimulinkModelSCSModified';
sim(modelName);

The Spectrum Analyzer block now shows a sample rate of 96 MHz, which is 1.5 times the previous sample rate, as expected.

Share Wireless Waveform Configuration with Other Blocks in the Model

To access read-only block parameters and waveform configuration parameters, use the UserData common block property, which is a structure with these fields.

  • WaveformConfig: Waveform configuration

  • WaveformLength: Waveform length

  • Fs: Waveform sample rate

You can access the user data of the exported block by using the get_param function.

get_param([gcs '/OFDM Waveform Generator'],'UserData')
ans = 

  struct with fields:

    WaveformConfig: [1x1 comm.OFDMModulator]
    WaveformLength: 8000
                Fs: 96000000

Store the structure available in the user data in a base workspace variable by using the InitFcn in the callback. The InitFcn callback is executed during a model update and simulation. To use this callback, click the MODELING tab, then click the Model Settings dropdown, and click the Model Properties option. In the Callbacks pane, select the InitFcn callback. Assign the user data to a new base workspace variable (for example, cfg).

The parameters that are available in the user data of the exported block are updated every time you apply configuration changes in the Initialization tab.

To demodulate the OFDM waveform, add an OFDM Demodulator block to the model. Connect an AWGN Channel block between the OFDM Waveform Generator and OFDM Demodulator blocks to add white Gaussian noise to the input signal. Also add a Constellation Diagram block to plot the demodulated symbols.

modelName = 'WWGExport2SimulinkModelWithDemod';
open_system(modelName);

The parameters that are required to configure the OFDM Demodulator block must match the parameters that are used to configure the exported block, (otherwise, demodulation fails). To access the configuration parameters of the exported block, use the variable cfg. This figure shows the parameters of the OFDM Demodulator block.

Because the OFDM Demodulator block requires the entire OFDM waveform for demodulation, set the Samples per frame parameter in the exported block to cfg.WaveformLength. Simulate the model.

sim(modelName);

After demodulating the OFDM waveform by using the OFDM Demodulator block, the Constellation Diagram block displays the resulting QAM symbols.

Generate Multicarrier Waveforms

For multicarrier generation, the sampling rates for all of the waveforms must be the same. To shift the waveforms to a carrier offset and aggregate them, you can use the Multiband Combiner block.

modelName = 'WWGExport2SimulinkMulticarrier';
open_system(modelName);

To shift the waveforms in frequency, you might have to increase the sampling rates. The Multiband Combiner block provides the option to oversample the input waveforms before shifting and combining them. This figure shows the parameters of the Multiband Combiner block.

Simulate the model to visualize the waveforms that are centered at -80, 20, and 100 MHz.

sim(modelName);

See Also

Blocks

Related Topics