function dif_error( fileName )
%--------------------------------------------------------------------------
% Error Spectrogram Comparison
%
% Cooper Baker - 2014
%--------------------------------------------------------------------------

close all;

name = 'Error Spectrograms';

% set path
p = genpath( '../../analyze' );
addpath( p );

% get audio file info
fileInfo    = audioinfo( [ fileName, '.classic.wav' ] );
sr          = fileInfo.SampleRate;
samps       = fileInfo.TotalSamples;
winSize     = 512;
halfWinSize = winSize / 2;
overlap     = 4;

% make file names
rawFile  = sprintf( '%s.classic.spect.csv' , fileName );
lockFile = sprintf( '%s.lock.spect.csv', fileName );
peakFile = sprintf( '%s.peak.spect.csv', fileName );
bankFile = sprintf( '%s.bank.spect.csv', fileName );
solaFile = sprintf( '%s.sola.spect.csv', fileName );
olaFile  = sprintf( '%s.ola.spect.csv' , fileName );

% load file data
rawData  = csvread( rawFile  );
lockData = csvread( lockFile );
peakData = csvread( peakFile );
bankData = csvread( bankFile );
solaData = csvread( solaFile );
olaData  = csvread( olaFile  );

% get data size
size = length( rawData );

% calculate msec grid values
msec     = ( samps / sr ) * 1000;
gridMsec = 500;
gridHops = gridMsec / ( ( ( winSize / overlap ) / sr ) * 1000 );
hopSize  = winSize / overlap;
hopMsec  = ( hopSize / sr ) * 1000;

% calculate data maximums
rawMax  = max( rawData  );
lockMax = max( lockData );
peakMax = max( peakData );
bankMax = max( bankData );
solaMax = max( solaData );
olaMax  = max( olaData  );

% find maximum maximum and minimum maximum
MaxMax = max( [ rawMax lockMax peakMax bankMax solaMax olaMax ] );
MinMax = min( [ rawMax lockMax peakMax bankMax solaMax olaMax ] );

% graph formatting
fontName   = 'Times New Roman';
fontSize   = 12;
xTxt       = size * 0.015;
yTxt       = halfWinSize * 0.9;

% set up plot window
fig = figure( 1 );
set( fig, 'Name', sprintf( '%s - %s.wav', name, fileName ) );
set( fig, 'Position', [ 0 0 800 1200 ] );
set( fig, 'defaultAxesFontName', fontName );
set( fig, 'defaultTextFontName', fontName );
set( fig, 'defaultlinelinewidth', 3 );
set( fig, 'defaultaxescolororder', [ 0.8 0.2 0.2 ] );

% color mapping
colormap( [ [ 1 : -0.2/64 : 0.8 ]; ( [ 1 : -0.5/64 : 0.5 ] .^ 10 ) ; [ 1 : -0.5/64 : 0.5 ] .^ 20 ]' );

% plot fft ifft raw
title = 'Classic';
set( subplot( 1, 1, 1 ), 'Position', [ 0.1, 5.5/7, 0.8, 1/7.333 ] );
imagesc( rawData );
axis xy;
axis( [ 0 length( rawData ) 1 halfWinSize ] );
caxis( [ 0 MaxMax ] );
set( gca, 'XTick', [ 0 : gridHops : size ] );
set( gca, 'XTickLabel', [] );
set( gca, 'YTick', [ 1 : ( halfWinSize / ( sr / 4000 ) ) : halfWinSize ] );
set( gca, 'YTickLabel', [ 0 : 2000 : ( sr / 2 ) ] );
text( xTxt, yTxt, title, 'EdgeColor', 'k', 'BackgroundColor', 'w' );
bar = colorbar( 'location', 'East' );
set( get( bar, 'YLabel'), 'String', 'Sones' );
set( get( bar, 'YLabel'), 'Position', [ 0.75 MaxMax * 0.15 ] );

% plot fft ifft phase locked
title = 'Lock';
set( subplot( 6, 1, 2 ), 'Position', [ 0.1, 4.5/7, 0.8, 1/7.333 ] );
imagesc( lockData );
axis xy;
axis( [ 0 length( rawData ) 1 halfWinSize ] );
caxis( [ 0 MaxMax ] );
set( gca, 'XTick', [ 0 : gridHops : size ] );
set( gca, 'XTickLabel', [] );
set( gca, 'YTick', [ 1 : ( halfWinSize / ( sr / 4000 ) ) : halfWinSize ] );
set( gca, 'YTickLabel', [ 0 : 2000 : ( sr / 2 ) ] );
text( xTxt, yTxt, title, 'EdgeColor', 'k', 'BackgroundColor', 'w' );
bar = colorbar( 'location', 'East' );
set( get( bar, 'YLabel'), 'String', 'Sones' );
set( get( bar, 'YLabel'), 'Position', [ 0.75 MaxMax * 0.15 ] );

% plot fft ifft peak tracking
title = 'Peak';
set( subplot( 6, 1, 3 ), 'Position', [ 0.1, 3.5/7, 0.8, 1/7.333 ] );
imagesc( peakData );
axis xy;
axis( [ 0 length( rawData ) 1 halfWinSize ] );
caxis( [ 0 MaxMax ] );
set( gca, 'XTick', [ 0 : gridHops : size ] );
set( gca, 'XTickLabel', [] );
set( gca, 'YTick', [ 1 : ( halfWinSize / ( sr / 4000 ) ) : halfWinSize ] );
set( gca, 'YTickLabel', [ 0 : 2000 : ( sr / 2 ) ] );
text( xTxt, yTxt, title, 'EdgeColor', 'k', 'BackgroundColor', 'w' );
bar = colorbar( 'location', 'East' );
set( get( bar, 'YLabel'), 'String', 'Sones' );
set( get( bar, 'YLabel'), 'Position', [ 0.75 MaxMax * 0.15 ] );

% plot fft oscillator bank
title = 'Bank';
set( subplot( 6, 1, 4 ), 'Position', [ 0.1, 2.5/7, 0.8, 1/7.333 ] );
imagesc( bankData );
axis xy;
axis( [ 0 length( rawData ) 1 halfWinSize ] );
caxis( [ 0 MaxMax ] );
set( gca, 'XTick', [ 0 : gridHops : size ] );
set( gca, 'XTickLabel', [] );
set( gca, 'YTick', [ 1 : ( halfWinSize / ( sr / 4000 ) ) : halfWinSize ] );
set( gca, 'YTickLabel', [ 0 : 2000 : ( sr / 2 ) ] );
text( xTxt, yTxt, title, 'EdgeColor', 'k', 'BackgroundColor', 'w' );
bar = colorbar( 'location', 'East' );
set( get( bar, 'YLabel'), 'String', 'Sones' );
set( get( bar, 'YLabel'), 'Position', [ 0.75 MaxMax * 0.15 ] );

% plot synchronous overlap add
title = 'Sola';
set( subplot( 6, 1, 5 ), 'Position', [ 0.1, 1.5/7, 0.8, 1/7.333 ] );
imagesc( solaData );
axis xy;
axis( [ 0 length( rawData ) 1 halfWinSize ] );
caxis( [ 0 MaxMax ] );
set( gca, 'XTick', [ 0 : gridHops : size ] );
set( gca, 'XTickLabel', [] );
set( gca, 'YTick', [ 1 : ( halfWinSize / ( sr / 4000 ) ) : halfWinSize ] );
set( gca, 'YTickLabel', [ 0 : 2000 : ( sr / 2 ) ] );
text( xTxt, yTxt, title, 'EdgeColor', 'k', 'BackgroundColor', 'w' );
bar = colorbar( 'location', 'East' );
set( get( bar, 'YLabel'), 'String', 'Sones' );
set( get( bar, 'YLabel'), 'Position', [ 0.75 MaxMax * 0.15 ] );

% plot overlap add
title = 'Ola';
set( subplot( 6, 1, 6 ), 'Position', [ 0.1, 0.5/7, 0.8, 1/7.333 ] );
imagesc( olaData );
axis xy;
axis( [ 0 length( rawData ) 1 halfWinSize ] );
caxis( [ 0 MaxMax ] );
set( gca, 'XTick', [ 0 : gridHops : size ] );
set( gca, 'XTickLabel', [ 0 : gridMsec : msec ] );
set( gca, 'YTick', [ 1 : ( halfWinSize / ( sr / 4000 ) ) : halfWinSize ] );
set( gca, 'YTickLabel', [ 0 : 2000 : ( sr / 2 ) ] );
text( xTxt, yTxt, title, 'EdgeColor', 'k', 'BackgroundColor', 'w' );
bar = colorbar( 'location', 'East' );
set( get( bar, 'YLabel'), 'String', 'Sones' );
set( get( bar, 'YLabel'), 'Position', [ 0.75 MaxMax * 0.15 ] );

xlabel( 'Milliseconds' );
ylabel( 'Frequency' );

% tighten up borders
tightfig();

% move y label to middle of graphs
ylabel( 'Frequency', 'Position', [ ( -size / 18 ) ( ( halfWinSize * 6.1666 ) / 2 ) ] );

% write plot to file
hgexport( fig, [ fileName, '.err.spect.eps' ] );

% EOF