Dawn@4: function [ASBP] = AudioSpectralBandPower(raw, fs, noOfFrames, frameLength) Dawn@4: % this file normalises the frequency spectrum and calculates the spectral Dawn@4: % power in frequency band 100 - 1000 Hz and in the top Dawn@4: x = buffer( raw, frameLength ); Dawn@4: myColor = 'rx'; Dawn@4: Dawn@4: hiEdgeSamples = getMaxFreq; % the highest fundamental Dawn@4: loEdgeSamples = getMinFreq; % the lowest fundamental Dawn@4: Dawn@4: hiFreqBin = ceil(((frameLength/2)/(fs/2))*hiEdgeSamples); Dawn@4: loFreqBin = floor(((frameLength/2)/(fs/2))*loEdgeSamples); Dawn@4: Dawn@4: bandWidth = hiFreqBin - loFreqBin; Dawn@4: Dawn@4: for n = 1:noOfFrames Dawn@4: spectrum = abs( fft( x(:,n) )); Dawn@4: spectrum = spectrum( 1 : frameLength/2 ); Dawn@4: % normalise Dawn@4: % spectrum = spectrum/max(spectrum); Dawn@4: % fundamental frequency band Dawn@4: lBand = ( loFreqBin : hiFreqBin ); Dawn@4: hBand = ( frameLength/2 - ( bandWidth ) : frameLength/2 ); Dawn@4: lBandPower = sum( spectrum( lBand )); Dawn@4: hBandPower = sum( spectrum( hBand )); Dawn@4: % gm(n) = nthroot( prod( spectrum ), frameLength ); Dawn@4: % am(n) = sum( spectrum )/frameLength; Dawn@4: ASBP(n) = lBandPower/hBandPower; Dawn@4: % subplot(421); plot( x(:,n) ); Dawn@4: % subplot(422); plot( spectrum ); hold on; Dawn@4: % plot( loFreqBin : hiFreqBin, spectrum( lBand ), 'r' ); Dawn@4: % plot( hBand, spectrum( hBand ), 'r' ); hold off Dawn@4: % Dawn@4: % % look at the frame with reference to the surrounding 10 frames Dawn@4: % if( n>5 ) Dawn@4: % startPlot = (n-5)*frameLength+1; Dawn@4: % endPlot = (n+5)*frameLength; Dawn@4: % else Dawn@4: % startPlot = 1; Dawn@4: % endPlot = 10*frameLength; Dawn@4: % end Dawn@4: % subplot(412); plot( raw( startPlot : endPlot ) ); hold on; Dawn@4: % plot( ((n-1)*frameLength+1) - startPlot : (n*frameLength) - startPlot, x(:,n), 'r' ); hold off; Dawn@4: % Dawn@4: % subplot(425); plot( n, lBandPower, myColor ); hold on;%plot( n, gm(n), myColor ); hold on; Dawn@4: % subplot(426); plot( n, hBandPower, myColor ); hold on;%plot( n, am(n), myColor ); hold on; Dawn@4: % subplot(414); plot( n, lBandPower / hBandPower, myColor ); hold on;%plot( n, ASF(n), myColor ); hold on; Dawn@4: % end Dawn@4: end Dawn@4: Dawn@4: Dawn@4: Dawn@4: Dawn@4: