Reply by Peter Dickerson●October 22, 20062006-10-22
<billyman3@gmail.com> wrote in message
news:1161387512.916834.255420@b28g2000cwb.googlegroups.com...
> 1 multiply, 1 add, 1 subtract?
>
> on a 14-bit PIC core, (8-bit integer math) the multiply simplifies to
> 8bit x 8bit -> 16bit, then take bits 2-9 (shift left) to compensate for
> 2*cos, move to w, subtract, add.
>
> I estimate that line would take ~20 - 45 cycles which, @ 5MIPS (20
> Mhz) comes out to 4-9us. 250000 - 111100 times per second.
I don't see 8 bit cutting it. If the frequency of interest is much smaller
than the sample freqency the cos will be close to 1. Also the Goertzel
algorithm uses differences of adjacent yn, so rounding error can easily get
amplified.
Peter
Reply by linnix●October 22, 20062006-10-22
> ...
> If harmonics are the problem, simply don't generate them in the
> first place. A three stage shiftregister counter driven by 6x the
> fundamental with a bit of logic can generate a signal free of all
> harmonics up to the 5th, and free of all even harmonics.
We don't always have control over the input waveforms. I don't exactly
know what the OP's requirements are. But for my need, I simply fast
fourier the initial samples to extract the characteristic frequencies
and goertzel it for the duration of the signal. I need approx. 4K of
fourier coefficient and 1K of goertzel coefficient tables. Which is
not a problem, since I have 64K to work with.
Reply by CBFalconer●October 22, 20062006-10-22
Paul Keinanen wrote:
> "linnix" <me@linnix.info-for.us> wrote:
>
... snip ...
>>
>> In addition to the problems with harmonics, the frequencies
>> resolutions must be very clean. So, a minimum of 360 phasers
>> must be used. Withsuch resolutions, the coefficents are like:
>> 0.0174, 0.0348, ... 0.9993 and 0.9998. At the extreme end,
>> the differences are 0.05%.
>
> Where did you get that 360 phasers from ?
>
> With 5512 Hz (original fs/8) sample rate and 16 bit phase
> accumulator, the NCO can generate any frequency 0,084 Hz apart,
> with 24 bits and the original sample rate, the frequency
> resolution is even finer. Any out of synch signal will generate
> a beat tone (difference between the NCO frequency and the input
> signal frequency) and you have to consider this when averaging.
If harmonics are the problem, simply don't generate them in the
first place. A three stage shiftregister counter driven by 6x the
fundamental with a bit of logic can generate a signal free of all
harmonics up to the 5th, and free of all even harmonics.
--
Chuck F (cbfalconer at maineline dot net)
Available for consulting/temporary embedded and systems.
<http://cbfalconer.home.att.net>
Reply by Paul Keinanen●October 22, 20062006-10-22
On 21 Oct 2006 10:25:40 -0700, "linnix" <me@linnix.info-for.us> wrote:
>
>> Since the frequencies of interest are in harmonic relation, the 2f and
>> 4f could directly cause unwanted mixing products with any harmonic
>> distortion in the frequency f detector. Also the 3rd and 5th harmonic
>> can beat with nearby potential tones.
>
>In addition to the problems with harmonics, the frequencies resolutions
>must be very clean. So, a minimum of 360 phasers must be used. With
>such resolutions, the coefficents are like:
>0.0174, 0.0348, ... 0.9993 and 0.9998. At the extreme end, the
>differences are 0.05%.
Where did you get that 360 phasers from ?
With 5512 Hz (original fs/8) sample rate and 16 bit phase accumulator,
the NCO can generate any frequency 0,084 Hz apart, with 24 bits and
the original sample rate, the frequency resolution is even finer. Any
out of synch signal will generate a beat tone (difference between the
NCO frequency and the input signal frequency) and you have to consider
this when averaging.
If you are referencing with the 360 phasers that the input waveform
can have any phase difference relative to the NCO carrier, this is not
a problem, since IQ detection is used. When the signal phase is the
same (or 180 degrees) as the NCO phase, the I (in phase) multiplier
will produce +/- 1, while the Q (quadrature) will produce 0. At 90
and 270 degrees I will produce 0 and Q +/-1. At 45 degrees both I and
Q will produce 0.71. When the magnitude is calculated as
square_root(I�+Q�), you will always get the same result regardless of
phase. There is no need to calculate the square root for each sample
separately, since you are interested in the average power anyway.
The simplified method calculates just abs(I)+abs(Q), which at 0 and 90
degrees produces 1, but at 45 degrees produces 1.41, which is 3 dB off
the correct result, however, in many applications, this is sufficient
accuracy.
Paul
Reply by linnix●October 21, 20062006-10-21
> Since the frequencies of interest are in harmonic relation, the 2f and
> 4f could directly cause unwanted mixing products with any harmonic
> distortion in the frequency f detector. Also the 3rd and 5th harmonic
> can beat with nearby potential tones.
In addition to the problems with harmonics, the frequencies resolutions
must be very clean. So, a minimum of 360 phasers must be used. With
such resolutions, the coefficents are like:
0.0174, 0.0348, ... 0.9993 and 0.9998. At the extreme end, the
differences are 0.05%.
> Thus the multiplication
> waveforms should be quite clean, so the phase accumulator should be at
> least 16 bits, preferably 24 bits and the sin/cos coefficients should
> be 12-16 bits.
No less than 16 bits with the exception of input data, where you are
expected to accept some errors anyway.
> To reduce the lookup table size, a single quadrant of
> the sinus table could be used, but this requires branching according
> to the quadrant and two additions/subtraction to adjust the arguments
> according to quadrant.
Even 1K lookup table is fine. Without the tri functions, the entire
program can fit in 8K including floating point. My benchmark is done
on the same Luminary Micro LM3S811 (64K flash) as the OP is using.
>
> Paul
Reply by David Ashley●October 21, 20062006-10-21
Tauno Voipio wrote:
> David Ashley wrote:
>
>>
>>
>> The frequencies go from a base frequency up by a
>> constant factor of 1.05946 in each step. That's
>> just 2 ^ (1/12). 12 steps and you're at double the
>> original frequency.
>
>
> Tempered musical scale?
>
> Reference at 440 Hz?
>
>
Yes, musical scale. Not for automatic transcription
(asked elsewhere). Hopefully no more 20 questions!
:)
Relates to a potential idea for the Circuit Cellar contest
on the luminarymicro kit. Don't know if I'll pursue it
though. I got a free kit and want to play with it if I
ever get time...
-Dave
--
David Ashley http://www.xdr.com/dash
Embedded linux, device drivers, system architecture
Reply by Robert Scott●October 21, 20062006-10-21
On Fri, 20 Oct 2006 17:30:39 -0700, David Ashley
<dash@nowhere.net.dont.email.me> wrote:
>Robert Scott wrote:
>> On Fri, 20 Oct 2006 14:25:57 -0700, David Ashley
>> <dash@nowhere.net.dont.email.me> wrote:
>>
>>
>>>The frequencies go from a base frequency up by a
>>>constant factor of 1.05946 in each step. That's
>>>just 2 ^ (1/12). 12 steps and you're at double the
>>>original frequency.
>>
>>
>> So, you're making a piano tuner, eh?
>>
>>
>> Robert Scott
>> Ypsilanti, Michigan
>
>Nope! Actually I think for that application you'd want
>much higher accuracy than I'm interested in. And
>you'd only need to tune one frequency at a time, so
>you could put a lot more cpu onto the task...
Automatic transcription?
Robert Scott
Ypsilanti, Michigan
Reply by Paul Keinanen●October 21, 20062006-10-21
On Fri, 20 Oct 2006 14:25:57 -0700, David Ashley
<dash@nowhere.net.dont.email.me> wrote:
>The frequencies go from a base frequency up by a
>constant factor of 1.05946 in each step. That's
>just 2 ^ (1/12). 12 steps and you're at double the
>original frequency.
What is the highest fundamental frequency you are interested in ? If
the input signal is digital samples at 44100 Hz and the highest
frequency of interest is only a few kHz, I would suggest low-pass
filtering the input to 4-5 kHz, decimate it to say 11025 kHz and do
the rest of the processing at that sampling rate, perhaps even 5501 Hz
would be enough.
One way of detecting these tones would be to use the numerically
controlled oscillator (NCO) principle. For each frequency maintain a
phase accumulator, incremented by the frequency specific phase
increment at the common sample rate. Use the phase accumulator to
address sine and cosine tables, multiply the input sample with these
coefficients in the I and Q multiplier and square the results and add
them together.
If 3 dB amplitude error is allowed, just take the absolute values of
the I and Q multiplications and add together. In the simplest case
this would be two additions, two table lookups, two multiplications
and two absolute values for each sample and frequency of interest.
Since the frequencies of interest are in harmonic relation, the 2f and
4f could directly cause unwanted mixing products with any harmonic
distortion in the frequency f detector. Also the 3rd and 5th harmonic
can beat with nearby potential tones. Thus the multiplication
waveforms should be quite clean, so the phase accumulator should be at
least 16 bits, preferably 24 bits and the sin/cos coefficients should
be 12-16 bits. To reduce the lookup table size, a single quadrant of
the sinus table could be used, but this requires branching according
to the quadrant and two additions/subtraction to adjust the arguments
according to quadrant.
Paul
Reply by Tauno Voipio●October 21, 20062006-10-21
David Ashley wrote:
>
>
> The frequencies go from a base frequency up by a
> constant factor of 1.05946 in each step. That's
> just 2 ^ (1/12). 12 steps and you're at double the
> original frequency.
Tempered musical scale?
Reference at 440 Hz?
--
Tauno Voipio
tauno voipio (at) iki fi
Reply by linnix●October 20, 20062006-10-20
>
> The frequencies go from a base frequency up by a
> constant factor of 1.05946 in each step. That's
> just 2 ^ (1/12). 12 steps and you're at double the
> original frequency.
In that case, I think N need to be at least 500. So, you need approx.
40MHz ARM. I assume that your base frequency is 440Hz and max. freq is
1567Hz.