Home > ACA-Code > FeatureSpectralPitchChroma.m

FeatureSpectralPitchChroma

PURPOSE ^

computes the pitch chroma from the magnitude spectrum

SYNOPSIS ^

function [vpc] = FeatureSpectralPitchChroma(X, f_s)

DESCRIPTION ^

computes the pitch chroma from the magnitude spectrum
> called by ::ComputeFeature
>
> @param X: spectrogram (dimension FFTLength X Observations)
> @param f_s: sample rate of audio data
>
> @retval vpc pitch chroma
 ======================================================================

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SUBFUNCTIONS ^

SOURCE CODE ^

0001 %computes the pitch chroma from the magnitude spectrum
0002 %> called by ::ComputeFeature
0003 %>
0004 %> @param X: spectrogram (dimension FFTLength X Observations)
0005 %> @param f_s: sample rate of audio data
0006 %>
0007 %> @retval vpc pitch chroma
0008 % ======================================================================
0009 function [vpc] = FeatureSpectralPitchChroma(X, f_s)
0010 
0011     % allocate memory
0012     vpc = zeros(12, size(X, 2));
0013 
0014     % generate filter matrix
0015     H = GeneratePcFilters_I(size(X, 1), f_s);
0016  
0017     % compute pitch chroma
0018     vpc = H * X.^2;
0019     
0020     % norm pitch chroma to a sum of 1
0021     vpc = vpc ./ repmat(sum(vpc, 1), 12, 1);
0022        
0023     % avoid NaN for silence frames
0024     vpc (:,sum(X, 1) == 0) = 0;
0025 end
0026 
0027 %> generate the semi-tone filters (simple averaging)
0028 function [H] = GeneratePcFilters_I (iSpecLength, f_s)
0029 
0030     % initialization at C4
0031     f_mid = 261.63;
0032     iNumOctaves = 4;
0033     
0034     % sanity check
0035     while (f_mid*2^iNumOctaves > f_s/2 )
0036         iNumOctaves = iNumOctaves - 1;
0037     end
0038     
0039     H = zeros (12, iSpecLength);
0040     
0041     for i = 1:12
0042         % semitone boundaries in Hz
0043         afBounds  = [2^(-1/24) 2^(1/24)] * f_mid * 2 * (iSpecLength-1) / f_s;
0044         for j = 1:iNumOctaves
0045            iBounds =    [ceil(2^(j-1)*afBounds(1)) ...
0046                         floor(2^(j-1)*afBounds(2))]+1;
0047            H(i, iBounds(1):iBounds(2)) = 1 / (iBounds(2)+1-iBounds(1));
0048         end
0049         
0050         % increment to next semi-tone
0051         f_mid = f_mid * 2^(1/12);
0052     end   
0053 end

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