Dawn@4
|
1 function func_VS2ssff(data, id, outfile, variables)
|
Dawn@4
|
2 % func_VS2ssff(data, id, outfile, variables)
|
Dawn@4
|
3 % Notes: Saves the contents of a matfile into an EMU compatible output.
|
Dawn@4
|
4 %
|
Dawn@4
|
5 % Author: Yen-Liang Shue and Henry Tehrani, UCLA
|
Dawn@4
|
6 % Copyright UCLA SPAPL 2009
|
Dawn@4
|
7
|
Dawn@4
|
8 % ssffsize=str2mat('CHAR', 'BYTE', 'SHORT', 'LONG', 'FLOAT', 'DOUBLE');
|
Dawn@4
|
9 % matsize =str2mat('uchar', 'int8', 'int16', 'int32', 'float32', 'float64');
|
Dawn@4
|
10
|
Dawn@4
|
11 %create ssff header
|
Dawn@4
|
12 samplerate = 1000 / variables.frameshift;
|
Dawn@4
|
13 starttime = 0.0;
|
Dawn@4
|
14 hdr=sprintf('%s\n', 'SSFF -- (c) SHLRC');
|
Dawn@4
|
15 hdr=sprintf('%s%s\n', hdr, 'Machine IBM-PC');
|
Dawn@4
|
16 hdr=sprintf('%s%s %i\n', hdr, 'Record_Freq', samplerate);
|
Dawn@4
|
17 hdr=sprintf('%s%s %5.2f\n', hdr, 'Start_Time',starttime);
|
Dawn@4
|
18 %hdr=sprintf('%s%s %s\n', hdr, 'Comment', comment);
|
Dawn@4
|
19
|
Dawn@4
|
20 hdr = sprintf('%s%s %s %s %i\n', hdr, 'Column', id, 'FLOAT', 1);
|
Dawn@4
|
21 hdr=sprintf('%s%s\n', hdr, '-----------------');
|
Dawn@4
|
22 %done with ssff header
|
Dawn@4
|
23
|
Dawn@4
|
24 % added 3/17/2010 - EMU is unable to read NaN
|
Dawn@4
|
25 NaNvalue = str2double(variables.NotANumber);
|
Dawn@4
|
26 if (isnan(NaNvalue))
|
Dawn@4
|
27 NaNvalue = 0; % this is the default NaN value
|
Dawn@4
|
28 end
|
Dawn@4
|
29
|
Dawn@4
|
30 data(isnan(data)) = NaNvalue;
|
Dawn@4
|
31 data(isinf(data)) = NaNvalue;
|
Dawn@4
|
32
|
Dawn@4
|
33 fid=fopen(outfile,'w');
|
Dawn@4
|
34 %write the header
|
Dawn@4
|
35 fprintf(fid, '%s', hdr);
|
Dawn@4
|
36 %write the parameter
|
Dawn@4
|
37 fwrite(fid,data,'float32', 0,'ieee-le');
|
Dawn@4
|
38
|
Dawn@4
|
39 fclose(fid);
|
Dawn@4
|
40
|
Dawn@4
|
41
|
Dawn@4
|
42
|