Utilizing DSP Power in Scilab Script
In this article, we will show how to use DSP management tools. We will show FFT example where the analog signal is generated on analog output and acquired with DSP management functions. MicroDAQ toolbox provides macros for managing DSP execution, a user can load DSP binary from Scilab script, register signal, read data from running DSP application and terminate its execution. This way application can be divided into a real-time part, which is executed on MicroDAQ DSP and script which allows using all Scilab functions for calculations. The FFT example uses Xcos generated DSP application and Scilab FFT function which calculates FFT from real-time data.
Our application will calculate FFT from real-time DSP data., we will start from creating example model which generates analog signal with two sine waveforms with different amplitude and frequency.
The diagram contains two sine waveform generators which output is added and passed to DAC block. Then we use ADC block to read analog samples from DAC (analog input and output should be wired). Data from ADC block is passed to SIGNAL block which sends data to host and this data can be read from Scilab script. Our model will run with 5kHz. After model creation, we generate DSP application by selecting Tools->MicroDAQ build model. The resulting application will be used in Scilab script for FFT calculation.
Running DSP application from Scilab script
MicroDAQ toolbox for Scilab provides macros which manage DSP execution. These macros can be used with a standard script to run DSP application in parallel with a Scilab script.
DSP managment scilab macros:
- mdaqDSPStart(path, rate) - starts DSP binary from path with rate
- mdaqDSPStop() - terminates DSP execution
- mdaqDSPSignal(id, size) - registers Xcos signal
- mdaqDSPSignalRead(count) - reads Xcos signal
- mdaqDSPBuild(path) - builds DSP binary from Xcos model
The example Scilab script which uses Xcos generated DSP application:
Our script loads DSP application with mdaqDSPStart() macro which as an argument takes Xcos generated DSP binary path and model rate. When the user provides -1 as a rate argument model rate the default model rate defined in Xcos model will be used. After this call DSP binary will be loaded and started on MicroDAQ DSP. In order to have access to signal data we have to register signal with mdaqDSPSignal() macro which takes two arguments, first one is signal ID defined in Xcos SIGNAL block and the second one is signal vector size which has to match with Xcos signal size. The script will read 500 samples from DSP and makes FFT calculation on this data. The mdaqDSPSignalRead() macro reads signal data from DSP, it needs one parameter which is data count which defines how many vectors will be read from DSP. The mdaqDSPSignalRead() will block Scilab until requested data is received. Reading DSP samples and FFT calculation is done in a loop. Our DSP application runs with 5kHz frequency so every 1/10sec we will new 500 samples from DSP and plot will be updated with new FFT result. After for loop completion, we need to terminate DSP execution with mdaqDSPStop() macro.
As expected on FFT plot we can see peaks at 50Hz and 100Hz with different amplitude.