view dsp/magspec.m @ 61:eff6bddf82e3 tip

Finally implemented perceptual brightness thing.
author samer
date Sun, 11 Oct 2015 10:20:42 +0100
parents c3b0cd708782
children
line wrap: on
line source
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