% Script written by Tanya Leise, Department of Mathematics, Amherst College
% Calls scripts from wmtsa package written by C. Cornish to accompany book 
% Wavelet Methods for Time Series Analysis by Percival & Walden 
% (http://www.atmos.washington.edu/~wmtsa/)
%
% This script plots the maximal overlap discrete wavelet transform of a 
% mouse wheel-running record and of a mouse SCN explant (PER2::LUC biolum).

clear all

filt='la12';

filename = 'OUTSYNC 170 Wheel-TimeSeries.csv';
M=dlmread(filename,',',1,0);
t=M(:,1); % time in hours
Nsteps=numel(t);
wheel=M(:,2); % wheel revolutions in 15 min bins
light=M(:,3); % 0=off 1=on
clear M

J=6;
[WJt, VJt, att] = modwt(wheel, filt,J,'reflection');  % wavelet coefficients
[DJt, ~] = imodwt_details(WJt, filt);    % wavelet details
[SJt, ~] = imodwt_smooth(VJt, filt, J);  % wavelet smooth
fig1=figure;set(fig1,'OuterPosition',[100 500 800 800]);
plot_imodwt_mra(DJt, SJt, wheel, att);   % graphs MRA

filename='SCNexplantLLf.csv';
M=dlmread(filename,',',2,2);
t=24*M(:,1);       % time in hours
Nsteps=numel(t);
biolum=M(:,2);     % counts/sec PER2::LUC, SCN explant from LL female mouse
clear M

J=7;
[WJt, VJt, att] = modwt(biolum, filt,J,'reflection');
[DJt, ~] = imodwt_details(WJt, filt);
[SJt, ~] = imodwt_smooth(VJt, filt, J);
fig1=figure;set(fig1,'OuterPosition',[100 500 600 800]);
plot_imodwt_mra(DJt, SJt, biolum, att);