I want to use exponential moving average filter( 1st order IIR) for envelope detection, to apply gain for transient suppression in audio. My requirement is that say at input x(n-1)[ when it starts rising, at onset of transient], I compute Gain/suppression factor which is high enough to reduce x[n-1], but by the time i compute the gain, new input x(n) would have arrived due to filter delay, and i will be applying gain on this new sample, rather than old sample x(n-1). so, how can I look ahead ,so to say, that I compute gain/suppression in advance to be applied later when the actual input sample for which it is meant arrives? what would be data structure/buffering needed? Thanks sunny _____________________________ Posted through www.DSPRelated.com
envelope detection for audio transient suppression
Started by ●June 19, 2014
Reply by ●June 19, 20142014-06-19
On 6/19/14 1:39 PM, sed_y wrote:> I want to use exponential moving average filter( 1st order IIR) for > envelope detection, to apply gain for transient suppression in audio.do you mean "compression of audio"? or "attenuation"?> > My requirement is that say at input x[n-1] (when it starts rising, at onset > of transient), I compute Gain/suppression factor which is high enough to > reduce x[n-1], but by the time i compute the gain, new input x[n] would > have arrived due to filter delay, and i will be applying gain on this new > sample, rather than old sample x[n-1]. so, how can I look ahead ,so to say, > that I compute gain/suppression in advance to be applied later when the > actual input sample for which it is meant arrives? what would be data > structure/buffering needed? >"look-ahead" is done on an audio file (non-realtime) by simply looking ahead to samples ahead of the "present" sample. for real time, you have to accept a little bit of delay. a few samples of delay won't kill anyone. essentially in real time, the gain factors that you compute with samples all the way to the most recent sample (x[n]) gets applied to some part of the audio a little further back in time (like x[n-D] where D is the delay). -- r b-j rbj@audioimagination.com "Imagination is more important than knowledge."
Reply by ●June 19, 20142014-06-19
Hi Robert. thanks for reply. I mean "attenuation". I have to do it real-time on DSP board. in Matlab, i have something like: for j=1:N-1 % N is length of input % x is input audio, below does 1 pole exponential averaging as difference equation y_fst(j+1) = (alpha1 *x(j+1)) + ((1- alpha1)* y_fst(j)); _____________________________ Posted through www.DSPRelated.com
Reply by ●June 19, 20142014-06-19
Hi Robert.
thanks for reply. I mean "attenuation".
I have to do it real-time on DSP board.
in Matlab, i have something like:
for j=1:N-1 % N is length of input
% x is input audio, below does 1 pole exponential averaging as
difference equation
y_fst(j+1) = (alpha1 *x(j+1)) + ((1- alpha1)* y_fst(j));
% some more averaging and thresholding here
y(j+1)= x(j)*Gain_FIR_final; % old sample
end
So, if the above computation takes more time, than my next sample arrival,
I would use Gain_FIR_final on old sample, which should be ok?
sunny
_____________________________
Posted through www.DSPRelated.com
Reply by ●June 20, 20142014-06-20
On 6/19/14 3:38 PM, sed_y wrote:> Hi Robert. > > thanks for reply. I mean "attenuation". > I have to do it real-time on DSP board. > > in Matlab, i have something like: > > for j=1:N-1 % N is length of input > > % x is input audio, below does 1 pole exponential averaging as > difference equation > y_fst(j+1) = (alpha1 * x(j+1)) + ((1- alpha1)* y_fst(j));what's the x(j+1) for? are you intending to skip x(1)? are you sure you don't want |x(j)| or |x(j)|^2 going into the weighted moving average?> > % some more averaging and thresholding here >how 'bout Gain_FIR_final = somefunction(y_fst(j-D)); (for the case where j-D>0) ? and where D = something like 4 or 5 time-constants (i think it's 1/alpha1 in sample units).> y(j+1)= x(j)*Gain_FIR_final; % old sample >and y(j) = x(j-D)*Gain_FIR_final> > end > > So, if the above computation takes more time, than my next sample arrival, > I would use Gain_FIR_final on old sample, which should be ok? > > sunny > > _____________________________ > Posted through www.DSPRelated.com-- r b-j rbj@audioimagination.com "Imagination is more important than knowledge."
Reply by ●June 20, 20142014-06-20
>On 6/19/14 3:38 PM, sed_y wrote:>what's the x(j+1) for? are you intending to skip x(1)? > >are you sure you don't want |x(j)| or |x(j)|^2 going into the weighted >moving average?Hi Robert, No I am not intending to skip x(1)[ I was evaluating it outside the loop but did not put it there ]. I am actually sending in abs(x) as the input.>> % some more averaging and thresholding here >> > >how 'bout > > Gain_FIR_final = somefunction(y_fst(j-D)); > >(for the case where j-D>0) ? > >and where D = something like 4 or 5 time-constants (i think it's >1/alpha1 in sample units). > >> y(j+1)= x(j)*Gain_FIR_final; % old sample >> > >and > y(j) = x(j-D)*Gain_FIR_final > >> >> endsuppose j=30 with time constant of 6 samples, 4 time constants =24 =D so, within loop at time j=30 sample i will have Gain_FIR_final = somefunction(y_fst(6)); y(30) = x(6)*Gain_FIR_final if the transient starting appearing at j=10, I would be applying attenuation computed at the high input sample at j=30, to the sample at j=6, which was not a transient and so, should not be applied this high attenuation.? sedy _____________________________ Posted through www.DSPRelated.com
Reply by ●June 20, 20142014-06-20
please read j as 30 in the previous post. pleas read D as 24 in the previous post. _____________________________ Posted through www.DSPRelated.com
Reply by ●June 20, 20142014-06-20
On 6/20/14 12:24 PM, sed_y wrote:>> On 6/19/14 3:38 PM, sed_y wrote: > >> what's the x(j+1) for? are you intending to skip x(1)? >> >> are you sure you don't want |x(j)| or |x(j)|^2 going into the weighted >> moving average? > > Hi Robert, > No I am not intending to skip x(1)[ I was evaluating it outside the loop > but did not put it there ]. > > I am actually sending in abs(x) as the input. >okay, you have mean abs, rather than just mean. that's okay. dunno which is better. sometimes you want *peak* abs value (over a finite period behind the "current" sample. okay, i'm not gonna write code for you (except maybe a line here or there) and i am not gonna write code to test in MATLAB (or Octave). the issue you're having is that of "edge conditions" (which i would not conflate with "boundary conditions" involving differential equations or difference equations - essentially that of setting up the states to initial conditions before you start processing samples). my recommendation for dealing with these edge effects is to zero-pad your data on both sides. and then start with sample #1 (or sample #0, if you were doing this in a language that can have 0 origin) of the original data, which would be sample N+1 if you pad with N zeros before the first sample. so you know how to concatenate arrays in MATLAB, so then concatenate N zeros before your 1st sample (which makes it the (N+1)th sample in the new concatenated array). then start processing from that sample, in computing your mean abs. but apply the results of that to the sample D samples preceding (and D better not exceed N). this is how you would implement this in C or assembly or some non-MATLAB setting. -- r b-j rbj@audioimagination.com "Imagination is more important than knowledge."
Reply by ●June 20, 20142014-06-20
Reply by ●June 27, 20142014-06-27
On Thursday, June 19, 2014 1:39:49 PM UTC-4, sed_y wrote:> I want to use exponential moving average filter( 1st order IIR) for > > envelope detection, to apply gain for transient suppression in audio. > > > > My requirement is that say at input x(n-1)[ when it starts rising, at onset > > of transient], I compute Gain/suppression factor which is high enough to > > reduce x[n-1], but by the time i compute the gain, new input x(n) would > > have arrived due to filter delay, and i will be applying gain on this new > > sample, rather than old sample x(n-1). so, how can I look ahead ,so to say, > > that I compute gain/suppression in advance to be applied later when the > > actual input sample for which it is meant arrives? what would be data > > structure/buffering needed? > > > > Thanks sunny > > > > _____________________________ > > Posted through www.DSPRelated.comThe way to predict without introducing lag is to use derivatives to project forward in time. Look at alpha/beta filters for some low complexity ideas.






