How to apply a Hanning filter to a time series?
조회 수: 42 (최근 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.
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
채택된 답변
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');
참고 항목
카테고리
Help Center 및 File Exchange에서 Filter Analysis에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!