How to apply a Hanning filter to a time series?

92 次查看(过去 30 天)
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.
data.png
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);
data+filter.png
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.

采纳的回答

Raunak Gupta
Raunak Gupta 2019-12-4
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.
  1 个评论
Lorenzo Melito
Lorenzo Melito 2019-12-4
Hello Raunak,
thank you for your answer. Yes, what I need to do is some sort of data smoothing in order to extract only the dominant (annual) trend of the data. The paper I am referring to for my research did this smoothing with a hann filter, so at first I preferred to stay consistent with their approach; but I now see where the problem lies with the hann window. I will try smoothdata as you suggested.
Thank you again!

请先登录,再进行评论。

更多回答(1 个)

Alessandro La Chioma
Hi
I think you should normalize the filter kernel:
win = hann(10);
win = win/sum(win); % Normalization
filtered = conv(b2,win,'same');
  1 个评论
Lorenzo Melito
Lorenzo Melito 2022-3-7
Hello Alessandro,
normalizing the filter is something I didn't consider back then. Thank you for your suggestion!

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Mathematics 的更多信息

产品


版本

R2019a

Community Treasure Hunt

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

Start Hunting!

Translated by