去趋势函数 detrend
matlab 去趋势 例程
clc clear all close all %创建一个模拟数据集并计算其平均值。 t = 0:300; dailyFluct = gallery('normaldata',size(t),2); sdata = cumsum(dailyFluct) + 20 + t/100; % 算法验证 start tm = mean(t); ym = mean(sdata); sty = mean(t.*sdata) - tm*ym; stt = mean(t.*t) - tm*tm; grad = sty/stt; yint = -grad*tm + ym; detrend_sdata_t = (sdata - (grad*t+ yint)) + 1; trend2 = grad*t+ yint + 1; % 算法验证 end figure plot(t,sdata); legend('Original Data','Location','northwest'); xlabel('Time (days)'); ylabel('Stock Price (dollars)'); %计算去趋势数据,并且从原始数据中移除 detrend_sdata = detrend(sdata); trend = sdata - detrend_sdata; mean(detrend_sdata) hold on plot(t,trend,':r') plot(t,trend2,':g') plot(t,detrend_sdata_t,'m') plot(t,detrend_sdata,'g') plot(t,zeros(size(t)),':k') legend('Original Data','Trend','Detrended Data',... 'Mean of Detrended Data','Location','northwest') xlabel('Time (days)'); ylabel('Stock Price (dollars)');