什么这个Butterworth过滤器在R和Matlab中显示不同

什么这个Butterworth过滤器在R和Matlab中显示不同

本文介绍了为什么这个Butterworth过滤器在R和Matlab中显示不同的结果?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试对R中的数据使用20Hz低通滤波器,但是当我使用filtfilt函数时,曲线图与matlab不同.

I'm trying to use a 20Hz low pass filter on data in R, but when I use the filtfilt function, the plot is different from the matlab.

我在R中使用以下代码:

I'm using the following code in R:

fc<-20
fs<-100
Wn<-pi*fc/(2*fs)
testar<- butter(5, Wn, type="low")
L2<- signal::filtfilt(testar,Tabela$posicao)
plot(Tabela$tempo, L2, type = "l", col="red")

matlab代码为:

The matlab code is:

fc=20;
fs=100;
Wn=pi*fc/(2*fs);
[b,a] = butter(5,Wn,'low');
posfilt= filtfilt(b,a,Tabela.posicao);

在matlab中的图是:

The plot in matlab is:

R一:

为什么R一个在图的开头和结尾显示这些变化?

why the R one is presenting those variation in the begin and in the end of the graph?

推荐答案

我预感到不同之处在于每个版本处理最终效应瞬态的方式.

I have hunch that the difference is in how each version handles end-effect transients.

您的信号具有较大的DC偏移(〜875 ).如果您认为录制前后信号为零 0 .信号开始处的跳变由滤波器处理,并被视为伪像或最终效果.这些最终效果是您在R版本的滤波信号中看到的.

Your signal has a large DC-offset (~875). If you think of the signal as being zero 0 before and after the recording. The jump at the start of the signal gets processed by the filter and is seen as an artifact or end-effect. These end-effects are what you see in the R version of the filtered signal.

来自 filtfilt 的R文档,此版本较旧,可能无法最小化结束瞬态( R'filtfilt'文档).另一方面,MATLAB版本的 filtfilt 可以做到.引用MATLAB文档:

From the R documentation from filtfilt this version is old and likely doesn't minimize the end transients (R 'filtfilt' docs). On the other hand the MATLAB version of filtfilt does; Quoting from the MATLAB documentation:

" filtfilt 通过匹配最小化启动和结束瞬态初始条件.不要对微分器和希尔伯特FIR滤波器使用'filtfilt',因为这些滤波器的操作在很大程度上取决于它们的相位响应." FILTFILT文档

"filtfilt minimizes start-up and ending transients by matching initial conditions. Do not use 'filtfilt' with differentiator and Hilbert FIR filters, because the operation of these filters depends heavily on their phase response." FILTFILT Documentation

这篇关于为什么这个Butterworth过滤器在R和Matlab中显示不同的结果?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-20 00:20