diff dsp/specgrm.m @ 32:c3b0cd708782

Imported core dsp tools.
author samer
date Sun, 20 Jan 2013 13:48:47 +0000
parents
children beb8a3f4a345
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/dsp/specgrm.m	Sun Jan 20 13:48:47 2013 +0000
@@ -0,0 +1,33 @@
+%  specgrm - Time-Varying Spectrum
+% 
+%  specgrm ::
+%     X:[[T]]   ~'signal of length T',
+%     N:natural | H:[[N]] ~'window length or window', 
+%     M:natural ~'hop size',
+%     options {
+%		   fs :: nonneg/1	~'sampling rate'
+%     }
+%  -> [[1+N/2,floor(T/M)]] ~'sequence of short term spectra'.  
+%
+%  Examples:
+%     Y1=specgram(x,hanning(256),128,'fs',44100)
+%
+%  Side Effects
+%    Image Plot of the spectrogram if no output
+
+function y=specgrm(x,w,m,varargin)
+	if length(w)==1,	H=ones(w,1); 
+	else H=w; end
+	if nargin<3 m=[]; end
+	
+	n = length(H); if isempty(m), m=n/2; end
+	if n>m, bufargs={'nodelay'}; else bufargs={}; end
+	y = powspec(diag(sparse(H))*buffer(zeropad(n-m,x),n,n-m,bufargs{:}));
+
+	% Make Spectrogram Display if no arg out
+	if nargout==0
+		tfdimage(y,n,m,getparam(prefs(varargin{:}),'fs',1));
+		clear y;
+	end
+
+