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

correct_classify_ic_eeg

PURPOSE ^

Manually correct classification of ICs

SYNOPSIS ^

function correct_classify_ic_eeg(p)

DESCRIPTION ^

 Manually correct classification of ICs

 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 correct_classify_ic_eeg(p)
0002 % Manually correct classification of ICs
0003 %
0004 % Copyright (C) 2011, ATR All Rights Reserved.
0005 % License : New BSD License(see VBMEG_LICENSE.txt)
0006 
0007 disp(mfilename);
0008 
0009 % Classification program
0010 classify_ic_prog = 'classify_ic_eeg';
0011 
0012 % Load EEG data
0013 data_file = fullfile(p.proj_root, p.eeg_dirname, p.trial_dirname, 'br_s1.eeg.mat');
0014 [eeg, ~, time_info] = vb_load_meg_data(data_file);
0015 [Nch, Nt, Ntr] = size(eeg);
0016 samplingrate = time_info.sample_frequency;
0017 time = time_info.time;
0018 
0019 % Load positions of channels
0020 pos = vb_load_channel(data_file);
0021 
0022 % Load ICA result
0023 ica_dir = fullfile(p.proj_root, p.eeg_dirname, p.ica_dirname);
0024 ica_result = fullfile(ica_dir, [classify_ic_prog '.mat']);
0025 load(ica_result,'w','s','v','unmix','mix','brain_ic','noise_ic')
0026 
0027 % Calculate ICs
0028 ic = zeros(Nch, Nt, Ntr);
0029 for tr = 1:Ntr
0030     ic(:,:,tr) = unmix*eeg(:,:,tr);  % [component x sample x trial]
0031 end
0032 
0033 % Calculate stimulu-triggered average and power spectrum
0034 mic = mean(ic, 3);% Average each IC across trials
0035 [pow, f] = vb_fftpower(ic, samplingrate);% Calculate power spectrum
0036 mp = mean(log(pow), 3);% Average power spectrum across trials
0037 
0038 % Obtain classification
0039 classification = -ones(1, Nch);
0040 classification(brain_ic) = 1;% 1: brain_ic, -1: noise_ic
0041 
0042 % Check and correct classification
0043 disp('Brain/noise ICs are represented by blue/red colors.')
0044 disp('Input IC number to correct or just push enter to go ahead.')
0045 disp('If you want to exit correction, input 0.')
0046 h = figure;
0047 cc = 1;
0048 while cc <= Nch
0049     clf(h, 'reset')
0050     set(0, 'CurrentFigure', h)
0051     k = 1;% Position of figure
0052     for c = cc:min([cc+4,Nch]);
0053         if classification(c) == 1
0054             color = 'b';
0055         else
0056             color = 'r';
0057         end
0058         
0059         % Plot spatial pattern of mixing vector
0060         subplot(5, 3, 1+3*(k-1))
0061         vb_plot_sensor_2d(pos, mix(:,c));
0062         vb_plot_sensor_2d_head_plot_add(gca);
0063         axis square off
0064         title(['IC ' num2str(c)])
0065         
0066         % Plot stimulus-triggered average of components
0067         subplot(5, 3, 2+3*(k-1))
0068         plot(time, mic(c, :), color);
0069         xlim([-0.5 1])
0070         if k == 1
0071             title('Stimulus-triggered average')
0072         elseif k == 5
0073             xlabel('Time [s]')
0074         end
0075         
0076         % Plot power spectrum
0077         subplot(5, 3, 3+3*(k-1))
0078         plot(f, mp(c, :), color);
0079         xlim([0 50])
0080         if k == 1
0081             title('Power spectrum (log)')
0082         elseif k == 5
0083             xlabel('Frequency [Hz]')
0084         end
0085         k = k+1;
0086     end
0087     ax1 = axes('Position', [0 0 1 1], 'Visible', 'off');
0088     text1 = {'Blue : Brain'; 'Red : Noise'};
0089     axes(ax1)
0090     text(0.93, 0.87, text1)
0091     drawnow
0092     
0093     % Obtain iput
0094     a = input('Input IC number to correct:');
0095     if isempty(a)% Go ahead
0096         cc = cc+5;
0097     elseif a == 0% Exit
0098         break
0099     else% Correct classification
0100         classification(a) = -classification(a);
0101     end
0102 end
0103 
0104 % Save result
0105 brain_ic = find(classification == 1);
0106 noise_ic = find(classification == -1);
0107 output_file = fullfile(ica_dir, [mfilename '.mat']);
0108 load(ica_result, 'w', 's', 'v', 'unmix', 'mix')
0109 save(output_file, 'w', 's', 'v', 'unmix', 'mix', 'brain_ic', 'noise_ic')
0110 
0111 
0112 
0113

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