Read SIGNAL block data
This function reads data from running DSP application generated from XCos model in external mode. Xcos model has to contain SIGNAL block with defined ID. Function blocks execution until it gathers all requested samples or 'timeout' is reached. For example, if a user wants to read data from DSP application where SIGNAL block with ID=13 is connected to MUX block which is passing 4 doubles (data size = 4), the function call will be as follows: mdaqDSPSignalRead(13, 4, 1, 1000). In that case, timeout is set to 1 second.
Signals reading mechanism is buffering data for all signal ONLY from one data request. The data request is performed when there is no data available at specific signal ID. To keep data coherency over the time there is a recommendation to read all signals. Example below:
[data] = mdaqDSPSignalRead(signalID, vectorSize, vectorCount, timeout);
signalID: SIGNAL block identification number from XCOS model
vectorSize: SIGNAL block data size
vectorCount: number of vectors to read
timeout: maximum amount of time to wait for data in miliseconds
// Script execution duration in seconds TIME = 20; // Model execution frequency in Hertz FREQ = 5000; // Build DSP binary from Xcos model mdaqDSPBuild(mdaqToolboxPath() + filesep() + "examples" + filesep() +"fft_demo.zcos"); // Start DSP application mdaqDSPStart('fft_demo_scig\fft_demo.out', 1.0/FREQ); first_time = 1; a = []; s = []; // Process data from DSP sample_count = FREQ/10; fig = figure("Figure_name","MicroDAQ FFT demo"); for i=1:(TIME*10) s = mdaqDSPSignalRead(1, 1, sample_count, 1000); N=size(s,'*'); //number of samples s = s - mean(s);//cut DC y=fft(s'); f= FREQ*(0:(N/10))/N; //associated frequency vector n=size(f,'*'); if is_handle_valid(fig) then if first_time == 1 then clf(); plot(f,abs(y(1:n))); title("FFT", "fontsize", 3); xlabel("frequency [Hz]","fontsize", 3); first_time = 0; a = gca(); else a.children.children.data(:,2) = abs(y(1:n))'; end else break; end end // Stop DSP execution mdaqDSPStop(); // Close plot mprintf("\nFFT demo has been stopped."); if is_handle_valid(fig) then close(fig); end | ![]() | ![]() |