Home > vbmeg > demo > tutorial_for_vbmeg2 > advanced > filter_meg.m

filter_meg

PURPOSE ^

Filter MEG data

SYNOPSIS ^

function filter_meg(p)

DESCRIPTION ^

 Filter MEG 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_meg(p)
0002 % Filter MEG 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 % Modify trigger signals for auditory and somatosensory tasks so that
0010 % they have time width of Nsample_trig.
0011 Nsample_trig=100;
0012 load_spec.ChannelName={'432'};
0013 load_spec.ChannelSwitch = true;
0014 load_spec.ChannelType = 'ALL';
0015 load_spec.ActiveChannel = 0; % all channels
0016 for file=1:2
0017     % Load trigger channel data
0018     meg_file = fullfile(p.proj_root, p.meg_dirname, p.denoise_dirname, [p.file_list{file} '.meg.mat']);
0019     data = vb_load_meg_data(meg_file,load_spec);
0020     meg_info  = vb_load_measurement_info(meg_file);
0021     precision = vb_meginfo_get_precision(meg_info);
0022     
0023     % Modify trigger signal
0024     t = 1;
0025     while t <= meg_info.Nsample
0026         if data(t) > 0.5
0027             data(t:t+Nsample_trig-1) = 1;
0028             t = t+Nsample_trig;
0029         end
0030         t = t+1;
0031     end
0032     
0033     % Save modified trigger channel data
0034     bin_dir = meg_file(1:strfind(meg_file, '.meg.mat')-1);
0035     save_file = sprintf('%s/%s.ch.meg.dat', bin_dir, load_spec.ChannelName{1});
0036     fid = fopen(save_file, 'wb');
0037     if fid == -1
0038         warining('(%s) cannot open file : %s\n', mfilename, save_file);
0039         continue;
0040     end
0041     fwrite(fid, data, precision);
0042     fclose(fid);
0043 end
0044 
0045 % Set parameters for filtering
0046 parm.bias_flg = p.bias_flg; % Bias correction (=0/1/2: OFF/Bias/Linear)
0047 parm.highpass = p.highpass; % Highpass filter cutoff frequency [Hz]
0048 parm.lowpass = p.lowpass; % Lowpass  filter cutoff frequency [Hz]
0049 parm.fsamp = p.fsamp;% down sampling frequency [Hz]
0050 parm.highpass_online = p.highpass_online; % order of online highpass filter (0=eegfilt)
0051 parm.lowpass_online = p.lowpass_online; % order of online lowpass filter (0=eegfilt)
0052 parm.common_flg = p.common_flg;% Common reference flag (=1/0 : ON/OFF)
0053 
0054 vb_fprint_filter_parm(parm);
0055 proc_spec.parm = parm;
0056 
0057 % Set output directory
0058 output_dir = fullfile(p.proj_root, p.meg_dirname, p.filter_dirname);
0059 if exist(output_dir, 'dir') ~= 7
0060     mkdir(output_dir);
0061 end
0062 
0063 for file = 1:length(p.file_list)
0064     disp(p.file_list{file})
0065     
0066     % Set input file
0067     meg_file = fullfile(p.proj_root, p.meg_dirname, p.denoise_dirname, [p.file_list{file} '.meg.mat']);
0068     
0069     % Set output file
0070     new_meg_file = fullfile(output_dir, [p.file_list{file} '.meg.mat']);
0071     
0072     % Filter MEG data
0073     vb_megfile_filter_ch_data(meg_file, proc_spec, new_meg_file);
0074 end
0075 
0076

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