I am trying to eliminate seasonality from my data using Fourier analysis in MATLAB. Following this post https://stackoverflow.com/questions/19285684/fast-fourier-transform-for-deasonalizing-data-in-matlab?answertab=oldest#tab-top I came up with this code:
clear; clc; close all; % load(fullfile(matlabroot,'examples','econ','Data_Accidental.mat')) % y = Data; T = length(y); years = linspace(1973,1979,T); ts = y; points_in_year = 12; % tim = (dates - dates(1))/(dates(2)-dates(1)); % <-- acquisition times for your *new* data, normalized NFpick = [2 7 13]; % <-- channels you picked to build the detrending baseline (peaks to be eliminated) % Compute the trend mu = mean(ts); Nchannels = length(ts); % <-- size of time domain data Mpick = 2*length(NFpick); X(:,1:2:Mpick) = cos(2*pi*(NFpick-1)'/Nchannels*tim')'; X(:,2:2:Mpick) = sin(-2*pi*(NFpick-1)'/Nchannels*tim')'; X = [ones(T,1), X]; beta = X\ts; trend = X*beta; detrended = y - trend + mu; figure plot(dates,detrended)
Notice that I am trying to avoid the use of fft. My problem is that I am not obtaining the same answer that https://www.mathworks.com/help/econ/seasonal-adjustment.html even changing the channels correspondent to the peaks I want to eliminate.
What is wrong with my approach?
How should I change my code to eliminate the seasonality using Fourier analysis?