Вы находитесь на странице: 1из 3

%----------------------------------------------------------------------

% PLOT DATA
%----------------------------------------------------------------------
s4=xlsread('Data Asli.xlsx','Data CH','C2:C301');
%s4=xlsread('Data Asli.xlsx','Data Nino 3.4','C2:C301');
%s4=xlsread('Data Asli.xlsx','Data DMI','C2:C301');
%s4=xlsread('Data Asli.xlsx','Data AUSMI','C2:C301');
%s4=xlsread('Data Asli.xlsx','Data Temp','C2:C493');
%s4=s4(121:420,1:3);
%s4=xlsread('Data Asli.xlsx','Data Temp 83','C2:C301');

%display gambar
figure();
plot(s4,'r');
ylabel('Curah Hujan','Fontsize',12');
xlabel('Bulanan','Fontsize',12');

%----------------------------------------------------------------------
% DO FFT
%----------------------------------------------------------------------
s4=detrend(s4);
nt=length(s4(:,1));%number of data points used for the FFT computation.
t = (0:nt-1)';

%2)Compute the Fourier Transform at twice as many frequencies


%as there are time observations. Since only the first
%1-(N/2)/N frequencies are useful, this step ensures that
%we will have at least the same resolution in frequency
%space as it has in time.
nf2 = 2*floor(nt/2);

%3)Perform the Fourier Transform:


s4_pxx = fft(s4,nf2);

%% 4) Compute the frequencies (eg., cylces/unit of time) where the fourier


%transform was performed and is useful:
nf = floor(nf2/2); %number of useful frequencies:
f = (0:(nf-1))'/nt;

%Use only the first nf2/2 values:


s4_pxx = s4_pxx(1:nf);

%% 5) Plot the length (absolute value) of the fft power at each frequency
plot(f,abs(s4_pxx))

%% 6) Perform a "White Noise" significane test:


%Ho: The peaks in the power spectrum are not signficantly different from
%random "white" (uncorrelated in time) data.
% nr = 100;
% std_s4 = std(s4);
%for i = 1:nr
% xrand = randn(size(s4));
% pxx_rand = fft(xrand*std_s4,nf2);
% pxx_rand = pxx_rand(1:nf);
%U(:,i) = abs(pxx_rand);
%end

%Sort the rows of U so that the first row has ALL the lowest powered
%values at each frequency:
% U = sort(U);

%Plot the 95th row (e.g., "95% confidence limits") as well as the
%"raw" power spectrum (abs(s4_pxx) in this case):
%clv95ind = floor(.95*nr);
%clv95 = U(:,clv95ind)';

%figure(2)
%hold on
%plot(f,abs(s4_pxx),'k','LineWidth',2);
%plot(f,[clv95],'r','LineWidth',1);

%plot setelah FFT


p=1./f; %periode
figure()
hold on
plot(p,abs(s4_pxx),'k','LineWidth',2);
%plot(p,[clv95],'r','LineWidth',1);
ylabel('Power ((mm^2)','Fontsize',12');
xlabel('Periode (Bulanan)','Fontsize',12');

%------------------------------------------------------------------------
% BandPass Filter
%------------------------------------------------------------------------
s4=s4-mean(s4);
dt=1;%sampling interval--> perhatikan time series data kita
fs=1/dt;%sampling frequency
fnyq=fs/2;%nayquist frequency

%-----------------------------
%LOW PASS
%-----------------------------
%iT=11;%cut off period-->memotong periode yg kita pengenin (Tahunan)
iT=28;%setengah tahunan
cf1=1/iT;%cut off frequency
[bl, al] = butter(4, cf1/fnyq, 'low'); %making window
%Do Low-pass
ylp=filtfilt(bl,al,s4);

%Plot original time series vs filtered time series


%figure()
%plot(ylp);%keluaran terakhir, ato inputan
%hold on
%plot(s4,'r');
%grid on

%---------------------------
%HIGH PASS
%---------------------------
%iT=14;%cut off period-->memotong periode yg kita pengenin (Tahunan)
iT=64;%setengah tahunan
cf1=1/iT;%cut off frequency
[bl, al] = butter(5, cf1/fnyq, 'high'); %making window
%HIGH PASS
ylp_high=filtfilt(bl,al,ylp);%bl,al, window. y=fungsinya

%Plot Bandpass Vs Data Asli


figure()
plot(ylp_high,'k','LineWidth',2);%keluaran terakhir, ato inputan
hold on
plot(s4-mean(s4),'r','LineWidth',1);
hold on
ylabel('Data','Fontsize',12');
xlabel('Period (Month)','Fontsize',12');
%plot(ylp_1,'k');
%grid on

%---------------------------------------------------------------------
% KORELASI
%---------------------------------------------------------------------
[r1,lag1]=crosscorr(ylp_high_index,ylp_high_data);
createfigure(lag1, r1);

%---------------------------------------------------------------------
% CUPLIK
%---------------------------------------------------------------------
s4=xlsread('Data Asli.xlsx','Data Temp','A2:C493');%Temperatur
s4_cuplik=s4(121:420,1:3);

%---------------------------------------------------------------------
% DATA HARIAN JADI BULANAN
%---------------------------------------------------------------------
clear all; close all; clc;
% Load data harian
harian_75 = xlsread('AUSMI_1973.xlsx','sheet3','B1:C366');
% Konversi harian-bulanan
tahun = 1975;
bulan = 1:12;
p = 1;
q = eomday(tahun(1),bulan(1));
for t = 1:length(tahun)
for b = 1:length(bulan)
bulanan(t,b) = nansum(harian_75(p:q)/q);
p = q + 1;
q = q + eomday(tahun(t),bulan(b));
end
end

Вам также может понравиться