Read SIGNAL block data
This function reads data from running DSP application generated from XCos model. Xcos model has to contain SIGNAL block with defined ID. Function blocks execution until it gathers all requested samples. In order to use function SIGNAL block needs to be registered with mdaqDSPSignal() function.
User has to provide number of scalars/vectors to read.
WARNING: Current mdaqDSPSignalRead() implementation allows reading only single XCos signal - use MUX block to gather signals into one signal vector.
[result, data] = mdaqDSPSignalRead(sample_count); [result, data] = mdaqDSPSignalRead(connection_id, sample_count);
connection_id : Connection ID returned by mdaqOpen() (OPTIONAL)
sample_count : number of signal reads
result : function call result
data : resulting data
// 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 result = mdaqDSPStart('fft_demo_scig\fft_demo.out', 1.0/FREQ); if result < 0 then abort; end // Register signal ID and signal size result = mdaqDSPSignal(1, 1); if result < 0 then disp("ERROR: unable to register signal"); abort; end first_time = 1; a = []; // Process data from DSP sample_count = FREQ/10; fig = figure("Figure_name","MicroDAQ FFT demo"); for i=1:(TIME*10) [result, s] = mdaqDSPSignalRead(sample_count); if result < 0 then disp("ERROR: unable to read signal data!"); abort; end 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 |