简体   繁体   English

R中的带通滤波器:时间序列结束时的奇怪行为

[英]Band-pass filter in R: weird behaviour at the end of time series

I have this time series 我有这个时间序列

t

            Jan         Feb         Mar         Apr         May         Jun         Jul         Aug         Sep         Oct         Nov         Dec
1922 -0.25108773 -0.27732553 -0.29703807 -0.30274000 -0.30323653 -0.28441682 -0.24106527 -0.18705071 -0.17440826 -0.17291725 -0.19116734 -0.21678948
1923 -0.24487998 -0.26658925 -0.28613991 -0.29674346 -0.29335742 -0.28325761 -0.23326680 -0.18697904 -0.18443807 -0.18144226 -0.18190910 -0.21574376
1924 -0.24465806 -0.27349425 -0.29925888 -0.30386766 -0.30250722 -0.27464960 -0.23390958 -0.19300616 -0.17910621 -0.17869576 -0.19611839 -0.20447324
1925 -0.25326812 -0.27344637 -0.29352971 -0.30947682 -0.30872025 -0.27604449 -0.24065208 -0.19676031 -0.17172229 -0.18484153 -0.19542607 -0.21841577
1926 -0.25214568 -0.27450911 -0.29438956 -0.30392114 -0.30619846 -0.29089168 -0.24829621 -0.20204202 -0.18621514 -0.18808172 -0.19708748 -0.22629595
1927 -0.25107357 -0.27204514 -0.29494695 -0.30751442 -0.30800040 -0.28569694 -0.24655626 -0.19547608 -0.19018517 -0.18866641 -0.20132372 -0.22084811
1928 -0.24733214 -0.27490388 -0.28780308 -0.30407576 -0.30857301 -0.28629658 -0.23872777 -0.19590465 -0.18437917 -0.18274289 -0.19936931 -0.22368973
1929 -0.25531870 -0.27264628 -0.29418746 -0.30385231 -0.31022219 -0.27931003 -0.23404912 -0.19538227 -0.17226595 -0.18465123 -0.19072933 -0.22043396
1930 -0.24735028 -0.27386782 -0.29193707 -0.29925459 -0.30039372 -0.28014958 -0.23551136 -0.19511701 -0.18006660 -0.18282789 -0.20113355 -0.22095253
1931 -0.24903438 -0.27439043 -0.29219506 -0.30312159 -0.30557600 -0.28180333 -0.22676008 -0.19048014 -0.18982644 -0.18459638 -0.19550196 -0.22127202
1932 -0.25870503 -0.27650825 -0.28521052 -0.30685609 -0.30896898 -0.28378619 -0.23614859 -0.18945699 -0.17575919 -0.17820312 -0.19620912 -0.21774873
1933 -0.24187599 -0.25575287 -0.28325644 -0.29554461 -0.29018996 -0.27040369 -0.23514812 -0.19935749 -0.18732198 -0.18606057 -0.19327237 -0.22321366
1934 -0.24793807 -0.26986056 -0.29217378 -0.30479126 -0.30199154 -0.27574924 -0.24097380 -0.18560708 -0.18643606 -0.18501770 -0.19375478 -0.22418002
1935 -0.25587642 -0.27805131 -0.29239104 -0.30784907 -0.30459449 -0.28216514 -0.23839965 -0.20137460 -0.18619998 -0.18328896 -0.20121286 -0.22869388
1936 -0.25322320 -0.28025116 -0.29713940 -0.30800346 -0.31177201 -0.28473251 -0.23552472 -0.20313945 -0.18251793 -0.18383941 -0.20554430 -0.23061875
1937 -0.26268769 -0.28529769 -0.30230641 -0.31107806 -0.30183547 -0.28324508 -0.23840574 -0.19862786 -0.19297314 -0.19392849 -0.19603212 -0.22877177
1938 -0.25445601 -0.28160871 -0.29837676 -0.29879519 -0.30328832 -0.28288226 -0.23577573 -0.19521124 -0.18393512 -0.19039895 -0.20537533 -0.21924241
1939 -0.25180969 -0.28199995 -0.29601764 -0.30147945 -0.30372884 -0.27837795 -0.23720063 -0.19929773 -0.18770674 -0.19341142 -0.20753282 -0.22484697
1940 -0.15145157 -0.16596690 -0.17572643 -0.18225920 -0.18823836 -0.17504012 -0.16019626 -0.12920340 -0.12369614 -0.12024704 -0.12891992 -0.14234080
1941 -0.10045275 -0.11095497 -0.11585389 -0.11932455 -0.11976700 -0.11653216 -0.10259231 -0.08271703 -0.07621320 -0.07184160 -0.07284514 -0.07385666
1942  0.00000000  0.00000000  0.00000000  0.00000000  0.00000000  0.00000000  0.00000000  0.00000000  0.00000000  0.00000000  0.00000000  0.00000000
1943  0.00000000  0.00000000  0.00000000  0.00000000  0.00000000  0.00000000  0.00000000  0.00000000  0.00000000  0.00000000  0.00000000  0.00000000
1944  0.00000000  0.00000000  0.00000000  0.00000000  0.00000000  0.00000000  0.00000000  0.00000000  0.00000000  0.00000000  0.00000000  0.00000000
1945  0.00000000  0.00000000  0.00000000  0.00000000  0.00000000  0.00000000  0.00000000  0.00000000  0.00000000  0.00000000  0.00000000  0.00000000
1946  0.00000000  0.00000000  0.00000000  0.00000000  0.00000000  0.00000000  0.00000000  0.00000000  0.00000000  0.00000000  0.00000000  0.00000000
1947  0.00000000  0.00000000  0.00000000  0.00000000  0.00000000  0.00000000  0.00000000  0.00000000  0.00000000  0.00000000  0.00000000  0.00000000
1948  0.00000000  0.00000000  0.00000000  0.00000000  0.00000000  0.00000000  0.00000000  0.00000000  0.00000000  0.00000000  0.00000000  0.00000000
1949  0.00000000  0.00000000  0.00000000  0.00000000  0.00000000  0.00000000  0.00000000  0.00000000  0.00000000  0.00000000  0.00000000  0.00000000
1950  0.00000000  0.00000000  0.00000000  0.00000000  0.00000000  0.00000000  0.00000000  0.00000000  0.00000000  0.00000000  0.00000000  0.00000000
1951  0.00000000  0.00000000  0.00000000  0.00000000  0.00000000  0.00000000  0.00000000  0.00000000  0.00000000  0.00000000  0.00000000  0.00000000
1952  0.00000000  0.00000000  0.00000000  0.00000000  0.00000000  0.00000000  0.00000000  0.00000000  0.00000000  0.00000000  0.00000000  0.00000000
1953  0.00000000  0.00000000  0.00000000  0.00000000  0.00000000  0.00000000  0.00000000  0.00000000  0.00000000  0.00000000  0.00000000  0.00000000
1954  0.00000000  0.00000000  0.00000000  0.00000000  0.00000000  0.00000000  0.00000000  0.00000000  0.00000000  0.00000000  0.00000000  0.00000000
1955  0.00000000  0.00000000  0.00000000  0.00000000  0.00000000  0.00000000  0.00000000  0.00000000  0.00000000  0.00000000  0.00000000  0.00000000
1956  0.00000000  0.00000000  0.00000000  0.00000000  0.00000000  0.00000000  0.00000000  0.00000000  0.00000000  0.00000000  0.00000000  0.00000000
1957  0.00000000  0.00000000  0.00000000  0.00000000  0.00000000  0.00000000  0.00000000  0.00000000  0.00000000  0.00000000  0.00000000  0.00000000
1958  0.00000000  0.00000000  0.00000000  0.00000000  0.00000000  0.00000000  0.00000000  0.00000000  0.00000000  0.00000000  0.00000000  0.00000000
1959  0.00000000  0.00000000  0.00000000  0.00000000  0.00000000  0.00000000  0.00000000  0.00000000  0.00000000  0.00000000  0.00000000  0.00000000
1960  0.00000000  0.00000000  0.00000000  0.00000000  0.00000000  0.00000000  0.00000000  0.00000000  0.00000000  0.00000000  0.00000000  0.00000000
1961  0.00000000  0.00000000  0.00000000  0.00000000  0.00000000  0.00000000  0.00000000  0.00000000  0.00000000  0.00000000  0.00000000  0.00000000

I am running a band pass filter using the bkfilter function in the mFilter package 我正在使用mFilter包中的bkfilter函数运行带通滤波器

t.bk <- bkfilter(t, pl=9.7,pu=16)

The first plot shows the 'raw' time series t while the second plot shows the cycle component of t.bk . 第一个图显示'原始'时间序列t而第二个图显示t.bk的周期分量。

在此输入图像描述

The red line indicates where t goes to zero and where also the t:Cycle should go to zero. 红线表示t变为零的位置以及t:Cycle应该归零的位置。 However, the latter after the red line is still wobbling.. Any help? 但是,后者红线后仍然摇摆不定..有什么帮助吗?

This is to be expected. 这是可以预料的。 Are you familiar with Gibbs Phenomenon , as it relates to BK-filters (or any finite length filter, for that matter)? 您是否熟悉Gibbs现象 ,因为它与BK滤波器(或任何有限长度滤波器)有关? They oscillate around the power transfer function of the filter. 它们围绕滤波器的功率传递函数振荡。

Here is a paper that discusses a modification to the standard BK-filter to reduce this oscillation, though with more limited input response, of course: http://www.gla.ac.uk/media/media_219052_en.pdf 这篇论文讨论了对标准BK滤波器的修改,以减少这种振荡,但当然输入响应更有限: http//www.gla.ac.uk/media/media_219052_en.pdf

Fortunately for you the mFilter package source code is available on the CRAN website: https://cran.r-project.org/web/packages/mFilter/index.html The file you would modify is written in R--not C like some packages--and is found in mFilter/R/bkfilter.R . 幸运的是,CRAN网站上提供了mFilter软件包源代码: https ://cran.r-project.org/web/packages/mFilter/index.html您要修改的文件是用R编写的 - 而不是像C一样一些软件包 - 可以在mFilter/R/bkfilter.R The part of the function you would modify is here: 您要修改的功能部分如下:

if(type=="fixed")
{
    bb = matrix(0,2*nfix+1,1)
    bb[(nfix+1):(2*nfix+1)] = B[1:(nfix+1)]
    bb[nfix:1] = B[2:(nfix+1)]
    bb = bb-sum(bb)/(2*nfix+1)

    for(i in (nfix+1):(n-nfix))
        AA[i,(i-nfix):(i+nfix)] = t(bb)
}

Compiling and installing packages you have modified is simple. 编译和安装已修改的软件包很简单。 Go to the directory where the mFilter directory is and enter from the shell command line: R CMD INSTALL mFilter . 转到mFilter目录所在的目录,然后从shell命令行输入: R CMD INSTALL mFilter The next time you go into R the mFilter package will use your modified bkFilter() function. 下次进入R时,mFilter包将使用您修改的bkFilter()函数。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM