r - Results from MATLAB's crosscorr function and R's ccf different
问题描述
I'm using MATLAB's crosscorr
function and R's ccf
. For the same data, the results differ. It appears that the lag axis is flipped in one of them. Why is this happening?
I've reproduced the crosscorr
documentation example in both platforms and this is what I see. Any help will be appreciated.
The data for the example can be found here:
R data:
xx <- c(-0.649013765191241, 1.18116604196553, -0.758453297283692, -1.10961303850152, -0.845551240007797, -0.572664866457950, -0.558680764473972, 0.178380225849766, -0.196861446475943, 0.586442621667069, -0.851886969622469, 0.800320709801823, -1.50940472473439, 0.875874147834533, -0.242789536333340, 0.166813439453503, -1.96541870928278, -1.27007139263854, 1.17517126546302, 2.02916018474976, -0.275157240675694, 0.603658445825815, 1.78125189324250, 1.77365832632615, -1.86512257453063, -1.05110705924059, -0.417382047996795, 1.40216228633781, -1.36774699097611, -0.292534999151874, 1.27084843418894, 0.0660093412882059, 0.451290213630776, -0.322209718011896, 0.788409216227425, 0.928736046813314, -0.490790376269763, 1.79720058425494, 0.590696551205452, -0.635785737847226, 0.603346612845761, -0.535247967775900, -0.155080385492789, 0.612122370772160, -1.04434349451734, -0.345631908307050, -1.17140482049761, -0.685586780437283, 0.926216394168962, -1.48167521167231, -0.558057808685045, -0.0284531115706568, -1.47629235201010, 0.258899957160403, -2.01869095243834, 0.199740262298379, 0.425864319131210, -1.27004345059705, -0.485218835743043, 0.594307616829848, -0.276464906639256, -1.85758288592737, 0.0407308117494288, 0.282970177161990, 0.0635612193024994, 0.433430065111595, 0.422860364487685, 1.29952829655200, -1.04979323447507,-1.78641172211092,0.816043081031918, -0.328208543142512, -1.21456561358767,1.11183287253465, -0.507496954829846, 0.898730486034072, 0.377215659958544, 1.45239164558790, 0.446945073178942, 0.645824788453030, -0.623677409296163, -0.595236431548712, 1.61132368718055, -0.348998045314167, 0.164167484938754, -1.63657708517891, 0.581365555343623, -0.128905996910632, 0.432858634222399, -0.245109040039237, -1.08543038934632, 1.68080151955536, 0.176411940863882, -2.07143962693628, 0.211089334851037, -0.582847822547194, 0.0181688430923922, 1.49477799287395, -0.424796733441211, 1.68624315536028)
yy <- c(0, 0, 0, 0, -0.649013765191241, 1.18116604196553, -0.758453297283692, -1.10961303850152, -0.845551240007797, -0.572664866457950, -0.558680764473972, 0.178380225849766, -0.196861446475943, 0.586442621667069, -0.851886969622469, 0.800320709801823, -1.50940472473439, 0.875874147834533, -0.242789536333340, 0.166813439453503,-1.96541870928278, -1.27007139263854, 1.17517126546302, 2.02916018474976,-0.275157240675694, 0.603658445825815, 1.78125189324250, 1.77365832632615, -1.86512257453063, -1.05110705924059,-0.417382047996795, 1.40216228633781,-1.36774699097611, -0.292534999151874, 1.27084843418894, 0.0660093412882059, 0.451290213630776, -0.322209718011896, 0.788409216227425, 0.928736046813314, -0.490790376269763, 1.79720058425494, 0.590696551205452, -0.635785737847226, 0.603346612845761, -0.535247967775900, -0.155080385492789, 0.612122370772160,-1.04434349451734, -0.345631908307050,-1.17140482049761, -0.685586780437283, 0.926216394168962, -1.48167521167231,-0.558057808685045, -0.0284531115706568, -1.47629235201010, 0.258899957160403, -2.01869095243834, 0.199740262298379, 0.425864319131210, -1.27004345059705, -0.485218835743043, 0.594307616829848, -0.276464906639256, -1.85758288592737, 0.0407308117494288, 0.282970177161990, 0.0635612193024994, 0.433430065111595, 0.422860364487685, 1.29952829655200, -1.04979323447507, -1.78641172211092, 0.816043081031918, -0.328208543142512, -1.21456561358767, 1.11183287253465, -0.507496954829846, 0.898730486034072, 0.377215659958544, 1.45239164558790, 0.446945073178942, 0.645824788453030, -0.623677409296163, -0.595236431548712, 1.61132368718055, -0.348998045314167, 0.164167484938754, -1.63657708517891, 0.581365555343623, -0.128905996910632, 0.432858634222399, -0.245109040039237, -1.08543038934632, 1.68080151955536, 0.176411940863882, -2.07143962693628, 0.211089334851037,-0.582847822547194)
ccf (xx, yy)
Matlab data & code:
x = [-0.649013765191241
1.18116604196553
-0.758453297283692
-1.10961303850152
-0.845551240007797
-0.572664866457950
-0.558680764473972
0.178380225849766
-0.196861446475943
0.586442621667069
-0.851886969622469
0.800320709801823
-1.50940472473439
0.875874147834533
-0.242789536333340
0.166813439453503
-1.96541870928278
-1.27007139263854
1.17517126546302
2.02916018474976
-0.275157240675694
0.603658445825815
1.78125189324250
1.77365832632615
-1.86512257453063
-1.05110705924059
-0.417382047996795
1.40216228633781
-1.36774699097611
-0.292534999151874
1.27084843418894
0.0660093412882059
0.451290213630776
-0.322209718011896
0.788409216227425
0.928736046813314
-0.490790376269763
1.79720058425494
0.590696551205452
-0.635785737847226
0.603346612845761
-0.535247967775900
-0.155080385492789
0.612122370772160
-1.04434349451734
-0.345631908307050
-1.17140482049761
-0.685586780437283
0.926216394168962
-1.48167521167231
-0.558057808685045
-0.0284531115706568
-1.47629235201010
0.258899957160403
-2.01869095243834
0.199740262298379
0.425864319131210
-1.27004345059705
-0.485218835743043
0.594307616829848
-0.276464906639256
-1.85758288592737
0.0407308117494288
0.282970177161990
0.0635612193024994
0.433430065111595
0.422860364487685
1.29952829655200
-1.04979323447507
-1.78641172211092
0.816043081031918
-0.328208543142512
-1.21456561358767
1.11183287253465
-0.507496954829846
0.898730486034072
0.377215659958544
1.45239164558790
0.446945073178942
0.645824788453030
-0.623677409296163
-0.595236431548712
1.61132368718055
-0.348998045314167
0.164167484938754
-1.63657708517891
0.581365555343623
-0.128905996910632
0.432858634222399
-0.245109040039237
-1.08543038934632
1.68080151955536
0.176411940863882
-2.07143962693628
0.211089334851037
-0.582847822547194
0.0181688430923922
1.49477799287395
-0.424796733441211
1.68624315536028]
yy = [0
0
0
0
-0.649013765191241
1.18116604196553
-0.758453297283692
-1.10961303850152
-0.845551240007797
-0.572664866457950
-0.558680764473972
0.178380225849766
-0.196861446475943
0.586442621667069
-0.851886969622469
0.800320709801823
-1.50940472473439
0.875874147834533
-0.242789536333340
0.166813439453503
-1.96541870928278
-1.27007139263854
1.17517126546302
2.02916018474976
-0.275157240675694
0.603658445825815
1.78125189324250
1.77365832632615
-1.86512257453063
-1.05110705924059
-0.417382047996795
1.40216228633781
-1.36774699097611
-0.292534999151874
1.27084843418894
0.0660093412882059
0.451290213630776
-0.322209718011896
0.788409216227425
0.928736046813314
-0.490790376269763
1.79720058425494
0.590696551205452
-0.635785737847226
0.603346612845761
-0.535247967775900
-0.155080385492789
0.612122370772160
-1.04434349451734
-0.345631908307050
-1.17140482049761
-0.685586780437283
0.926216394168962
-1.48167521167231
-0.558057808685045
-0.0284531115706568
-1.47629235201010
0.258899957160403
-2.01869095243834
0.199740262298379
0.425864319131210
-1.27004345059705
-0.485218835743043
0.594307616829848
-0.276464906639256
-1.85758288592737
0.0407308117494288
0.282970177161990
0.0635612193024994
0.433430065111595
0.422860364487685
1.29952829655200
-1.04979323447507
-1.78641172211092
0.816043081031918
-0.328208543142512
-1.21456561358767
1.11183287253465
-0.507496954829846
0.898730486034072
0.377215659958544
1.45239164558790
0.446945073178942
0.645824788453030
-0.623677409296163
-0.595236431548712
1.61132368718055
-0.348998045314167
0.164167484938754
-1.63657708517891
0.581365555343623
-0.128905996910632
0.432858634222399
-0.245109040039237
-1.08543038934632
1.68080151955536
0.176411940863882
-2.07143962693628
0.211089334851037
-0.582847822547194]
[XCF,lags,bounds] = crosscorr(xx,yy);
解决方案
推荐阅读
- javascript - 如何找到加载缓慢的 SAPUI5 应用程序的加载瓶颈
- cmd - 在多个 Windows Server 子目录中运行特定程序
- windows - 如何获取完整的剪贴板内容,包括格式和链接?
- sql-server - EF Code First:无法连接到本地 SQL 服务器数据库
- mod-security - 即使启用了 SecRequestBodyAccess,Modsecurity 也不会检查 POST 数据
- reactjs - 材质 UI 网格项目在 Safari 上溢出其网格容器
- java - Spring Webflux - 文件上传大小限制(spring.servlet.multipart.max-file-size 不起作用)
- python-3.x - 如何在pyspark或python中建立父子关系?
- powershell - 为什么在这个例子中我需要子表达式操作符?
- git - 为什么flutter pub找不到我的github ssh-key?