%Class for CO907. %__________________________________________ %Author: Jiarui Cao %Date: 19 Nov 2013 %Purpose: Problem Sheet 2. Q2.4 close all; clear all; clc; clf; %% Load data %set file path filepath =['/Users/...']; %The code below are generated from 'import data'. filename1=[filepath 'ftse.dat']; delimiter = '\t'; startRow = 2; formatSpec = '%f%f%[^\n\r]'; fileID = fopen(filename1,'r'); dataArray = textscan(fileID, formatSpec, 'Delimiter', delimiter, 'EmptyValue' ,NaN,'HeaderLines' ,startRow-1, 'ReturnOnError', false); Day = dataArray{:, 1}; FTSE = dataArray{:, 2}; fclose(fileID); filename2=[filepath 'xray.dat']; delimiter = ' '; startRow = 6; formatSpec = '%f%f%*s%*s%*s%*s%[^\n\r]'; fileID = fopen(filename2,'r'); dataArray = textscan(fileID, formatSpec, 'Delimiter', delimiter, 'MultipleDelimsAsOne', true, 'EmptyValue' ,NaN,'HeaderLines' ,startRow-1, 'ReturnOnError', false); fclose(fileID); t = dataArray{:, 1}; xray = dataArray{:, 2}; filename3=[filepath 'temperatureanomaly.dat']; Temp=load(filename3); Month =1:1:length(Temp); %% Plot the raw data. %%Notice: we only give the simple plots of the unprocessed data here. After %%that you need find a clever way to pre-process your data, as required by %%the problem. % % plot(Day,FTSE,'om'); % xlabel('day'); % ylabel('FTSE'); % figure() % plot(t,xray,'sb'); % xlabel('time'); % ylabel('x-ray'); % figure() % plot(Month,Temp,'xr'); % xlabel('month'); % ylabel('temp'); %% Generate and plot autocorrelation functions autocorr(xray,1000); % you need 'autocorr' package in Econometrics Toolbox %%Or use xcorr to calculate the autocorrelation figure() xray=xray-mean(xray); %center data c=xcorr(xray,'unbiased'); % unbiased is an option of xcorr, say help file for detail m=(length(c)+1)/2; % take the middle point c=c./c(m); % normalise correlation %c2=c(m:length(c)); c2=c(m:m+1000); plot(c2,'ob');