annotate nonExposed/utils/powspec.m @ 51:ebf92ed7d680 tip master

Added -fd (--full-duration) argument.
author Emmanouil Theofanis Chourdakis <e.t.chourdakis@qmul.ac.uk>
date Sun, 30 Sep 2018 13:21:49 +0100
parents b1901e8d8f5f
children
rev   line source
mathieu@14 1 function [y,e] = powspec(x, sr, wintime, steptime, dither)
mathieu@14 2 %[y,e] = powspec(x, sr, wintime, steptime, sumlin, dither)
mathieu@14 3 %
mathieu@14 4 % compute the powerspectrum and frame energy of the input signal.
mathieu@14 5 % basically outputs a power spectrogram
mathieu@14 6 %
mathieu@14 7 % each column represents a power spectrum for a given frame
mathieu@14 8 % each row represents a frequency
mathieu@14 9 %
mathieu@14 10 % default values:
mathieu@14 11 % sr = 8000Hz
mathieu@14 12 % wintime = 25ms (200 samps)
mathieu@14 13 % steptime = 10ms (80 samps)
mathieu@14 14 % which means use 256 point fft
mathieu@14 15 % hamming window
mathieu@14 16 %
mathieu@14 17 % $Header: /Users/dpwe/matlab/rastamat/RCS/powspec.m,v 1.3 2012/09/03 14:02:01 dpwe Exp dpwe $
mathieu@14 18
mathieu@14 19 % for sr = 8000
mathieu@14 20 %NFFT = 256;
mathieu@14 21 %NOVERLAP = 120;
mathieu@14 22 %SAMPRATE = 8000;
mathieu@14 23 %WINDOW = hamming(200);
mathieu@14 24
mathieu@14 25 if nargin < 2
mathieu@14 26 sr = 8000;
mathieu@14 27 end
mathieu@14 28 if nargin < 3
mathieu@14 29 wintime = 0.025;
mathieu@14 30 end
mathieu@14 31 if nargin < 4
mathieu@14 32 steptime = 0.010;
mathieu@14 33 end
mathieu@14 34 if nargin < 5
mathieu@14 35 dither = 1;
mathieu@14 36 end
mathieu@14 37
mathieu@14 38 winpts = round(wintime*sr);
mathieu@14 39 steppts = round(steptime*sr);
mathieu@14 40
mathieu@14 41 NFFT = 2^(ceil(log(winpts)/log(2)));
mathieu@14 42 %WINDOW = hamming(winpts);
mathieu@14 43 %WINDOW = [0,hanning(winpts)'];
mathieu@14 44 WINDOW = [hanning(winpts)'];
mathieu@14 45 % hanning gives much less noisy sidelobes
mathieu@14 46 NOVERLAP = winpts - steppts;
mathieu@14 47 SAMPRATE = sr;
mathieu@14 48
mathieu@14 49 % Values coming out of rasta treat samples as integers,
mathieu@14 50 % not range -1..1, hence scale up here to match (approx)
mathieu@14 51 y = abs(specgram(x*32768,NFFT,SAMPRATE,WINDOW,NOVERLAP)).^2;
mathieu@14 52
mathieu@14 53 % imagine we had random dither that had a variance of 1 sample
mathieu@14 54 % step and a white spectrum. That's like (in expectation, anyway)
mathieu@14 55 % adding a constant value to every bin (to avoid digital zero)
mathieu@14 56 if (dither)
mathieu@14 57 y = y + winpts;
mathieu@14 58 end
mathieu@14 59 % ignoring the hamming window, total power would be = #pts
mathieu@14 60 % I think this doesn't quite make sense, but it's what rasta/powspec.c does
mathieu@14 61
mathieu@14 62 % that's all she wrote
mathieu@14 63
mathieu@14 64 % 2012-09-03 Calculate log energy - after windowing, by parseval
mathieu@14 65 e = log(sum(y));