Mercurial > hg > ishara
annotate dsp/specgrm.m @ 32:c3b0cd708782
Imported core dsp tools.
author | samer |
---|---|
date | Sun, 20 Jan 2013 13:48:47 +0000 |
parents | |
children | beb8a3f4a345 |
rev | line source |
---|---|
samer@32 | 1 % specgrm - Time-Varying Spectrum |
samer@32 | 2 % |
samer@32 | 3 % specgrm :: |
samer@32 | 4 % X:[[T]] ~'signal of length T', |
samer@32 | 5 % N:natural | H:[[N]] ~'window length or window', |
samer@32 | 6 % M:natural ~'hop size', |
samer@32 | 7 % options { |
samer@32 | 8 % fs :: nonneg/1 ~'sampling rate' |
samer@32 | 9 % } |
samer@32 | 10 % -> [[1+N/2,floor(T/M)]] ~'sequence of short term spectra'. |
samer@32 | 11 % |
samer@32 | 12 % Examples: |
samer@32 | 13 % Y1=specgram(x,hanning(256),128,'fs',44100) |
samer@32 | 14 % |
samer@32 | 15 % Side Effects |
samer@32 | 16 % Image Plot of the spectrogram if no output |
samer@32 | 17 |
samer@32 | 18 function y=specgrm(x,w,m,varargin) |
samer@32 | 19 if length(w)==1, H=ones(w,1); |
samer@32 | 20 else H=w; end |
samer@32 | 21 if nargin<3 m=[]; end |
samer@32 | 22 |
samer@32 | 23 n = length(H); if isempty(m), m=n/2; end |
samer@32 | 24 if n>m, bufargs={'nodelay'}; else bufargs={}; end |
samer@32 | 25 y = powspec(diag(sparse(H))*buffer(zeropad(n-m,x),n,n-m,bufargs{:})); |
samer@32 | 26 |
samer@32 | 27 % Make Spectrogram Display if no arg out |
samer@32 | 28 if nargout==0 |
samer@32 | 29 tfdimage(y,n,m,getparam(prefs(varargin{:}),'fs',1)); |
samer@32 | 30 clear y; |
samer@32 | 31 end |
samer@32 | 32 |
samer@32 | 33 |