How to apply a Hanning filter to a time series?
49 次查看(过去 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](https://www.mathworks.com/matlabcentral/answers/uploaded_files/251120/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](https://www.mathworks.com/matlabcentral/answers/uploaded_files/251121/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.
0 个评论
采纳的回答
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 个)
Alessandro La Chioma
2022-3-3
Hi
I think you should normalize the filter kernel:
win = hann(10);
win = win/sum(win); % Normalization
filtered = conv(b2,win,'same');
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!