function [filtered_data]=COFilter_linear(data)

%This M-file will take in the CO2 data provided on Garcia's website,
%perform a fourier transform, filter out the components closest to 1 cycle
%per year, and transform back to the time domain

N=length(data);         %Number of Samples
Fs=24;                       %24 samples per year
time=(1:N)/Fs;               %time increments (years)
tau=1/Fs;                    %Sampling time 1 year per 24 samples
f=(0:N-1)*(Fs/N);            %Frequency values

c=polyfit(time,data',1)         %Fit line to data
trend=polyval(c,time)'           %Evaluate line at time points
data_without_trend=data-trend;  %Subtract linear behavior

freqdata=fft(data_without_trend);     %perform DFT on data 

for i=1:(N/2)
    
    if floor(f(i))==1                                 %Frequency is nearly 1 cycle per year
        freqdata(i)=0;freqdata(i-1)=0;                              %Kill componet
        freqdata(N+2-i)=0;freqdata(N+3-i)=0;                              %Kills its reflection about Nyquist frequency
        break;    
    end
    
end

inv=ifft(freqdata);                           %Take inverse transform back to time domain
filtered_data=inv+trend;

plot(time,data,'b',time,filtered_data,'r');
Title('CO2 Concentration In Parts Per Million (?)');
xlabel('Years');ylabel('Atmospheric C02 (Parts Per Million?)');
legend('Actual Data','Filtered Data');


     