On 9/27/05, Harold Hallikainen wrote: > OK... Here's another question... I've got an application where we need to > update a VU audio level indication maybe 10 times a second. One way to do > this is in hardware do rectification (ideal diode) and filtering to give > the appropriate ballistics (attack and release time). This'd then go into > an analog input on the PIC. > > However, since the ideal design has zero parts, I'm wondering about > another approach. How about if the incoming audio goes through a current > limit resistor to the PIC analog input. Add a clamp diode so the PIC input > is not driven negative much. This would result in half wave rectification > of the audio, since the PIC A/D would read zero for negative inputs and > read a positive number for positive inputs. > > The next trick is, since we're only updating the display 10 times a second > or so, how about sampling the audio with the PIC A/D 100 times a second or > so, then averaging those samples. I'd probably average a number of samples > that is a power of two so the division by the number of samples is just > throwing away a few least significant bits. > > The question is... would the result of this average be similar to the > hardware approach? Sometimes the instantaneous voltage sample would land > on zero, other times it would land on the peak of the incoming audio. Most > of the time it would land somewhere in between. Since the sampling is not > synchronized with the audio in any way, would we get an average similar to > the hardware approach described earlier? > Nyquist says, you need to filter at less than half the sample frequency before you sample the signal. Consider this case: The audio signal is a pure 100Hz sinewave of amplitude 1. You are sampling it at 100Hz. Without filtering, if the phase between the sine wave and the sampler is 0, you will sample the wave when it is zero. If the phase difference is pi/2, you will sample the wave when it is 1. Or consider a 99 or 101 Hz sinewave. The wave is of constant amplitude, but the VU meter would swing from 0 to full scale once per second. So include filtering after the diode, before the A/D input. I'd start with an RC=4/fs. You will run into the problem again when you subsample the 100 samples/sec to 10 updates/sec. Your plan of averaging will probably work OK: the averaging acts as a filter before decimation. A more carefully designed filter may be better (for certain values of "better"). Regards, Mark markrages@gmail -- You think that it is a secret, but it never has been one. - fortune cookie -- http://www.piclist.com PIC/SX FAQ & list archive View/change your membership options at http://mailman.mit.edu/mailman/listinfo/piclist