📄 ssave.m
字号:
function [HDR] = ssave(FILENAME,DATA,TYPE,Fs,bits)
% SSAVE saves signal data in various data formats
%
% Currently are the following data formats supported:
% EDF, BDF, GDF, BKR, SND/AU, (WAV, AIF)
% and WSCORE event file
%
% HDR = ssave(HDR,data);
% HDR = ssave(FILENAME,data,TYPE,Fs);
%
% FILENAME name of file
% data signal data, each column is a channel
% TYPE determines dataformat
% Fs sampling rate
%
% see also: SSAVE, SOPEN, SWRITE, SCLOSE, doc/README
% $Revision: 1.3 $
% $Id: ssave.m,v 1.3 2004/06/10 21:16:12 schloegl Exp $
% Copyright (C) 2003-2004 by Alois Schloegl <a.schloegl@ieee.org>
% This file is part of the biosig project http://biosig.sf.net/
% This library is free software; you can redistribute it and/or
% modify it under the terms of the GNU Library General Public
% License as published by the Free Software Foundation; either
% Version 2 of the License, or (at your option) any later version.
%
% This library is distributed in the hope that it will be useful,
% but WITHOUT ANY WARRANTY; without even the implied warranty of
% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
% Library General Public License for more details.
%
% You should have received a copy of the GNU Library General Public
% License along with this library; if not, write to the
% Free Software Foundation, Inc., 59 Temple Place - Suite 330,
% Boston, MA 02111-1307, USA.
if isstruct(FILENAME),
HDR=FILENAME;
if isfield(HDR,'FileName'),
FILENAME=HDR.FileName;
else
fprintf(2,'Error SSAVE: missing FileName.\n');
return;
end;
else
HDR.FileName = HDR;
HDR.TYPE = TYPE; % type of data format
HDR.SampleRate = Fs;
HDR.bits = bits;
end;
if (nargin > 1),
[HDR.SPR, HDR.NS] = size(DATA);
HDR = sopen(HDR,'wb');
HDR = swrite(HDR,DATA);
HDR = sclose(HDR);
end;
% Convert EVENT into WSCORE event format
if all([HDR.EVENT.N, length(HDR.EVENT.POS), length(HDR.EVENT.TYP)]),
p = which('sopen'); [p,H,e] = fileparts(p);
H = sload(fullfile(p,'eventcodes.txt'));
HDR.EVENT.CodeDesc = H.CodeDesc;
HDR.EVENT.CodeIndex = H.CodeIndex;
if isfield(HDR.EVENT,'DUR')
HDR.EVENT.POS = [HDR.EVENT.POS; HDR.EVENT.POS + HDR.EVENT.DUR];
HDR.EVENT.TYP = [HDR.EVENT.TYP; HDR.EVENT.TYP + hex2dec('8000')];
end;
OnOff = {'On','Off'};
[HDR.EVENT.POS, ix] = sort(HDR.EVENT.POS);
HDR.EVENT.TYP = HDR.EVENT.TYP(ix);
[TYP, IX, IY] = unique(HDR.EVENT.TYP);
if isfield(HDR,'EDF'), % WSCORE uses maximum SamplingRate rather than selected Sampling Rate
if HDR.SampleRate ~= max(HDR.EDF.SampleRate),
HDR.EVENT.POS = HDR.EVENT.POS(:) * (max(HDR.EDF.SampleRate) / HDR.SampleRate);
end;
end;
% write "free form" scoring file for WSCORE
fid = fopen(fullfile(HDR.FILE.Path,[HDR.FILE.Name,'.C07']),'w');
for k = 1:length(TYP),
fprintf(fid,'%2i %s (%s)\r\n', k, HDR.EVENT.CodeDesc(mod(TYP(k),2^15)==HDR.EVENT.CodeIndex), OnOff{(TYP(k)>=2^15)+1});
end;
fclose(fid);
% write "free form" scoring file for WSCORE
fid = fopen(fullfile(HDR.FILE.Path,[HDR.FILE.Name,'.007']),'w');
fprintf(fid,'%i %i\r\n', [round(HDR.EVENT.POS(:)),IY(:)]');
fclose(fid);
end;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -