Home > ACA-Code > FeatureTimePeakEnvelope.m

FeatureTimePeakEnvelope

PURPOSE ^

computes two peak envelope measures for a time domain signal

SYNOPSIS ^

function [vppm, t] = FeatureTimePeakEnvelope(x, iBlockLength, iHopLength, f_s)

DESCRIPTION ^

computes two peak envelope measures for a time domain signal
> called by ::ComputeFeature
>
> @param x: audio signal
> @param iBlockLength: block length in samples
> @param iHopLength: hop length in samples
> @param f_s: sample rate of audio data (unused)
>
> @retval vppm peak envelope (1,:: max, 2,:: PPM)
> @retval t time stamp
 ======================================================================

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SUBFUNCTIONS ^

SOURCE CODE ^

0001 %computes two peak envelope measures for a time domain signal
0002 %> called by ::ComputeFeature
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 (unused)
0008 %>
0009 %> @retval vppm peak envelope (1,:: max, 2,:: PPM)
0010 %> @retval t time stamp
0011 % ======================================================================
0012 function [vppm, t] = FeatureTimePeakEnvelope(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     vppm = zeros(2, iNumOfBlocks);
0020     v_tmp = zeros(1, iBlockLength);
0021 
0022     %initialization
0023     alpha = 1 - [exp(-2.2 / (f_s * 0.01)), exp(-2.2 / (f_s * 1.5))];
0024 
0025     for n = 1:iNumOfBlocks
0026         % calculate the maximum
0027         vppm(1, n) = max(abs(x_b(n, :)));
0028         
0029         % calculate the PPM value
0030         v_tmp = ppm_I(x_b(n, :), v_tmp(iHopLength), alpha);
0031         vppm(2, n) = max(v_tmp);
0032     end
0033  
0034     % convert to dB avoiding log(0)
0035     epsilon = 1e-5; %-100dB
0036     vppm(vppm < epsilon) = epsilon;
0037     vppm = 20*log10(vppm);
0038 end
0039 
0040 function [ppmout] = ppm_I(x, filterbuf, alpha)
0041 
0042     %initialization
0043     ppmout = zeros(size(x));
0044     alpha_AT = alpha(1);
0045     alpha_RT = alpha(2);
0046  
0047     x = abs(x);
0048     for i = 1: length(x)
0049         if (filterbuf > x(i))
0050             % release state
0051             ppmout(i) = (1-alpha_RT) * filterbuf;
0052         else
0053             % attack state
0054             ppmout(i) = alpha_AT * x(i) + (1-alpha_AT) * filterbuf;
0055         end
0056         filterbuf = ppmout(i);
0057     end
0058 end

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