Home > vbmeg > demo > tutorial_for_vbmeg2 > easy_VBMEG > filter_eeg.m

filter_eeg

PURPOSE ^

Filter EEG data

SYNOPSIS ^

function filter_eeg(p)

DESCRIPTION ^

 Filter EEG data

 Copyright (C) 2011, ATR All Rights Reserved.
 License : New BSD License(see VBMEG_LICENSE.txt)

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function filter_eeg(p)
0002 % Filter EEG data
0003 %
0004 % Copyright (C) 2011, ATR All Rights Reserved.
0005 % License : New BSD License(see VBMEG_LICENSE.txt)
0006 
0007 disp(mfilename);
0008 
0009 % Set parameters
0010 ch_filter=1:65;
0011 ch_trigger=66;
0012 Nsample_trig=100;
0013 
0014 parm.bias_flg = p.bias_flg; % Bias correction (=0/1/2: OFF/Bias/Linear)
0015 parm.highpass = p.highpass; % Highpass filter cutoff frequency [Hz]
0016 parm.lowpass = p.lowpass; % Lowpass  filter cutoff frequency [Hz]
0017 parm.fsamp = p.fsamp;% down sampling frequency [Hz]
0018 parm.highpass_online = p.highpass_online; % order of online highpass filter (0=eegfilt)
0019 parm.lowpass_online = p.lowpass_online; % order of online lowpass filter (0=eegfilt)
0020 
0021 % Set output directory
0022 output_dir=fullfile(p.proj_root, p.eeg_dirname, p.filter_dirname);
0023 if exist(output_dir, 'dir') ~= 7
0024     mkdir(output_dir);
0025 end
0026 
0027 disp('s1')
0028 
0029 % Load EEG data
0030 eeg_file=fullfile(p.proj_root, p.eeg_dirname, p.load_dirname, 's1.eeg.mat');
0031 load(eeg_file)
0032 
0033 % Modify trigger channel
0034 t=1;
0035 while t<=EEGinfo.Nsample
0036     if eeg_data(ch_trigger,t)>0.5
0037         eeg_data(ch_trigger,t:t+Nsample_trig-1)=1;
0038         t=t+Nsample_trig;
0039     end
0040     t=t+1;
0041 end
0042 
0043 % Lowpass filter
0044 eeg_data(ch_filter,:)=eegfilt(eeg_data(ch_filter,:),EEGinfo.SampleFrequency,0,parm.lowpass);
0045 
0046 % Down sampling
0047 if EEGinfo.SampleFrequency~=parm.fsamp
0048     eeg_data = vb_convert_freq(eeg_data, EEGinfo.SampleFrequency, parm.fsamp);
0049 end
0050 EEGinfo.SampleFrequency=parm.fsamp;
0051 EEGinfo.Nsample=size(eeg_data,2);
0052 
0053 % Highpass filter
0054 eeg_data(ch_filter,:)=eegfilt(eeg_data(ch_filter,:),EEGinfo.SampleFrequency,parm.highpass,0);
0055 
0056 % Save filtered EEG data
0057 filtered_file=fullfile(output_dir, 's1.eeg.mat');
0058 save(filtered_file, 'eeg_data', 'EEGinfo', 'Measurement')
0059 end

Generated on Mon 22-May-2023 06:53:56 by m2html © 2005