I am attempting to analyse a time series with spectral analysis. I am trying to detect any periodicities in my data, which is composed of hourly measurements recorded for one week (24 * 7 = 168 measurements), I aim to show the diurnal component of the temperature variation. So far I have (for example):
clear all
StartDate = '2011-07-01 00:00';
EndDate = '2011-07-07 23:00';
DateTime=datestr(datenum(StartDate,'yyyy-mm-dd HH:MM'):60/(60*24):...
datenum(EndDate,'yyyy-mm-dd HH:MM'),...
'yyyy-mm-dd HH:MM');
DateTime=cellstr(DateTime);
DecDay = datenum(DateTime)-datenum(2011,0,0);
t = 0:25/length(DecDay):(25-0.1488);
x = sin(2*pi*50*t) + sin(2*pi*120*t);
y = x + 2*randn(size(t));
Y = fft(y,length(y));
Where would I go from here? any advice would be much appreciated.
Altered:
clear all
StartDate = '2011-07-01 00:00';
EndDate = '2011-07-07 23:00';
DateTime=datestr(datenum(StartDate,'yyyy-mm-dd HH:MM'):60/(60*24):...
datenum(EndDate,'yyyy-mm-dd HH:MM'),...
'yyyy-mm-dd HH:MM');
DateTime=cellstr(DateTime);
DecDay = datenum(DateTime)-datenum(2011,0,0);
x = cos((2*pi)/12*DecDay)+randn(size(DecDay));
% if you have the signal processing toolbox
[Pxx,F] = periodogram(x,rectwin(length(x)),length(x),1);
plot(F,10*log10(Pxx)); xlabel('Cycles/hour');
ylabel('dB/(Cycles/hour');
Can anyone suggest how I would convert the x axis to hours instead of cycles per hour? I have tried
plot(1./F,10*log10(Pxx)); xlabel('hours');
but this messes up the peridogram.