Hampel Matlab vs R
이전 댓글 표시
I am struggeling rewriting matlab code in R as the hampel implementation in matlab seems to be different to the pracma package in R which, according to the window length leaves the lower and upper ends of times series untouched, whicle matlab seems to modify them. I have highlighted the problem already on stackoverflow: https://stackoverflow.com/questions/64631709/hampel-matlab-vs-r
As I would really like to know where the discrepancies are coming from, help is highly appreciated!
With kind regards
CV
답변 (1개)
Bjorn Gustavsson
2020년 11월 9일
0 개 추천
You seem to use different filter lengths in your call to hampel in matlab (30 - which I take to mean you will get a window of 2*30+1 samples, i.e. 30 samples before and 30 samples after the central point) and R (15 which I find very hard to believe gives you a total filter-length of 61.) Since the matlab-code is available to inspect you can simply go to the code to see what's done, R is an open source project so that source-code should also be available. Perhaps R uses median absolute deviation an matlab uses mean absolute deviation? I cant recall what the default of mad in matlab is at the moment.
HTH
댓글 수: 4
Claudio Viecelli
2020년 11월 9일
Bjorn Gustavsson
2020년 11월 9일
Have you compared the source-codes?
Claudio Viecelli
2020년 11월 9일
Bjorn Gustavsson
2020년 11월 9일
My guess for the matlab-hampel's handling is that it simply cuts out all indices that fall outside your array-limits, something like this:
idxWindow = [max(1,idxCentre-K):min(array_length,idxCentre+K)]
and then calculates the mad on that array. You'll have to investigate using a suitably small array where you can change the values at the ends and compare the output with what you'd calculate "by hand", using sensibly small K (3, 4, 5?)...
How R can use the full window-length when it runs outside the array-limits, is a question for someone else, perhaps simply repicating the last element?
카테고리
도움말 센터 및 File Exchange에서 Digital Filtering에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!