samer@32: function S=magspec(X,N) samer@32: % magspec - get magnitude spectra of columns of x (v. 2) samer@32: % samer@32: % magspec :: [[N,L]] -> [[M,L]] :- M=dftbins(N). samer@32: % samer@32: % Version 2 corrects error in V. 1 - the wrong bands were being samer@32: % doubled up in the power reckoning. This version now guarantees samer@32: % that sum(magspec(x).^2) = sum(x.^2). samer@32: samer@32: if nargin<2, N=size(X,1); end samer@32: samer@32: bins=1+floor(N/2); samer@32: Y=fft(X,N); samer@32: S=abs(Y(1:bins,:))*sqrt(2/N); % sqrt of double of total power per band samer@32: singles=1:ceil(N/2):bins; samer@32: S(singles,:)=S(singles,:)/sqrt(2); % undo double counting of singletons samer@32: