Convert sampling frequency y = vb_convert_freq(x, fs, fs2); x : [channel x time x trial] fs : original sampling frequency fs2 : new sampling frequency !! For downsampling, lowpass filtering should be done before using this Copyright (C) 2011, ATR All Rights Reserved. License : New BSD License(see VBMEG_LICENSE.txt)
0001 function y = vb_convert_freq(x,fs,fs2); 0002 % Convert sampling frequency 0003 % y = vb_convert_freq(x, fs, fs2); 0004 % x : [channel x time x trial] 0005 % fs : original sampling frequency 0006 % fs2 : new sampling frequency 0007 % !! For downsampling, 0008 % lowpass filtering should be done before using this 0009 % 0010 % Copyright (C) 2011, ATR All Rights Reserved. 0011 % License : New BSD License(see VBMEG_LICENSE.txt) 0012 0013 [N,T,Nr]=size(x); 0014 0015 if fs==fs2; 0016 y=x; 0017 elseif mod(fs,fs2)==0; 0018 y=x(:,1:fs/fs2:T,:); 0019 else 0020 xi = 1:T; 0021 xii = 1:fs/fs2:T; 0022 TY = length(xii); 0023 y = zeros(N,TY,Nr); 0024 0025 for i=1:N; 0026 y(i,:,:)=interp1(xi,x(i,:,:),xii); 0027 end; 0028 end;