plot_matrix.m 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. function plot_matrix(X,t,f,plt,Xerr)
  2. % Function to plot a time-frequency matrix X. Time and frequency axes are in t and f.
  3. % If error bars are specified in Xerr,
  4. % it also plots them. Xerr contains upper and lower confidence intervals
  5. % on X.
  6. % Usage: plot_matrix(X,t,f,plt,Xerr)
  7. % Inputs:
  8. % X: input vector as a function of time and frequency (t x f)
  9. % t: t axis grid for plot. Default [1:size(X,1)]
  10. % f: f axis grid for plot. Default. [1:size(X,2)]
  11. % plt: 'l' for log, 'n' for no log.
  12. % Xerr: lower and upper confidence intervals for X1: lower/upper x t x f.
  13. if nargin < 1; error('Need data'); end;
  14. [NT,NF]=size(X);
  15. if nargin < 2;
  16. t=1:NT;
  17. end;
  18. if nargin < 3;
  19. f=1:NF;
  20. end;
  21. if length(f)~=NF || length(t)~=NT; error('axes grid and data have incompatible lengths'); end;
  22. if nargin < 4 || isempty(plt);
  23. plt='l';
  24. end;
  25. if strcmp(plt,'l');
  26. X=10*log10(X);
  27. if nargin ==5; Xerr=10*log10(Xerr); end;
  28. end;
  29. if nargin < 5;
  30. imagesc(t,f,X');axis xy; colorbar; title('Spectrogram');
  31. else
  32. subplot(311); imagesc(t,f,squeeze(Xerr(1,:,:))'); axis xy; colorbar; title('Lower confidence');
  33. subplot(312); imagesc(t,f,X'); title('X');axis xy; colorbar;
  34. subplot(313); imagesc(t,f,squeeze(Xerr(2,:,:))'); axis xy; colorbar; title('Upper confidence');
  35. end;
  36. xlabel('t');ylabel('f');