What does IIR and FIR filter are used for in embedded

this sounds similar to what we've done to detect speech given background noise.

while the signal may be filtered, somewhat different signal processing is used to measure the signal levels

the absolute amplitude (i.e. rectified) of the signal is needed. we used conditional leaky integration

if (seg > avg)
    avg += (sig - avg ) * kAttack;
else
    avg += (sig - avg ) * kDecay;

in general, think of k = 1/N and that the avg will reach 95% of sig in 3N iterations (like an RC time constant)

to "measure" speech, the attack rate (kAttck) is > the decay rate. to measure noise, the decay rate is >> attack rate so that it quickly reacts to a drop in noise level

finally, speech is detected when the measured speech level exceeds the measured noise level by some amount (we used 6dB)