Home > ACA-Code > ComputeFeature.m

ComputeFeature

PURPOSE ^

computes a feature from the audio data

SYNOPSIS ^

function [v, t] = ComputeFeature (cFeatureName, x, f_s, afWindow, iBlockLength, iHopLength)

DESCRIPTION ^

computes a feature from the audio data
>
> supported features are:
>  'SpectralCentroid',
>  'SpectralCrestFactor',
>  'SpectralDecrease',
>  'SpectralFlatness',
>  'SpectralFlux',
>  'SpectralKurtosis',
>  'SpectralMfccs',
>  'SpectralPitchChroma',
>  'SpectralRolloff',
>  'SpectralSkewness',
>  'SpectralSlope',
>  'SpectralSpread',
>  'SpectralTonalPowerRatio',
>  'TimeAcfCoeff',
>  'TimeMaxAcf',
>  'TimePeakEnvelope',
>  'TimePredictivityRatio',
>  'TimeRms',
>  'TimeStd',
>  'TimeZeroCrossingRate',
>
> @param cFeatureName: feature to compute, e.g. 'SpectralSkewness'
> @param x: time domain sample data (dimension samples x channels)
> @param f_s: sample rate of audio data
> @param afWindow: FFT window of length iBlockLength (default: hann), can be [] empty
> @param iBlockLength: internal block length (default: 4096 samples)
> @param iHopLength: internal hop length (default: 2048 samples)
>
> @retval v feature value
> @retval t time stamp for the feature value
 ======================================================================

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SUBFUNCTIONS ^

SOURCE CODE ^

0001 %computes a feature from the audio data
0002 %>
0003 %> supported features are:
0004 %>  'SpectralCentroid',
0005 %>  'SpectralCrestFactor',
0006 %>  'SpectralDecrease',
0007 %>  'SpectralFlatness',
0008 %>  'SpectralFlux',
0009 %>  'SpectralKurtosis',
0010 %>  'SpectralMfccs',
0011 %>  'SpectralPitchChroma',
0012 %>  'SpectralRolloff',
0013 %>  'SpectralSkewness',
0014 %>  'SpectralSlope',
0015 %>  'SpectralSpread',
0016 %>  'SpectralTonalPowerRatio',
0017 %>  'TimeAcfCoeff',
0018 %>  'TimeMaxAcf',
0019 %>  'TimePeakEnvelope',
0020 %>  'TimePredictivityRatio',
0021 %>  'TimeRms',
0022 %>  'TimeStd',
0023 %>  'TimeZeroCrossingRate',
0024 %>
0025 %> @param cFeatureName: feature to compute, e.g. 'SpectralSkewness'
0026 %> @param x: time domain sample data (dimension samples x channels)
0027 %> @param f_s: sample rate of audio data
0028 %> @param afWindow: FFT window of length iBlockLength (default: hann), can be [] empty
0029 %> @param iBlockLength: internal block length (default: 4096 samples)
0030 %> @param iHopLength: internal hop length (default: 2048 samples)
0031 %>
0032 %> @retval v feature value
0033 %> @retval t time stamp for the feature value
0034 % ======================================================================
0035 function [v, t] = ComputeFeature (cFeatureName, x, f_s, afWindow, iBlockLength, iHopLength)
0036 
0037     % set feature function handle
0038     hFeatureFunc = str2func (['Feature' cFeatureName]);
0039 
0040     % set default parameters if necessary
0041     if (nargin < 6)
0042         iHopLength = 2048;
0043     end
0044     if (nargin < 5)
0045         iBlockLength = 4096;
0046     end
0047   
0048     % pre-processing: down-mixing
0049     x = ToolDownmix(x);
0050     
0051     % pre-processing: normalization (not necessary for many features)
0052     x = ToolNormalizeAudio(x);
0053  
0054     if (IsSpectral_I(cFeatureName))
0055         if (nargin < 4 || isempty(afWindow))
0056             afWindow = hann(iBlockLength, 'periodic');
0057         end
0058         
0059         % compute FFT window function
0060         if (length(afWindow) ~= iBlockLength)
0061             error('window length mismatch');
0062         end                        
0063 
0064         % in the real world, we would do this block by block...
0065         [X, f, t] = ComputeSpectrogram(x, ...
0066                                     f_s, ...
0067                                     afWindow, ...
0068                                     iBlockLength, ...
0069                                     iHopLength);
0070         
0071         % compute feature
0072         v = hFeatureFunc(X, f_s);
0073     end %if (IsSpectral_I(cFeatureName))
0074     
0075     if (IsTemporal_I(cFeatureName))
0076         % compute feature
0077         [v,t] = hFeatureFunc(   x, ...
0078                                 iBlockLength, ...
0079                                 iHopLength, ...
0080                                 f_s);
0081     end %if (IsTemporal_I(cFeatureName))
0082 end
0083 
0084 function [bResult] = IsSpectral_I(cName)
0085     bResult = false;
0086     iIdx = strfind(cName, 'Spectral');
0087     if (~isempty(iIdx))
0088         if (iIdx(1) == 1)
0089             bResult = true;
0090         end
0091     end
0092 end
0093 
0094 function [bResult] = IsTemporal_I(cName)
0095     bResult = false;
0096     iIdx = strfind(cName, 'Time');
0097     if (~isempty(iIdx))
0098         if (iIdx(1) == 1)
0099             bResult = true;
0100         end
0101     end
0102 end

Generated on Fri 22-Apr-2022 20:59:51 by m2html © 2005