How to apply a Hanning filter to a time series?
40 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
Lorenzo Melito
il 28 Nov 2019
Commentato: Lorenzo Melito
il 7 Mar 2022
I am analyzing a time series of location of a given feature (b) over time (date). Both b and date are (786x1) vectors; b collects the position of the feature in meters, while date collects the dates of each detected location (the dates are in datenum at the moment). Each element of date represents a single day, so that the entire time series spans across a bit more than two years. Note that, in some days, the position of the feature could not be identified, so b presents some NaNs in the corresponding days. You can see the plotted data in the figure below.
Following a research approach from a paper I have read recently, I am trying to (I cite the paper) "year-average the time series by applying a Hanning (cosine-squared) filter with a half-width of 365 days". I presume the authors are meaning that I have to window this time series with a Hann window. I am no expert of digital filters, so I searched through this forum, and an answer for another question suggested me to try a convolution. First, I have removed the NaN elements in b and the corresponding dates in date.
not_nan = ~isnan(b);
date2 = date(not_nan); b2 = b(not_nan);
Supposing that the window width is 10 samples (days), I define a Hann window of 10 elements and convolute b2:
win = hann(10);
filtered = conv(b2,win,'same');
plot(date2,b2,'.'); hold on;
plot(date2,filtered);
While I believe that this convolution is somehow doing the trick, it seems that the filtered time series is amplified with respect to the original series and the amplification grows as the Hann window width grows. When I define a 365-days Hann window, moreover, the amplification goes really high. I have tried to demean the original time series before windowing it, but the issue still remains.
Can you please point me in the right direction?
Thank you for any help.
0 Commenti
Risposta accettata
Raunak Gupta
il 4 Dic 2019
Hi,
In my understanding it is required to smooth the data as I can see from the step that are taken in the problem. The hann filter will generate a filter that has positive value for all points in the window length (Because of the squared cosine). So, convolving with it will only amplify the value as surrounding data values will be added. Even subtracting the mean will not help here.
Instead of this you may try smoothdata for smoothing out the data with a specific ‘method’ and ‘window’ which meets the requirements.
Hope this helps.
Più risposte (1)
Alessandro La Chioma
il 3 Mar 2022
Hi
I think you should normalize the filter kernel:
win = hann(10);
win = win/sum(win); % Normalization
filtered = conv(b2,win,'same');
Vedere anche
Categorie
Scopri di più su Filter Analysis in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!