% Solution BTM exercise 6
% author: Ronni Grapenthin
%
% I encourage you to read the assignment in parallel to this code as
% comments so you get a better feeling for how to turn such instructions
% into code.

clear all , close all , clc ;

% read dates and temperatures 
[dates, temps] = textread('FAI_temps.txt', '%d%f', 'headerlines', 1);

d_nums = datenum(num2str(dates), 'yyyymmdd');
ticks  = datenum({'19801001', '19851001', '19901001', '19951001', '20001001', '20051001', '20101001'}, 'yyyymmdd');

figure
plot(d_nums, temps) 
set(gca, 'XTick', ticks)
axis tight

figure
hold on
plot(d_nums, temps) 
set(gca, 'XTick', ticks, 'XTickLabel', datestr(ticks, 'yyyy-mm'), 'FontSize', 12)
xlabel('Date (YYYY/MM/DD)', 'FontSize', 12)
ylabel('Temp \circF', 'FontSize', 12)
title('Temperature Fairbanks Intl Airport', 'FontSize', 12, 'FontWeight', 'bold')
plot(d_nums, smooth(temps, 365), 'r', 'LineWidth', 2)
legend('measured T', 'smoothed over 365 days')
axis tight

figure
a1 = axes('Position', [.1 .65 .89 .3]);
hold on
plot(a1, d_nums, temps) 
set(gca, 'XTick', ticks, 'XTickLabel', datestr(ticks, 'yyyy-mm'), 'FontSize', 12)
xlabel('Date (YYYY/MM/DD)', 'FontSize', 12)
ylabel('Temp \circF', 'FontSize', 12)
title('Temperature Fairbanks Intl Airport', 'FontSize', 12, 'FontWeight', 'bold')
plot(a1, d_nums, smooth(temps, 365), 'r', 'LineWidth', 2)
legend('measured T', 'smoothed over 365 days')
axis tight

a2 = axes('Position', [.1 .1 .89 .5]);
spectrogram(temps, 180, 90, 128, 1/(24*60*60), 'yaxis')
