How to Decompose Time Series Data into Trend and Seasonality?

166 views (last 30 days)
carolina
carolina on 22 Mar 2021
Answered: Michelle Hirsch on 24 Sep 2021
I have a time series with predictive temperature and real temperature. I need to decompose a time series into components. Some components from time series are level, trend,seasonality and one component called noise.
Where the components are added together as follows:
Time series = Level + Trend + Seasonality + Noise
Noise=Time series- seasonality –trend
The purpose of decomposing the time series is to easily analyze the behavior of the results over time
This is the original predicted temperature time series which shows a nonlinear trend
I tried to remove the trend, this is the result it provided
Here is the code I have used
clear
close all
load StepOutTemp__Estacion.mat
%Señal de Temperatura Predicha
x=1:1:100
ptemp=cell2mat(matriz_results(88277:88376,3:3))'
ordsignal=6
coeficient=polyfit(x,ptemp,6)
[p,s,mu]=polyfit(x,ptemp,ordsignal)
f_y=polyval(p,x,[],mu)
rtrend=ptemp-f_y
subplot(2,1,1)
plot(x,ptemp),grid
title('Tiempo de Predicción adelante: 60 minutos'),ylabel('Temperatura en °C')
subplot(2,1,2)
plot(x,rtrend),grid
xlabel('Muestras de Tiempo'),ylabel('Temperatura en °C')
title('Tiempo de Predicción adelante: 60 minutos-Sin Tendencia')
The ordsignalis the orden a function.
Remove trends from Data
https://www.mathworks.com/help/signal/ug/remove-trends-from-data.html
I need to show a similar result or if maybe there is a tool to decompose a time series into
components. I have not been able to estimate noise or residual components and seasonality. Thanks in advance for your help.

Answers (2)


Shashank Gupta
Shashank Gupta on 25 Mar 2021
Hi Carolina,
MATLAB as of now does not have an explicite function for decomposition of time series data. But there are workaround to get these components. Check out this resource material. The trend can be estimated easily through moving average filter, look at this doc page. Similarly, seasonal component can also be estimated by parameteric estimated model, this link should help you. the remaining component you can find out by simply substracting each one of them by original signal (assuming the model is additive in nature).
I hope this helps you.
Cheers.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!