diff dsp/magspec.m @ 32:c3b0cd708782

Imported core dsp tools.
author samer
date Sun, 20 Jan 2013 13:48:47 +0000
parents
children
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/dsp/magspec.m	Sun Jan 20 13:48:47 2013 +0000
@@ -0,0 +1,17 @@
+function S=magspec(X,N)
+% magspec - get magnitude spectra of columns of x (v. 2)
+%
+% magspec :: [[N,L]] -> [[M,L]] :- M=dftbins(N).
+%
+% Version 2 corrects error in V. 1 - the wrong bands were being
+% doubled up in the power reckoning. This version now guarantees
+% that sum(magspec(x).^2) = sum(x.^2).
+
+if nargin<2, N=size(X,1); end
+
+bins=1+floor(N/2);
+Y=fft(X,N);
+S=abs(Y(1:bins,:))*sqrt(2/N); % sqrt of double of total power per band
+singles=1:ceil(N/2):bins;
+S(singles,:)=S(singles,:)/sqrt(2); % undo double counting of singletons
+