MATLAB中detrend函数使用

目录

语法

说明

示例

连续线性趋势

连续二次趋势 

不连续线性趋势


        detrend函数的功能是去除多项式趋势。

语法

y = detrend(x)
y = detrend(x,n)
y = detrend(x,n,bp)
y = detrend(___,nanflag)
y = detrend(___,Name,Value)

说明

        ​y = detrend(x) 从 x 的数据中去除最佳直线拟合线。​

  • 如果 x 是向量,则 detrend 从 x 的元素中减去趋势。

  • 如果 x 是矩阵,则 detrend 分别对每列进行运算,从对应的列中减去每个趋势。

        ​y = detrend(x,n) 去除 n 次多项式趋势。例如,当 n = 0 时,detrend 从 x 中删除均值。当 n = 1 时,detrend 去除线性趋势,这等效于上述语法。当 n = 2 时,detrend 去除二次趋势。​

        ​y = detrend(x,n,bp) 去除由断点 bp 定义段的连续分段趋势。

​        y = detrend(___,nanflag) 指定在使用上述任一语法时如何处理 NaN 值。例如,detrend(x,'omitnan') 在计算趋势之前删除 NaN 值,而 detrend(x,'includenan') 包括这些值(默认)。​

        ​y = detrend(___,Name,Value) 使用一个或多个名称-值对组指定其他参数。例如,detrend(x,1,bp,'Continuous',false) 指定拟合趋势可以有不连续趋势。​

示例

连续线性趋势

        创建一个数据向量,并去除连续线性趋势。绘制原始数据、去趋势后的数据和线性趋势。

t = 0:20;
x = 3*sin(t) + t;
y = detrend(x);
plot(t,x,t,y,t,x-y,':k')
legend('Input Data','Detrended Data','Trend','Location','northwest') 

        如图所示:

连续二次趋势 

        创建一个数据向量,并去除连续二次趋势。绘制原始数据、去趋势后的数据和趋势。

t = 0:20;
x = 20*sin(t) + t.^2;
y = detrend(x,2);
plot(t,x,t,y,t,x-y,':k')
legend('Input Data','Detrended Data','Trend','Location','northwest') 

        如图所示:

不连续线性趋势

        创建一个数据向量,并使用 0 处的断点去除分段线性趋势。指定所得到的输出可以是不连续的。绘制原始数据、去趋势后的数据和趋势。 

t = -10:10;
x = t.^3 + 6*t.^2 + 4*t + 3;
bp = 0;
y = detrend(x,1,bp,'SamplePoints',t,'Continuous',false);
plot(t,x,t,y,t,x-y,':k')
legend('Input Data','Detrended Data','Trend','Location','northwest') 

        如图所示:

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值