<< mdaqDSPBuild DSP managment mdaqDSPSignalRead >>

MicroDAQ toolbox >> MicroDAQ toolbox > DSP managment > mdaqDSPSignal

mdaqDSPSignal

Register SIGNAL block

Description

This function registers Xcos signal. In order to read data from Xcos generated DSP application SIGNAL block with its ID needs to be registered. Signal ID registration has to be done before read data operation done with mdaqDSPSignalRead().

WARNING: Current mdaqDSPSignalRead() implementation allows reading only single XCos signal - use MUX block to gather signals into one signal vector.

Calling Sequence

mdaqDSPSignal(signal_id, signal_size);
mdaqDSPSignal(connection_id, signal_id, signal_size);

Arguments

Example

// 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

See Also


Report an issue
<< mdaqDSPBuild DSP managment mdaqDSPSignalRead >>