LTPDA_RESAMPLE make the two vectors have the same length. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% DESCRIPTION: LTPDA_RESAMPLE make the two vectors have the same length and sample rate by down-sampling the one with the higher samplerate. Vectors are also truncated to the length of the shorter vector. CALL: [xo, yo, fs] = mresample(x, y, xfs, yfs) INPUTS: x - data vector y - data vector xfs - sample rate of x yfs - sample rate of y OUTPUTS: x - new data vector y - new data vector fs - new sample rate of x AND y VERSION: $Id: ltpda_matchvectors.html,v 1.14 2008/03/31 10:27:31 hewitson Exp $ HISTORY: 26-01-2007 M Hewitson Creation %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0001 function [x, y, fs] = ltpda_matchvectors(x, y, xfs, yfs) 0002 % LTPDA_RESAMPLE make the two vectors have the same length. 0003 % 0004 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 0005 % 0006 % DESCRIPTION: LTPDA_RESAMPLE make the two vectors have the same length and 0007 % sample rate by down-sampling the one with the higher samplerate. 0008 % Vectors are also truncated to the length of the shorter vector. 0009 % 0010 % CALL: [xo, yo, fs] = mresample(x, y, xfs, yfs) 0011 % 0012 % INPUTS: x - data vector 0013 % y - data vector 0014 % xfs - sample rate of x 0015 % yfs - sample rate of y 0016 % 0017 % OUTPUTS: x - new data vector 0018 % y - new data vector 0019 % fs - new sample rate of x AND y 0020 % 0021 % VERSION: $Id: ltpda_matchvectors.html,v 1.14 2008/03/31 10:27:31 hewitson Exp $ 0022 % 0023 % HISTORY: 26-01-2007 M Hewitson 0024 % Creation 0025 % 0026 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 0027 0028 % check the sample rates 0029 if yfs > xfs 0030 dv_disp('!!! vectors are not equal sample rates. Down-sampling y. !!!'); 0031 y = resample(y, xfs, yfs); 0032 fs = xfs; 0033 end 0034 0035 if xfs > yfs 0036 dv_disp('!!! vectors are not equal sample rates. Down-sampling x. !!!'); 0037 x = resample(x,yfs,xfs); 0038 fs = yfs; 0039 end 0040 0041 if xfs == yfs 0042 fs = xfs; 0043 end 0044 0045 % now check the vector lengths 0046 nx = length(x); 0047 ny = length(y); 0048 0049 if nx > ny 0050 dv_disp('!!! vectors are not equal lengths. Truncating x. !!!'); 0051 x = x(1:ny); 0052 end 0053 if ny > nx 0054 dv_disp('!!! vectors are not equal lengths. Truncating y. !!!'); 0055 y = y(1:nx); 0056 end 0057