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

common_average_eeg

PURPOSE ^

Take common average

SYNOPSIS ^

function common_average_eeg(p)

DESCRIPTION ^

 Take common average

 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 common_average_eeg(p)
0002 % Take common average
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 paremeters
0010 prefix = 'c';% Prefix of resultant EEG data
0011 
0012 % Load fileinfo
0013 data_file = fullfile(p.proj_root, p.eeg_dirname, p.trial_dirname, 'ribr_s1.eeg.mat');
0014 
0015 % Load indices of channels to take common average
0016 [~, ch_info, time_info] = vb_load_meg_data(data_file);
0017 Nch = length(ch_info.Active);
0018 load(data_file, 'EEGinfo')
0019 ix_in_eeg_data = zeros(1, Nch);
0020 for ii = 1:Nch
0021     ix_in_eeg_data(ii) = find(EEGinfo.ChannelInfo.ID == ch_info.ID(ii));
0022 end
0023 
0024 % Load EEG data
0025 load(data_file)
0026 
0027 % Take common reference
0028 fparm.common_flg=1;
0029 fparm.freq=EEGinfo.SampleFrequency;
0030 for tr=1:size(eeg_data,3)
0031     eeg_data(ix_in_eeg_data,:,tr)=vb_filter_raw_data(eeg_data(ix_in_eeg_data,:,tr),fparm);
0032 end
0033 
0034 % Save denoised EEG data
0035 ix = strfind(data_file, p.trial_dirname);
0036 Nc =length(p.trial_dirname);
0037 new_file = fullfile(p.proj_root, p.eeg_dirname, p.trial_dirname, [prefix 'ribr_s1.eeg.mat']);
0038 copyfile(data_file, new_file);
0039 vb_save(new_file, 'eeg_data');
0040  
0041 % Chack if average across channels is 0
0042 a = vb_load_meg_data(new_file);
0043 ma = squeeze(mean(a,1));
0044 figure
0045 plot(time_info.time, ma)
0046 xlim([time_info.time(1) time_info.time(end)])
0047 xlabel('Time [s]')
0048

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