This example shows how to use the DSP Testbench Generator Example App in order to quickly generate DSP Algorithm testbenches which accelerate the development and testing of streaming signal processing algorithms. This example for a simple DSP MATLAB application which filters frames of a noisy sine wave signal. In this DSP application, the noisy sine wave signal is passed through a lowpass FIR filter, and the power spectrum of the filtered signal is visualized using a Spectrum Analyzer.
DSP Testbench Generator Example App is useful to quickly generate DSP Algorithm testbenches. In order to launch the Testbench Generator, execute the following command from the MATLAB Command Window.
This will bring up a graphical user interface in which you can select a set of sources and sinks you want to use for the testbench as well as the name of a custom algorithm you want to call to process the streaming signals. Note that you can select more than one sink to be associated with a particular output from your custom algorithm. Also note that default properties are used for all sources and sinks. These properties should be customized to meet individual needs.
Let's say the inputs are two sine wave sources with sampling rate 44100 Hz and frequencies 1000 Hz and 10000 Hz respectively and a white noise source with standard deviation 0.1.
Let's use frame-based processing in this example. In frame-based processing, objects process data one frame at a time. Each frame of data contains sequential samples from an independent channel. Using frame-based processing is advantageous for many signal processing applications because you can process multiple samples at once. By buffering your data into frames and processing multisample frames of data, you can often improve the computational time of your signal processing algorithms. In this example, the number of samples per frame is 1024.
By default, the Testbench Generator selects one two channel Sine Wave input and one White Noise input. The default two channels of the Sine Wave are of frequencies 1000 Hz and 10000 Hz respectively. In order to add more sources, you can use the drop-down list under "Add a new source to the above list of inputs" to select one of the supported sources or you can add your custom System object source and click the "Add" button. Your added source will be seen in the list of inputs. You can also click on the Configure button to change the System object properties of the source selected from the list of inputs.
The lowpass filter is modeled using a dsp.FIRFilter System object. The filter coefficients are computed based on the constrained equiripple FIR filter design, using the function firceqrip. The filter's cutoff frequency is 5 KHz, and the linear ripples in the pass-band and stop-band are equal to 0.05 and 1e-3, respectively.
The "Enable parameter tuning" checkbox and the "Edit parameters table" buttons are useful if you want to use parameter tuning to edit the parameters in your "User Algorithm" while running the testbench.
The power spectra of the output is visualized using a Spectrum Analyzer. The spectrum units are in dBm. You can add more sinks to visualize or post-process the outputs. Use the drop-down list under "Add a new sink to the above list of outputs" to add a new sink.
Once the testbench is configured, go to menu item "Generate MATLAB Code" under "Generate Code" menu. A untitled editor document will be opened with the generated testbench code. You can edit the generated code to customize it to your needs before executing it. On running the testbench, you will see on the Spectrum Analyzer that the frequencies above 4kHz in the source signal are attenuated. The resulting signal maintains the peak at 1kHz because it falls in the passband of the lowpass filter.