Home > ACA-Code > FeatureTimeRms.m

FeatureTimeRms

PURPOSE ^

computes the RMS of a time domain signal

SYNOPSIS ^

function [vrms, t] = FeatureTimeRms(x, iBlockLength, iHopLength, f_s)

DESCRIPTION ^

computes the RMS of 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 vrms root mean square (row 1: block-based rms, row 2: single pole approx)
> @retval t time stamp
 ======================================================================

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 %computes the RMS of 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 vrms root mean square (row 1: block-based rms, row 2: single pole approx)
0010 %> @retval t time stamp
0011 % ======================================================================
0012 function [vrms, t] = FeatureTimeRms(x, iBlockLength, iHopLength, f_s)
0013 
0014     T_i = .3; 
0015     alpha = 1 - exp(-2.2/f_s/T_i);
0016 
0017     % blocking
0018     [x_b, t] = ToolBlockAudio(x, iBlockLength, iHopLength, f_s);
0019     
0020     % allocate memory
0021     vrms = zeros(2, length(t));
0022 
0023     % single pole implementation
0024     v_sp = filter(alpha, [1 -(1-alpha)], x.^2);
0025 
0026     % per block standard implementation
0027     for n = 1:size(x_b, 1)
0028         i_start = (n-1) * iHopLength + 1;
0029         i_stop = min(length(x), i_start + iBlockLength - 1);
0030         
0031         % calculate the rms
0032         vrms(1, n) = sqrt(mean(x_b(n, :).^2));
0033         vrms(2, n) = max(sqrt(v_sp(i_start:i_stop)));
0034     end
0035 
0036     % convert to dB
0037     epsilon = 1e-5; %-100dB
0038     vrms(vrms < epsilon) = epsilon;
0039     vrms = 20*log10(vrms);
0040 end

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