annotate toolboxes/bioakustik_tools/visualisation/dataspecgram.m @ 0:e9a9cd732c1e tip

first hg version after svn
author wolffd
date Tue, 10 Feb 2015 15:05:51 +0000
parents
children
rev   line source
wolffd@0 1 function [h,out] = dataspecgram(wavin, varargin)
wolffd@0 2 %[h,spec] = dataspecgram(data,'sr',fs,'fftlen',2048,'stepw',1024,'winsize',2048,'min_fkhz',0.5,'max_fkhz',15,'nolog',0,'clip',0,'logadd',0);
wolffd@0 3
wolffd@0 4
wolffd@0 5 [sr,fftlen, stepw,winsize,min_fkhz,max_fkhz,nolog,clip,logadd,fontsize,cutoff,colormode,unused]=process_options(varargin,...
wolffd@0 6 'sr',44800,'fftlen',2048,'stepw',1024,'winsize',2048,'min_fkhz',0.5,'max_fkhz',15,...
wolffd@0 7 'nolog',0,'clip',0,'logadd',0,'fontsize',8,'cutoff',0,'colormode','jet');
wolffd@0 8 out= specgram(wavin,fftlen,sr,winsize,winsize-stepw);
wolffd@0 9
wolffd@0 10 wavlens=round(length(wavin)/sr*100)/100;
wolffd@0 11
wolffd@0 12 firstindex= max(round(fftlen/(sr)*min_fkhz*1000),1);
wolffd@0 13 lastindex= min(round(fftlen/(sr)*max_fkhz*1000),fftlen/2);
wolffd@0 14
wolffd@0 15 out=out(firstindex:lastindex,:);
wolffd@0 16 if nolog
wolffd@0 17 out=abs(out);
wolffd@0 18 out=sqrt(abs(out));
wolffd@0 19 out=out./max(max(out));
wolffd@0 20 else
wolffd@0 21 out=log(0.000000001+logadd+abs(out));
wolffd@0 22 out=out./max(max(abs(out)));
wolffd@0 23 out=out+1;
wolffd@0 24 end
wolffd@0 25
wolffd@0 26 %cut off small values
wolffd@0 27 if cutoff
wolffd@0 28 for i=1:size(out,2)
wolffd@0 29 out((out(:,i)<cutoff),i)=0;
wolffd@0 30 end
wolffd@0 31 end
wolffd@0 32
wolffd@0 33
wolffd@0 34
wolffd@0 35 if clip > 0
wolffd@0 36 h=image([0 wavlens],[min_fkhz max_fkhz],out*100*clip);
wolffd@0 37 else
wolffd@0 38 h=imagesc([0 wavlens],[min_fkhz max_fkhz],out);
wolffd@0 39 end
wolffd@0 40
wolffd@0 41 switch colormode
wolffd@0 42 case 'inv'
wolffd@0 43 color= 'w';
wolffd@0 44 bgcolor= 'k';
wolffd@0 45 colormap(hot);
wolffd@0 46 case 'bw'
wolffd@0 47 color= 'black';
wolffd@0 48 colormap(1-grey);
wolffd@0 49 bgcolor= 'w';
wolffd@0 50 case 'jet'
wolffd@0 51 color= 'black';
wolffd@0 52 colormap(jet);
wolffd@0 53 bgcolor= 'w';
wolffd@0 54 end
wolffd@0 55
wolffd@0 56 set(gca,'FontSize',fontsize,'xcolor',color);
wolffd@0 57 set(gca,'FontSize',fontsize,'ycolor',color);
wolffd@0 58
wolffd@0 59 h=get(0,'CurrentFigure');
wolffd@0 60 axis xy;
wolffd@0 61 set(gcf, 'color', bgcolor);
wolffd@0 62 set(gcf, 'InvertHardCopy', 'off');
wolffd@0 63
wolffd@0 64 xlabel('Time[s]','FontSize',fontsize,'Color',color)
wolffd@0 65 ylabel('Frequency[kHz]','FontSize',fontsize,'Color',color)