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@42
|
8 % fs :: nonneg/1 ~'sampling rate';
|
samer@42
|
9 % range:: [[2]] ~'range for tfdimage'
|
samer@32
|
10 % }
|
samer@32
|
11 % -> [[1+N/2,floor(T/M)]] ~'sequence of short term spectra'.
|
samer@32
|
12 %
|
samer@32
|
13 % Examples:
|
samer@32
|
14 % Y1=specgram(x,hanning(256),128,'fs',44100)
|
samer@32
|
15 %
|
samer@32
|
16 % Side Effects
|
samer@32
|
17 % Image Plot of the spectrogram if no output
|
samer@32
|
18
|
samer@32
|
19 function y=specgrm(x,w,m,varargin)
|
samer@32
|
20 if length(w)==1, H=ones(w,1);
|
samer@32
|
21 else H=w; end
|
samer@32
|
22 if nargin<3 m=[]; end
|
samer@32
|
23
|
samer@32
|
24 n = length(H); if isempty(m), m=n/2; end
|
samer@32
|
25 if n>m, bufargs={'nodelay'}; else bufargs={}; end
|
samer@32
|
26 y = powspec(diag(sparse(H))*buffer(zeropad(n-m,x),n,n-m,bufargs{:}));
|
samer@32
|
27
|
samer@32
|
28 % Make Spectrogram Display if no arg out
|
samer@32
|
29 if nargout==0
|
samer@42
|
30 opts=options('fs',1,'range',13.5,varargin{:});
|
samer@42
|
31
|
samer@43
|
32 tfdimage(y,n,m,opts.fs,opts.range,opts);
|
samer@32
|
33 clear y;
|
samer@32
|
34 end
|
samer@32
|
35
|
samer@32
|
36
|