% LittleTimeAnalysisDemo.m
% This is a Matlab script.

% reads in a Matlab file and plots the waveform
figure;
signal = wavread('HFaway.wav');
plot(signal); 

% opens a new figure and plots the square of the waveform
figure;
plot(signal.*signal); hold on;
% use the next line instead of the last line for abs of the waveform
% plot(abs(signal)); hold on;    

% experiment with different values for thresh and N
thresh = .2;    % use thresh*max(energy) as threshhold for high energy 
N = 201;        % window size
overlap = 20;   % window overlap

energy = get_energy(signal,N,overlap);
indx = 1:length(energy);

% plot the energy
% (N-overlap)*indx is an array of x that go with the energy
% y-values.  There is one energy value for each (N - overlap) signal
% values.
plot((N-overlap)*indx,energy, 'r','LineWidth',2);

ehigh = (energy>=thresh*max(energy));

my=max(energy)*ones(size(signal));
plot(thresh*my,'g','LineWidth',2);
plot((N-20)*indx,(.01+max(signal.*signal))*ehigh, 'c','LineWidth',2);
line([0 (N-20)*length(energy)], [thresh*max(energy) thresh*max(energy)],'Color','g','LineWidth',2);
