How to Remove Seasonal Cycle?

13 views (last 30 days)
FIONA HOTCHKISS
FIONA HOTCHKISS on 7 Dec 2021
Answered: Star Strider on 7 Dec 2021
%Point Barrow, Alaska
PB=readtable('monthly_flask_co2_ptb.csv');
%create time and CO2 variable
%time
PBdailyt=PB(:,4);
%CO2
PBdailyCO2=PB(:,7);
%take data out of table and put into array
PBt=table2array(PBdailyt);
PBCO2=table2array(PBdailyCO2);
%index to extract outliers
idx = PBCO2 >=450 | PBCO2 <=300 ;
%set outliers equal to NaN
PBCO2(idx) = NaN;
This is my code so far, I am now looking to extract the seasonal cycle. The two different codes I have tried(below) has been unsuccessful. Is there another way I can go about removing the seasonal cycle?
[~,mo,~]=datevec(PBt);
%find the mean of the data
for k=1:12
PBCO2_mean(k) = mean(PBCO2(mo==k),'omitnan');
end
%subtract mean from data to remove seasonal cycle
for k = 1:12
PBCO2_deseasoned(mo==k) = PBCO2(mo==k) - PBCO2_mean(k);
end
and
[~,mo,~]=datevec(LJt);
%mean
PBCO2_mean=ones(12,1);
for i=1:12
idx=find(mo==i);
PBCO2_mean(i)=mean(PBCO2(idx),'omitnan');
end
%remove seasonal cycle
PBCO2_deseasoned=ones(636,1);
for i=1:12
PBCO2_deseasoned(mo==i)=PBCO2(mo==i)-PBCO2_s(i);
end

Answers (1)

Star Strider
Star Strider on 7 Dec 2021
If the seasonal cycle is a narrow frequency band, and the data are sampled at consistent regular intervals, use a bandstop filter to remove it.
.

Categories

Find more on Polynomials in Help Center and File Exchange

Products


Release

R2021a

Community Treasure Hunt

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

Start Hunting!