resampling by spline interpolation before applying this function, lowpass filtering should be done --- Usage [yy, tt] = vb_resample_by_spline(y,t,freq) yy = vb_resample_by_spline(y,t,[],tt) --- Input y : time series data [Nchannel x Nsample] t : time for y [sec] [1 x Nsample] freq : sampling frequency [Hz] [1 x 1] tt : time for resampled data [sec] [1 x Nresample] y(n, j) : n-th channel signal at time t(j), n=1:Nchannel, j=1:Nsample --- Output yy : resampled signal at tt tt : time for resampled data [sec] [1 x Nresample] Copyright (C) 2011, ATR All Rights Reserved. License : New BSD License(see VBMEG_LICENSE.txt)
0001 function [yy , tt]= vb_resample_by_spline(y, t, freq, tt) 0002 % resampling by spline interpolation 0003 % before applying this function, lowpass filtering should be done 0004 % --- Usage 0005 % [yy, tt] = vb_resample_by_spline(y,t,freq) 0006 % yy = vb_resample_by_spline(y,t,[],tt) 0007 % --- Input 0008 % y : time series data [Nchannel x Nsample] 0009 % t : time for y [sec] [1 x Nsample] 0010 % freq : sampling frequency [Hz] [1 x 1] 0011 % tt : time for resampled data [sec] [1 x Nresample] 0012 % y(n, j) : n-th channel signal at time t(j), 0013 % n=1:Nchannel, j=1:Nsample 0014 % --- Output 0015 % yy : resampled signal at tt 0016 % tt : time for resampled data [sec] [1 x Nresample] 0017 % 0018 % Copyright (C) 2011, ATR All Rights Reserved. 0019 % License : New BSD License(see VBMEG_LICENSE.txt) 0020 0021 %%% DEBUG setting 0022 %freq = 5; 0023 %t = 0:100; 0024 %y = sin(t); 0025 %%% DEBUG setting 0026 0027 t0 = t(1); 0028 t1 = t(end); 0029 0030 if ~exist('tt','var') 0031 if ~isempty(freq) && length(freq)==1, 0032 dt = 1/freq; 0033 tt = t0:dt:t1; 0034 else 0035 error('No frequency nor resampled time is specified') 0036 end 0037 end 0038 0039 [Nch, T] = size(y); 0040 0041 if T ~= length(t), error('dimension mismatch'); end; 0042 0043 yy = zeros(Nch, length(tt)); 0044 0045 for n= 1:Nch 0046 yy(n,:) = spline(t,y(n,:),tt); 0047 end 0048 0049 %%% DEBUG setting 0050 %plot(tt,yy) 0051 %%% DEBUG setting