%%%%%%%%%%%APPLICATION NOTES%%%%%%%%%%%%%%%%%%%%%%%% % % This function is used to load Zmachine EEG data. Use it as follows, % [data,loginfo] = LoadZmachineData('E:\data200\00000.bin'); % % Return variables: % data: EEG signal in double precision format in micro-volts (full range is -500uV to 500uV) % loginfo: this structure contains information about the EEG signal % (sampling frequency, gain, A/D span, A/D resolution, etc). % % If you have already used the Zmachine Data Viewer to import sleep data to your PC, % the EEG data is now stored in the PC, and no longer in the Micro SD card of Zmachine. % So you need to change the directory name in the above example, 'E:\data200\', % to the directory of your PC in which the EEG data is stored, % such as 'C:\ProgramData\ZmachineDataViewer\XXXXXXX\Import0\data\', % where 'XXXXXXX' is the name that you have used for this person. % % The directory 'C:\ProgramData\' is a hidden directory, so you might need to % turn on "show hidden files, folders, and drives" in Windows of your PC % in order to see 'C:\ProgramData\'. % % Zmachine checks sensor impedances every 15 minutes by default to make sure the good sensor connection. % This check last for 1.854 second and the data during this period is not a valid EEG signal. % % Ver 1.2 % Copyright 2016 General Sleep Corporation. All rights reserved. % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% function [data,loginfo] = LoadZmachineData(file_name) loginfo = parse_wbpp_log_public(strrep(file_name,'bin','LOG')); if isempty(loginfo) data = []; disp('ERROR: Can not open LOG file\n'); return; end counts=loadraw_public(file_name,'uint16'); if isempty(counts) data = []; loginfo = []; disp('ERROR: Can not open DATA file\n'); return; end counts=swapbytes(uint16(counts)); ad_bits = loginfo.resolution; full_range = (loginfo.span_max-loginfo.span_min); data = double(counts)*full_range/power(2,ad_bits)-full_range/2; data = data/loginfo.gain*1e6; function [data,count]=loadraw_public(filename,type) if (nargin == 1) type = 'double'; end fid=fopen(filename,'r'); if (fid == -1) % no such file data = []; count = 0; else [data,count]=fread(fid,type); fclose(fid); end function info = parse_wbpp_log_public(filename) fid = fopen(filename); temp = textscan(fid,'%s','delimiter','\n'); fclose(fid); for i = 1:length(temp{1}) if strcmp(temp{1}{i},'Sample Rate, in Hz') == 1, info.fs = str2double(temp{1}{i+1}); end if strcmp(temp{1}{i},'Amplification') == 1, info.gain = str2double(temp{1}{i+1}); end if strcmp(temp{1}{i},'Span Max, in Volts') == 1, info.span_max = str2double(temp{1}{i+1}); end if strcmp(temp{1}{i},'Span Min, in Volts') == 1, info.span_min = str2double(temp{1}{i+1}); end if strcmp(temp{1}{i},'Bits of Resolution') == 1, info.resolution = str2double(temp{1}{i+1}); end if strcmp(temp{1}{i},'Impedance Checking Amplification') == 1, info.impedance_gain = str2double(temp{1}{i+1}); end end