Searching \ for '[PIC] Undersampling Audio for level indication?' in subject line. ()
Make payments with PayPal - it's fast, free and secure! Help us get a faster server
FAQ page: www.piclist.com/techref/microchip/ios.htm?key=audio
Search entire site for: 'Undersampling Audio for level indication?'.

Exact match. Not showing close matches.
PICList Thread
'[PIC] Undersampling Audio for level indication?'
2005\09\27@162706 by Harold Hallikainen

face picon face
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?

Harold
(The ideal design has zero parts)


--
FCC Rules Updated Daily at http://www.hallikainen.com

2005\09\27@164426 by Maarten Hofman

face picon face
>
> 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.

Usually with a VU meter you would want the maximum, and not the average, so
I would recommend using the maximum of the sampled values. Also, I might be
wrong, but usually the PICmicro has diodes of its own, so you might be able
to get away with leaving out the diode. You're minimizing parts, after all.
Other than that, I don't see why it wouldn't work.

Greetings,
Maarten Hofman.

2005\09\27@171851 by Mark Rages

face picon face
On 9/27/05, Harold Hallikainen <spam_OUTharoldTakeThisOuTspamhallikainen.com> wrote:
{Quote hidden}

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

2005\09\27@174104 by Stef Mientki

flavicon
face

>Nyquist says, you need to filter at less than half the sample
>frequency before you sample the signal.
>  
>
Not exactly,
he said sample frequency should be at least half the bandwidth.
So e.g. if you know (apriori) that your frequency is between 1000 and
1100 Hz,
it's enough to sample with 200 Hz.

Stef

>  
>

2005\09\27@182913 by Mark Rages

face picon face
On 9/27/05, Stef Mientki <.....s.mientkiKILLspamspam@spam@mailbox.kun.nl> wrote:
>
> >Nyquist says, you need to filter at less than half the sample
> >frequency before you sample the signal.
> >
> >
> Not exactly,
> he said sample frequency should be at least half the bandwidth.
> So e.g. if you know (apriori) that your frequency is between 1000 and
> 1100 Hz,
> it's enough to sample with 200 Hz.
>
> Stef
>

That's correct. (if you meant to write "twice the bandwidth")

Regards,
Mark
markrages@gmail
--
You think that it is a secret, but it never has been one.
 - fortune cookie

2005\09\27@183733 by Jan-Erik Soderholm

face picon face
Twice the highest freq that you want to be able to
reproduce from the original signal. Bandwidth has nothing
to do with it, IMHO.

> So e.g. if you know (apriori) that your frequency is
> between 1000 and 1100 Hz, it's enough to sample with 200 Hz.

2200 Hz, IMHO.

Jan-Erik.



2005\09\27@185608 by olin piclist

face picon face
Jan-Erik Soderholm wrote:
> Twice the highest freq that you want to be able to
> reproduce from the original signal. Bandwidth has nothing
> to do with it, IMHO.

Yes it does, but you have to know the target frequency range when
reconstructing the orignal signal from the samples.  Think about it this
way: Each frequency band with width of 1/2 the sampling frequency is aliased
accross the complete baseband 1/2 sampling frequency spread.  This is
usually bad because there is no way to know which original band a baseband
signal came from, and information is therefore lost.  However, if only one
such band was known to be present in the first place, then no information is
lost and it is possible to reconstruct the original signal.  In other words,
each baseband frequency maps to one and only one input frequency allowing
the input to be reconstructed.

It works like a sampling oscilloscope.  A 1Ghz signal may be sampled every
1.01 cycles to yield a look-alike signal at 10MHz.  This can't be
distinguished from a true 10MHz signal by looking at the samples, but if you
know that 10MHz and other frequencies that would cause the same alias are
not present except 1GHz, then you have an unambigous true picture of the
original signal.


*****************************************************************
Embed Inc, embedded system specialists in Littleton Massachusetts
(978) 742-9014, http://www.embedinc.com

2005\09\27@193949 by Harold Hallikainen

face picon face
Thanks for all the comments! Regarding Nyquist, I agree I'd have to sample
at twice the highest frequency or more if I want to reconstruct the
signal. But, I don't want to reconstruct the signal, I just want an
approximation of its amplitude. As has been pointed out, if I sample at
100 Hz and a 101 Hz tone is presented, I'd swing from zero to some value
at 1 Hz. However, it seems that frequencies very close to the sampling
rate would be a small portion of the overall audio. Frequencies further
from the sampling rate would be filtered out by the averaging filter.

Regarding use of the PIC internal clamp diodes instead of an external
diode to get rid of the negative swing, I've found in the past (especially
with the positive clamp diode) that current in the PIC clamp diodes causes
leakage into adjacent A/D channels. I don't know if this is the case on
the negative side, but I've seen it on the positive side. I haven't
checked it recently, so I don't know if that's the case with current
chips.

As I read the specs on VU meters, they are pretty much an averaging
device. They are supposed to reach 99% of their ultimate value within
300ms and overshoot by 1 to 1.5%. A National ap note says this is
equivalent to a damped second order response with a resonant frequency of
2.1Hz and a Q of 0.62.

Finally, the people responsible for the hardware side of this project
decided to do it all in hardware. They're going to rectify and filter the
audio and give the PIC a varying DC level that I'll measure whenever I
need to update the display level. Should work fine, but uses lots more
parts...

Again, THANKS for all the comments!

Harold

--
FCC Rules Updated Daily at http://www.hallikainen.com

2005\09\28@001120 by Jinx

face picon face
> the PICmicro has diodes of its own, so you might be able
> to get away with leaving out the diode

Any voltage on a pin below -0.6V leaves you open to latch-up,
which can destroy all or part of the PIC. If you want to clip the
negative portion of a 0V-centred AC voltage (or any portion
which could go below -0.6V or suppress below-ground noise
spikes for example) it is advisable to have a Schottky from pin
(a) to 0V (k). Also a 5V1 Zener (assuming 5V Vcc), also pin
(a), 0V (k) to prevent latch-up on the +ve side

2005\09\28@083851 by Gerhard Fiedler

picon face
Harold Hallikainen wrote:

> Thanks for all the comments! Regarding Nyquist, I agree I'd have to
> sample at twice the highest frequency or more if I want to reconstruct
> the signal. But, I don't want to reconstruct the signal, I just want an
> approximation of its amplitude. As has been pointed out, if I sample at
> 100 Hz and a 101 Hz tone is presented, I'd swing from zero to some value
> at 1 Hz. However, it seems that frequencies very close to the sampling
> rate would be a small portion of the overall audio. Frequencies further
> from the sampling rate would be filtered out by the averaging filter.

But still... a single bass tone that happens to be close to your sampling
frequency and in the right phase /will/ make your meter jump way beyond it
is expected to jump.

> As I read the specs on VU meters, they are pretty much an averaging
> device. They are supposed to reach 99% of their ultimate value within
> 300ms and overshoot by 1 to 1.5%. A National ap note says this is
> equivalent to a damped second order response with a resonant frequency
> of 2.1Hz and a Q of 0.62.

Yes, VU meters are not peak detectors. There are digital versions that have
both (often a bar for the VU value and a single dot for the peak).

> Finally, the people responsible for the hardware side of this project
> decided to do it all in hardware. They're going to rectify and filter
> the audio and give the PIC a varying DC level that I'll measure whenever
> I need to update the display level. Should work fine, but uses lots more
> parts...

But better. IMO there's no shortcut -- wanting to reproduce or not, if you
want to have reliable data about AC, you need to sample at twice the
bandwidth.

Gerhard

More... (looser matching)
- Last day of these posts
- In 2005 , 2006 only
- Today
- New search...