function varargout = lotplot(y,wLength,Fs)
% LOTPLOT plot of the lapped orthogonal transform
%
% Example
% varargout = lappedorthoplot(y,wLength,timeVec) 
% 
% plots a spectrogram-like visualisation of the lapped orthogonal
% transform coefficients contained in y
%
% Input
% - y: vector containing the lapped orthogonal transform coefficients
% - wLength: vector containing the lengths of the overlapping windows
% - Fs: (optional, default=44100) sampling frequency
%
% Output
% - varargout{1}: optionally, the function outputs the matrix containing 
% the spectrogram-like representation.
%
% See also lot, ilot

% Author(s): Daniele Barchiesi
% Copyright 2011-2011

if ~exist('Fs','var') || isempty(Fs), Fs = 44100; end
if isscalar(wLength) %create vector of fixed window lengths
    nWindows = floor(length(y)/wLength);
    wLength = wLength*ones(nWindows,1);
end

nWindows = length(wLength);
maxLength = max(wLength);
sigLength = sum(wLength);

timeVec = linspace(0,sigLength/Fs,nWindows); 

S = zeros(maxLength,nWindows);
timeSupp  = @(p) floor(wLength(p)*length(timeVec)/sigLength);
interpFun = @(p,v) interp1(1:wLength(p),abs(v),linspace(1,wLength(p),maxLength))';
S(:,1) = repmat(interpFun(1,y(1:wLength(1))),1,1);
for i=2:nWindows
    S(:,i) = ...
        mag2db(repmat(interpFun(i,y(sum(wLength(1:i-1))+(1:wLength(i)))),1,1));
end

if nargout, varargout{1} = S; end

surf(timeVec,(1:maxLength)/maxLength*Fs/2,S,'EdgeColor','none');
axis xy; axis tight;
colormap(jet);
view(0,90);
set(gca,'YScale','log');
xlabel('time (sec)');
ylabel('frequency (Hz)');