plotsigdiff.m 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. function [mask,Xdiff]=plotsigdiff(X1,X1err,X2,X2err,plt,t,f)
  2. % Function to plot significant differences between two time-frequency arrays X1 and X2
  3. % given errors X1err, X2err.
  4. % Usage: mask=plotsigdiff(X1,X1err,X2,X2err,plt,t,f)
  5. %
  6. % X1 err and X2err contain upper and lower confidence intervals for X1 and X2
  7. % The plot generated is shows X1-X2 where the difference is significant
  8. % either in dB or on a linear scale.
  9. %
  10. % Inputs:
  11. % X1: input array t x f. Can also be a function of just the frequency.
  12. % X1err: lower and upper confidence intervals for X1: lower/upper x t x f
  13. % X2: input array t x f. if vector then as row vector
  14. % X2err: lower and upper condidence intervals for X2: lower/upper x t x f
  15. % plt: 'l' for log, 'nl' for no log,'n' for no plot at all.
  16. % t: t axis grid for plot. If X1,X2 are vectors, then specify t=1.
  17. % f: f axis grid for plot.
  18. %
  19. % Outputs:
  20. % mask: +1 for all t-f (or f) indices for which the X1 significantly greater than
  21. % X2, -1 for all t-f (or f) indices for which X1 is significantly less than X2,
  22. % and zero otherwise
  23. %
  24. % Xdiff: X1-X2
  25. %
  26. if nargin < 7; error('Need all arguments'); end;
  27. % [T1,F1]=size(X1); [T2,F2]=size(X2);
  28. [T,F]=check_consistency(X1,X2);
  29. if F==1;
  30. X1=X1'; X2=X2';F=length(X1); T=1;
  31. end;
  32. ystr='';
  33. if T==1,
  34. mask=zeros(1,F);
  35. indxneg=find(X1<X2err(1,:) & X2>X1err(2,:));
  36. indxpos=find(X1>X2err(2,:) & X2<X1err(1,:));
  37. mask(indxneg)=-1;
  38. mask(indxpos)=+1;
  39. if strcmp(plt,'l');
  40. X1=10*log10(X1); X2=10*log10(X2); X1err=10*log10(X1err); X2err=10*log10(X2err);
  41. ystr= ' dB';
  42. end;
  43. subplot(311); plot(f,X1,f,X1err(1,:),f,X1err(2,:));
  44. title('Spectrum 1');
  45. xlabel('f')
  46. ylabel(['S1' ystr]);
  47. subplot(312); plot(f,X2,f,X2err(1,:),f,X2err(2,:));
  48. title('Spectrum 2');
  49. xlabel('f')
  50. ylabel(['S2' ystr]);
  51. subplot(313); plot(f,mask.*(X1-X2));
  52. title('Difference where significant');
  53. xlabel('f')
  54. ylabel(['S1-S2' ystr]);
  55. else
  56. mask=zeros(T,F);
  57. for n=1:length(t);
  58. for m=1:length(f);
  59. if X1(n,m)<X2err(1,n,m) && X2(n,m)>X1err(2,n,m);
  60. mask(n,m)=-1;
  61. elseif X2(n,m)<X1err(1,n,m) && X1(n,m)>X2err(2,n,m);
  62. mask(n,m)=+1;
  63. end;
  64. end;
  65. end;
  66. if strcmp(plt,'l');
  67. X1=10*log10(X1);X2=10*log10(X2); %X1err=10*log10(X1err); X2err=10*log10(X2err);
  68. ystr=' dB';
  69. end;
  70. if ~strcmp(plt,'n');
  71. subplot(311); imagesc(t,f,X1'); axis xy; colorbar;
  72. xlabel('f')
  73. ylabel(['S1' ystr]);
  74. subplot(312); imagesc(t,f,X2'); axis xy; colorbar;
  75. xlabel('f')
  76. ylabel(['S2' ystr]);
  77. % subplot(313); imagesc(t,f,(mask.*(X1-X2))'); axis xy; colorbar
  78. subplot(313); imagesc(t,f,mask'); axis xy; colorbar
  79. xlabel('f')
  80. ylabel('Significance');
  81. end;
  82. end
  83. Xdiff=X1-X2;