Home > ACA-Code > PitchTimeZeroCrossings.m

PitchTimeZeroCrossings

PURPOSE ^

computes f_0 through zero crossing distances

SYNOPSIS ^

function [f_0, t] = PitchTimeZeroCrossings(x, iBlockLength, iHopLength, f_s)

DESCRIPTION ^

computes f_0 through zero crossing distances
> called by ::ComputePitch
>
> @param x: audio signal
> @param iBlockLength: block length in samples
> @param iHopLength: hop length in samples
> @param f_s: sample rate of audio data 
>
> @retval f_0 double zero crossing distance (in Hz)
> @retval t time stamp of f_0 estimate (in s)
 ======================================================================

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 %computes f_0 through zero crossing distances
0002 %> called by ::ComputePitch
0003 %>
0004 %> @param x: audio signal
0005 %> @param iBlockLength: block length in samples
0006 %> @param iHopLength: hop length in samples
0007 %> @param f_s: sample rate of audio data
0008 %>
0009 %> @retval f_0 double zero crossing distance (in Hz)
0010 %> @retval t time stamp of f_0 estimate (in s)
0011 % ======================================================================
0012 function [f_0, t] = PitchTimeZeroCrossings(x, iBlockLength, iHopLength, f_s)
0013 
0014     % blocking
0015     [x_b, t] = ToolBlockAudio(x, iBlockLength, iHopLength, f_s);
0016     iNumOfBlocks = size(x_b, 1);
0017     
0018     % allocate memory
0019     T_0 = zeros(1, iNumOfBlocks);
0020 
0021     for n = 1:iNumOfBlocks
0022         i_tmp = diff(find(x_b(n, 1:end-1) .* x_b(n, 2:end) < 0));
0023         %  average distance of zero crossings indicates half period
0024         T_0(n) = 2 * mean(i_tmp); % or histogram max, ...
0025     end
0026  
0027     % convert to Hz
0028     f_0 = f_s ./ T_0;
0029     
0030     % avoid NaN for silence frames
0031     f_0 (isnan(f_0)) = 0;
0032 end

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