function plotUltraMSK(name,start,stop)
% PLOTULTRAMSK  plot ultramsk VLF phase and amplitude data files
%	PLOTULTRAMSK(FILENAME) plots all data from FILENAME
%	PLOTULTRAMSK(FILENAME, START) plots from START hour onwards
%	PLOTULTRAMSK(FILENAME, START, STOP) plots data between START and STOP
%	hours
%
%   See also www.ultramsk.com

if nargin < 3, stop = 24; end
if nargin < 2, start = 0; end

data=load(name);
t=data(:,1); % time column
t=t/3600; % convert seconds to hours
index = t>=start & t<stop; %limit plot to this data range

t=t(index);

rc = size(data);
    
    if rc(2) == 3, % time, amplitude, phase data
        a=data(index,2);
        p=data(index,3);
    elseif rc(2) == 5, % time, Xhigh,Yhigh, Xlow,Ylow, data
        xh=data(index,2);
        yh=data(index,3);
        xl=data(index,4);
        yl=data(index,5);
        %average high and low frequency data
        x=(xh+xl)*0.5;
        y=(yh+yl)*0.5;
        a=10*log10(x.^2+y.^2); %amplitude in dB
        p=atan2(y,x)*180/pi; %phase in degrees
    else
        disp('Unknown data format');
        return
    end
    
%possible optional extras 
%decimation
%a=decimate(a,10);
%p=decimate(p,10);
%t=decimate(t,10);

%unwrap phase
%p=unwrap(pi*p/180)*180/pi;

%plot amplitude
subplot(2,1,1)
plot(t,a,'b')
%plot(datenum(0,1,1, t,0,0),a)
%datetick('x',13)
v=axis;
v(1)=start;
v(2)=stop;
axis(v);
    
ylabel('Amplitude (dB)');
title(name);
grid

%plot phase
subplot(2,1,2)
%up=unwrap(p*pi/180)*180/pi;
plot(t,p)
%plot(datenum(0,1,1, t,0,0),p)
%datetick('x',13)

v=axis;
v(1)=start;
v(2)=stop;
axis(v);
ylabel('Phase (degrees)');
xlabel('Time (hours after midnight UTC)');
grid on