Due to memory limitations, I am segmenting and resampling my data before processing. However, in the process of resampling, somehow the samples get misaligned, i.e. if I have a signal A with length N which I divide into two smaller segments B and C, where B=A(1:j) and C=A(j+1:N), the part of the signal after j is misaligned compared to the original signal A.
The below code and images illustrate my problem. I'm not so converned about getting differences at the edges of the segments but the accumulation of error is problematic for me.
target_freq = 1000;
sampling_frequency = 32556;
order = 2;
fcutlow_low = 140;
fs = sampling_frequency;
[b_low,a_low] = butter(order,fcutlow_low/(fs/2), 'low');
myresamp = @(array) resample(array,target_freq,sampling_frequency);
myfilt = @(array) filtfilt(b_low, a_low, abs(array));
mydata = rand(1,100000);
target_freq = 1000;
original_freq = fs;
segresample = [myresamp(mydata(1:end/4)) myresamp(mydata((end/4)+1:end/2)) myresamp(mydata((end/2)+1:end))];
%% misalignment at the point of segmentation
figure
subplot(2,1,1)
plot(myresamp(mydata) - segresample)
ylabel('difference')
title('resampled')
%% this works as expected
segresample = [mydata(1:end/2)...
mydata(end/2+1:end)];
subplot(2,1,2)
plot(mydata-segresample)
title('not resampled')
ylabel('difference')