Follow us Follow us Signalogic on LinkedIn

MATLAB® DSP/Analog Hardware Interface Example #1

Source Code Home

Below is an example of interfacing off-the-shelf DSP/analog hardware to MATLAB using DirectDSP® software. Note the use of the ShowHwSelector call to bring up a list of supported hardware.


% test / example MATLAB program for DirectDSP® software
% shows hardware selector, opens Hypersignal program as DSP engine, 
%initializes selected board, and acquires waveform file
% jhb, 29 FEB 96

load windows.con -mat  % misc. constants used by DirectDSP test and 
example programs
load enmgr.con -mat    % Engine Manager DLL constants
load hwlib.con -mat    % Hardware Library DLL constants

% initialize flags

fCanceled = FALSE;          % result of hardware selector dialog
hEngine = NULL;             % engine handle
hBoard = NULL;              % board handle
fBoardInitialized = FALSE;  % board status

ShowStat;  % turn on debug status window in Engine Manager

% show hardware selector dialog box ("Hardware Manager"); returns board 
designator
% string selected by user
% note:  if hardware choice is fixed, then skip this call and use correct 
board designator
% string in AssignBoard call below

[fSelect, BoardStr] = ShowHwSelector(NULL);

if (fSelect == IDCANCEL)  % user canceled?
    return;
end


% open dsp engine

hEngine = EngineOpen(DS_EO_HSM, NULL, NULL);  % first try to open Hypersignal-Macro 
(or Macro EX) as engine

if (hEngine == NULL)

    hEngine = EngineOpen(DS_EO_HSA, NULL, NULL);  % if that doesn't work, try 
Hypersignal-Acoustic

    if (hEngine == NULL)

        errstr = ['EngineOpen failed; error code = ' num2str(GetHwLibErrStat)];
        disp(errstr);

        return;  % abort
    end
end


% assign a board handle:  engine handle, board designator string, instruction set, 
IO base addr, Mem base addr

hBoard = AssignBoard(hEngine, BoardStr, NULL, NULL, NULL);  % NULL == use defaults 
where possible

% initialize the board; make sure it's installed and responding

fBoardInitialized = InitBoard(hBoard);

if (fBoardInitialized == FALSE)

    errstr = ['InitBoard failed; error code = ' num2str(GetEngErrStat(hEngine))];
    disp(errstr);

    if (hBoard ~= NULL)
        FreeBoard(hBoard);
    end

    if (hEngine ~= NULL)
        EngineClose(hEngine);
    end

    return;  % abort
end

hConvInfo = AllocConvInfo;  % allocate CONVINFO structure

SetConvItem(hConvInfo, DS_FILENAME, 'test');
SetConvItem(hConvInfo, DS_SAMPFREQ, 22050);
SetConvItem(hConvInfo, DS_NUMCHAN, 1);
SetConvItem(hConvInfo, DS_NUMSAMPLES, 50000);

% acquire waveform file, wait for result (synchronous operation); note
% that asynchronous operation is possible to allow continued processing
% (see the dtape.cpp source code file for an example of async operation)

AcquireWvfrmFile(hBoard, hConvInfo, DS_AWF_SYNC);

FreeConvInfo(hConvInfo);  % free CONVINFO structure

% done; leave board in disabled state, clean up handles, engines

if (fBoardInitialized == TRUE)
    DisableBoard(hBoard);
end

if (hBoard ~= NULL)
    FreeBoard(hBoard);
end

if (hEngine ~= NULL)
    EngineClose(hEngine);
end