Home | Overview | Documentation | Download | MATLAB API | HowTo... | FAQ | Feedback |
MATLAB Support
Overview
The SFS MATLAB API allows MATLAB programmers access to the rich data
structures of SFS files and through them to the acquisition, signal
processing, editing and display functions of SFS. The SFS MATLAB API
allows scripts to be written in MATLAB to list the contents of SFS
files, to read, write and create data sets. A utility program matlabex
allows MATLAB functions to be called from the command line in the same way as other SFS programs.
Download and Installation
Version 2 supports 32-bit and 64-bit MATLAB!
Version 2.00 of the SFS MATLAB API can be downloaded from:
To install:
- Download the zip file into a temporary directory.
- Open the zip file with a program such as WINZIP
- Extract the contents to a suitable directory, for example
-
c:\program files\sfs\matlab
- Check that the top level directory contains the sfs*.mexw32, sfs*.mexw64 and sfs*.m files, while a subdirectory 'examples' contains example scripts.
- Start MATLAB and choose the File/Set Path menu option. Click on Add Folder, and browse to the directory where you installed the SFS MATLAB API. Click Save, and Close.
- To test out the example scripts, change the working directory in MATLAB to the examples directory, or add the examples directory to the MATLAB path as above.
API Functions
The following functions are available in SFS MATLAB API:
Function | Description | |
---|---|---|
sfsfile | Performs file-level operations on SFS files. Test existence of SFS file, create new file, empty file, get list of file contents. |
|
sfsgetitem | Reads the contents of an SFS item into MATLAB. sfsgetitem returns the item header in a MATLAB structure and the data set as a MATLAB array. Information about the size, structure and provenenance of the item is present in the header structure. | |
sfsnewitem | Creates a new empty SFS item consisting of a header structure and a data set in a form compatible with sfsputitem(). | |
sfsputitem | Writes the contents of a supplied header structure and data set to an SFS file as a new item. |
Type help sfsgetitem
etc at the MATLAB prompt to get more information about function use. There is a separate documentation file for the MATLABEX
program.
API Example
Here is an example of the SFS MATLAB API being used
function sfsfilter(fname,item,hertz,ftype)
% SFSFILTER Applies a filter to a speech signal
%
% SFSFILTER(fname,item,hertz,ftype) applies an 8th-order
% Butterworth filter to the speech signal 'item' in the SFS
% file fname. The hertz parameter gives the cut-off frequency
% (or frequencies) in hertz. The ftype parameter selects the
% filter type from: 'low'=low-pass, 'high'=high-pass, 'band'=
% band-pass, 'stop'=band-stop. The filtered speech is saved
% back into the SFS file.
%
% For example:
% sfsfilter('file.sfs','1.01',1000,'low');
% sfsfilter('file.sfs','sp',[1000 2000],'band');
%
% get item from SFS file (h=header, d=data set)
%
[h,d]=sfsgetitem(fname,item);
%
% make filter (uses butter() design from signal-processing toolbox)
%
if strcmp(ftype,'low') | strcmp(ftype,'band')
[b,a]=butter(8,2*hertz*h.frameduration);
else
[b,a]=butter(8,2*hertz*h.frameduration,ftype);
end;
%
% make a new item header as copy of input item header
%
oh=sfsnewitem(h.datatype,h.frameduration,h.offset,h.framesize,h.numframes);
%
% create a suitable processing history string
%
if (length(hertz)==2)
oh.history=sprintf('matlab/SP(%d.%02d;script=signalfilter,hertz=%g:%g,ftype=%s)',...
h.datatype,h.subtype,hertz(1),hertz(2),ftype);
else
oh.history=sprintf('matlab/SP(%d.%02d;script=signalfilter,hertz=%g,ftype=%s)',...
h.datatype,h.subtype,hertz,ftype);
end;
%
% apply filter to input signal
%
od=filter(b,a,d);
%
% save filtered signal to file
%
sfsputitem(fname,oh,od);
Feedback
Please send suggestions for improvements and reports of program faults to sfs@pals.ucl.ac.uk.
Please note that we are unable to provide help with the use of this software. <