Synchronizing experimental data with different timescales

23 views (last 30 days)
Hi all,
I am still concerned about the same project as yesterday. I have recorded experimental data of one experiment with several devices (GC (gas sample), GC-SCD (liquid sample), UVVIS (liquid sample), Volume flow measurement). These devices produce data at different frequencies, which leaves me with some trouble when it comes to calculating molar flows of components and reaction rates. The following (simple-sorry for the excel look) figure should help clarify what I mean: http://tinypic.com/r/900vm8/7
How can I extend the matrices of the devices with a slower sampling rate? I think I want to sample all data up to the same, highest frequency. I actually don't think about interpolation but just repeating the same value of one device until the the next measured value is there. Are there possibly already matlab functions out there which meet my needs, or how can I implement something myself? The dates are already in number format.
Best regards,
bearli

Accepted Answer

Daniel Shub
Daniel Shub on 5 Aug 2011
A quick glance suggests your sample rates are all over the place, but never have a precision greater than 1s, so I would suggest rescaling everything to 1s. While there are quicker way to do this, I will show you in a loop, because it seems the most straight forward to me.
You need to start with knowing how long you took measurements for in seconds T. I will assume your measurement times, in seconds from the start of the measurement, for each sample are in a vector x and the measurement values for that sample are in a vector y and the "re-sampled" data will be stored in z.
z = zeros(T, 1);
z(1:(x(1)-1)) = 0;
for i = 1:(length(x)-1)
z(x(i):(x(i+1)-1)) = y(i);
end
z(x(end):end) = y(end);
  3 Comments
Bearli Ubuku
Bearli Ubuku on 5 Aug 2011
Hi,
there is also one more question I'm not sure about. When plotting these datapoints 50k+ my PC slows down quiete a bit. Is there a function that reduces the number of datapoints (JUST for plotting?)
Daniel Shub
Daniel Shub on 5 Aug 2011
You are correct, there is no reason for z(1:(x(1)-1)) = 0; I included it to show the edge effect. You might want to start at a non-zero initial value. You can plot a subset of the points, e.g., every fourth point: plot(1:4:T, z(1:4:end)).
The x(1)=0 is messy. Not all of your initial measurements need to have been made at time 0, i.e., x(1) can equal anything you want. In fact, if x(1) is zero, the code is going to crash. The correct answer would be
z((x(i)+1):x(i+1)).

Sign in to comment.

More Answers (1)

Oleg Komarov
Oleg Komarov on 5 Aug 2011
You can use run-length decoding to expand the low-frequency data to match the high-frequency:
% Generate random dates (sorted in ascending order)
hf = now + sort(rand(10,1)/100);
lf = now + sort(rand(10,1)/30);
datestr(hf)
datestr(lf)
% Now bin/(count) the high-freq into the low-freq according to [...) edges
len = histc(hf,lf);
% Use the counts to replicate the low-freq
rude(len,lf).'
You can find rude on the FEX: here

Products

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!