Mercurial > hg > ishara
annotate 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 |
rev | line source |
---|---|
samer@32 | 1 function S=magspec(X,N) |
samer@32 | 2 % magspec - get magnitude spectra of columns of x (v. 2) |
samer@32 | 3 % |
samer@32 | 4 % magspec :: [[N,L]] -> [[M,L]] :- M=dftbins(N). |
samer@32 | 5 % |
samer@32 | 6 % Version 2 corrects error in V. 1 - the wrong bands were being |
samer@32 | 7 % doubled up in the power reckoning. This version now guarantees |
samer@32 | 8 % that sum(magspec(x).^2) = sum(x.^2). |
samer@32 | 9 |
samer@32 | 10 if nargin<2, N=size(X,1); end |
samer@32 | 11 |
samer@32 | 12 bins=1+floor(N/2); |
samer@32 | 13 Y=fft(X,N); |
samer@32 | 14 S=abs(Y(1:bins,:))*sqrt(2/N); % sqrt of double of total power per band |
samer@32 | 15 singles=1:ceil(N/2):bins; |
samer@32 | 16 S(singles,:)=S(singles,:)/sqrt(2); % undo double counting of singletons |
samer@32 | 17 |