# plotsigdiff

## PURPOSE

Function to plot significant differences between two time-frequency arrays X1 and X2

## SYNOPSIS

function [mask,Xdiff]=plotsigdiff(X1,X1err,X2,X2err,plt,t,f)

## DESCRIPTION

     Function to plot significant differences between two time-frequency arrays X1 and X2
     given errors X1err, X2err.
     Usage: mask=plotsigdiff(X1,X1err,X2,X2err,plt,t,f)

     X1 err and X2err contain upper and lower confidence intervals for X1 and X2
     The plot generated is shows X1-X2 where the difference is significant
     either in dB or on a linear scale.

     Inputs:
     X1: input array t x f. Can also be a function of just the frequency.
     X1err: lower and upper confidence intervals for X1: lower/upper x t x f
     X2: input array t x f. if vector then as row vector
     X2err: lower and upper condidence intervals for X2: lower/upper x t x f
     plt: 'l' for log, 'nl' for no log,'n' for no plot at all.
     t: t axis grid for plot. If X1,X2 are vectors, then specify t=1.
     f: f axis grid for plot.

     Outputs:
     mask: +1 for all t-f (or f) indices for which the X1 significantly greater than
     X2, -1 for all t-f (or f) indices for which X1 is significantly less than X2,
     and zero otherwise

     Xdiff: X1-X2

## CROSS-REFERENCE INFORMATION

This function calls:

- check_consistency Helper routine to check consistency of data dimensions

This function is called by:

## SOURCE CODE

    0001 function [mask,Xdiff]=plotsigdiff(X1,X1err,X2,X2err,plt,t,f)
    0002 % Function to plot significant differences between two time-frequency arrays X1 and X2
    0003 % given errors X1err, X2err.
    0004 % Usage: mask=plotsigdiff(X1,X1err,X2,X2err,plt,t,f)
    0005 %
    0006 % X1 err and X2err contain upper and lower confidence intervals for X1 and X2
    0007 % The plot generated is shows X1-X2 where the difference is significant
    0008 % either in dB or on a linear scale.
    0009 %
    0010 % Inputs:
    0011 % X1: input array t x f. Can also be a function of just the frequency.
    0012 % X1err: lower and upper confidence intervals for X1: lower/upper x t x f
    0013 % X2: input array t x f. if vector then as row vector
    0014 % X2err: lower and upper condidence intervals for X2: lower/upper x t x f
    0015 % plt: 'l' for log, 'nl' for no log,'n' for no plot at all.
    0016 % t: t axis grid for plot. If X1,X2 are vectors, then specify t=1.
    0017 % f: f axis grid for plot.
    0018 %
    0019 % Outputs:
    0020 % mask: +1 for all t-f (or f) indices for which the X1 significantly greater than
    0021 % X2, -1 for all t-f (or f) indices for which X1 is significantly less than X2,
    0022 % and zero otherwise
    0023 %
    0024 % Xdiff: X1-X2
    0025 %
    0026 if nargin < 7; error('Need all arguments'); end;
    0027 % [T1,F1]=size(X1); [T2,F2]=size(X2);
    0028 [T,F]=check_consistency(X1,X2);
    0029 if F==1;
    0030     X1=X1'; X2=X2';F=length(X1); T=1;
    0031 end;
    0032 ystr='';
    0033 if T==1,
    0034     mask=zeros(1,F);
    0035     indxneg=find(X1<X2err(1,:) & X2>X1err(2,:));
    0036     indxpos=find(X1>X2err(2,:) & X2<X1err(1,:));
    0037     mask(indxneg)=-1;
    0038     mask(indxpos)=+1;
    0039     if strcmp(plt,'l');
    0040         X1=10*log10(X1); X2=10*log10(X2); X1err=10*log10(X1err); X2err=10*log10(X2err);
    0041         ystr= '  dB';
    0042     end;
    0043     subplot(311); plot(f,X1,f,X1err(1,:),f,X1err(2,:));
    0044     title('Spectrum 1');
    0045     xlabel('f')
    0046     ylabel(['S1' ystr]);
    0047     subplot(312); plot(f,X2,f,X2err(1,:),f,X2err(2,:));
    0048     title('Spectrum 2');
    0049     xlabel('f')
    0050     ylabel(['S2' ystr]);
    0051     subplot(313); plot(f,mask.*(X1-X2));
    0052     title('Difference where significant');
    0053     xlabel('f')
    0054     ylabel(['S1-S2' ystr]);
    0055 else
    0056     mask=zeros(T,F);
    0057     for n=1:length(t);
    0058         for m=1:length(f);
    0059            if X1(n,m)<X2err(1,n,m) && X2(n,m)>X1err(2,n,m);
    0060               mask(n,m)=-1;
    0061            elseif X2(n,m)<X1err(1,n,m) && X1(n,m)>X2err(2,n,m);
    0062               mask(n,m)=+1;
    0063            end;
    0064         end;
    0065     end;
    0066     if strcmp(plt,'l');
    0067        X1=10*log10(X1);X2=10*log10(X2); %X1err=10*log10(X1err); X2err=10*log10(X2err);
    0068         ystr='  dB';
    0069     end;
    0070     if ~strcmp(plt,'n');
    0071         subplot(311); imagesc(t,f,X1'); axis xy; colorbar;
    0072         xlabel('f')
    0073         ylabel(['S1' ystr]);
    0074         subplot(312); imagesc(t,f,X2'); axis xy; colorbar;
    0075         xlabel('f')
    0076         ylabel(['S2' ystr]);
    0077     %     subplot(313); imagesc(t,f,(mask.*(X1-X2))'); axis xy; colorbar
    0078         subplot(313); imagesc(t,f,mask'); axis xy; colorbar
    0079         xlabel('f')
    0080         ylabel('Significance');
    0081     end;
    0082 end
    0083 Xdiff=X1-X2;