How to deseasonalize this temperature record?
조회 수: 9 (최근 30일)
이전 댓글 표시
Hi all!
I have a temperature record (Temp.mat) that holds hourly temperature information from 2005 to 2019. Can anyone please give me an idea on how to deseasonalize the data?
any feedback will be greatly appreciated!!
댓글 수: 0
채택된 답변
Image Analyst
2023년 4월 28일
If you have the Signal Processing Toolbox, I'd use a Savitzky-Golay filter, sgolayfilt, with a third order polynomial and a window size of about 3 months. This will give you something like a sine wave. Then you can subtract that smoothed signal from your original signal to get the hourly deviation from the "average" for that time.
Try this:
fontSize = 16;
s = load('Temperatures.mat')
temps = s.Temp;
subplot(3, 1, 1);
plot(temps, 'b-')
xlabel('Hour', 'FontSize', fontSize)
ylabel('Temperature', 'FontSize', fontSize)
grid on;
title('Actual Temperature', 'FontSize', fontSize)
% Smooth the signal.
windowLength = round(numel(temps) / 60);
% Make sure it's odd
if rem(windowLength, 2) == 0
windowLength = windowLength + 1
end
smoothedTemps = sgolayfilt(temps, 2, windowLength);
subplot(3, 1, 2);
plot(smoothedTemps, 'r-');
xlabel('Hour', 'FontSize', fontSize)
ylabel('Temperature', 'FontSize', fontSize)
title('Seasonal Average Temperature', 'FontSize', fontSize)
grid on;
% Get the deviation from average.
deviationtemps = temps - smoothedTemps;
subplot(3, 1, 3);
plot(deviationtemps, 'b-');
xlabel('Hour', 'FontSize', fontSize)
ylabel('Temperature', 'FontSize', fontSize)
grid on;
title('Detrended Temperature', 'FontSize', fontSize)
If you want, you can get the average of all the years and synthesize a smoothed signal from that. Or you can use interp1 to fill in gaps in your original data.
댓글 수: 10
Image Analyst
2023년 5월 17일
I'd again use the Savitzky Golay filter because sine and cosine can be thought of as polynomials (recall the taylor series expansions of them). So then after it's smoothed, find the valleys with findpeaks. Then extract the signal (or smoothed signal) between each valley to get one hump. Then average all the humps together to get an average season, averaged over several years. Then fit that to a polynomial with polyfit or to a sine or cosine with fitnlm. to get the formula (if you need the formula). Then replicate the fitted data and subtract it from your signal.
추가 답변 (1개)
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!