Gaussian moving average on dataset with replicate analyses
Mostrar comentarios más antiguos
Hey Guys,
I got isotopic abundance data of samples that come from a different period in the past, but sometimes I have more than 1 measurement per sample/time. I want to smooth my data using a gaussian window but I can't figure out how to smooth my data in the time domain.
minimum working example. % create a matrix with replicate time values, probably not import but let's say that time here is days
time = [1 1 2 3 3 3 4 4 4 4 5 6 6 6 6 6 7 7 8 8 9 9 9 10];
% create associated values
data = [0.43 0.44 0.45 0.44 0.46 0.48 0.49 0.50 0.49 0.52 0.55 0.52 0.51 0.53 0.52 0.55 0.49 0.49 0.46 0.45 0.44 0.40 0.41 0.35]
%create 5-day gaussian window and normalize
w = gausswin(5)/sum(gausswin(5))
Now I want to use this gaussian window to smooth my data set by moving it with a 1 day timestep. But I want all replicates to be incorporated. I also would like to add a conditional, so that it skips a day when there aren't enough replicates in the window.
Does anyone have an idea on how to do this?
Respuestas (1)
Ameer Hamza
el 20 de Mayo de 2018
If you want to apply gaussian window smoothing on the data matrix then you can use conv with one vector flipped.
smoothedData = conv(data, fliplr(w))
smoothedData = smoothedData(length(w):end-length(w)+1); % to only get the data points in which the window fully fits the |Data| matrix.
7 comentarios
Robin Vorsselmans
el 20 de Mayo de 2018
Ameer Hamza
el 20 de Mayo de 2018
It will be easier to understand if you give an example that how you want to calculate the first element of the final matrix. For example, the first day that fit the window is day 3. What is your expected output for day 3?
Robin Vorsselmans
el 20 de Mayo de 2018
Editada: Robin Vorsselmans
el 20 de Mayo de 2018
Image Analyst
el 20 de Mayo de 2018
Ameer, why flipped? A Gaussian is symmetric.
Robin, if the element spacing is not one day then you'll have to figure out how many elements it is. If the spacing is not uniform or you do not have the same number of elements per day then you might have to interpolate/resample your data to get uniform spacing.
Ameer Hamza
el 20 de Mayo de 2018
Editada: Ameer Hamza
el 20 de Mayo de 2018
Thanks, @Image Analyst, for pointing this out. I overlooked this point.
@Robin, How are you sliding the window? For the sliding window, each weight should appear an equal number of time. For example, at first time instant
[1 1 2 3 3 3 4 4 4 4 5 6 6 6 6 6 7 7 8 8 9 9 9 10];
w1 w2 w3 w4 w5
which gives
w(1)*data(1) + w(2)*data(2) + w(3)*data(3) + w(4)*data(4) + w(5)*data(5)
then at second time instant
[1 1 2 3 3 3 4 4 4 4 5 6 6 6 6 6 7 7 8 8 9 9 9 10];
w1 w2 w3 w4 w5
which gives
w(1)*data(2) + w(2)*data(3) + w(3)*data(4) + w(4)*data(5) + w(5)*data(6)
so each from w(1) to w(5) weights will occur in each window. And in the final equation for day 3 there should be an equal number of w(1), w(2)... w(5).
Robin Vorsselmans
el 20 de Mayo de 2018
Robin Vorsselmans
el 20 de Mayo de 2018
Categorías
Más información sobre Chemistry en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!