Audio sine wave
Erlend
Posts: 612
in Propeller 1
I am going to use audio to indicate small variations from a set of sensors (- in stereo). The ear is extremely sensitive to changes in frequency, but it needs to be a pure tone - sine - in order to work well. Square wave contains an endless series of harmonics, which appears to be confusing. Can anyone point me to a source or a technique that will allow me to generate variable frequency (300Hz-5kHz) sine wave with few harmonics in it? Yes, I will put in a hardware filter, but that generally is only good for the very high hramonics. And I prefer it to be in Spin or other high level language.
Happy New Year,
Erlend
Happy New Year,
Erlend
Comments
Requires building an R2R D/A
One of the biggest contributors was Drone.
I found a link to his post
forums.parallax.com/discussion/121470/a-sine-wave-dds-in-pasm-comments/p1
DDS would allow you to switch between tones easily
Tom
Humans are very good at picking out sounds of interest in what looks like noise.
Give it a try with your sensors, you might be surprised.
http://obex.parallax.com/object/688
Do you mean use AD9851 , or SW DDS on Prop ?
A dedicated DDS will have higher performance, but for 300Hz-5KHz sound-alert, a dedicated DDS is way-overkill.
With a upper target of a modest 5KHz, you may find the DAC can be simplified.
eg sqrt(80M/5k) = 126.49
means you can have ~7 bits in the X axis and ~7 bits from PDM DAC in the Y axis.
Not top-shelf Audiophile performance, but very good for a sound-alert.- and just a simple RC filter.
Erlend
I remember back in the (original) hifi vinyl days, how even a microscopic instability in record player speed would be picked up by the ear - and ruin the listening experience. Now I want to see if I can use that sensitivity to my advantage.
Erlend
Erlend
I had a simple DDS in software. Just a simple loop that increments a 32 bit counter as fast as possible. The top 8 bits of the counter go out to the resistor ladder. The size of the increment determines the output frequency.
Of course the Prop has counters for that.
A DUTY mode PWM output is much better than a 8bit R-2R DAC and needs only one pin.
Here is a very simple tone generator, that outputs a triangle - very close to a sine. All you need is a ~250 Ohm resistor between the output and the Earphone.
Andy
Those top 8 bits of the 32 bit counter are used to index an array containing 8 bit samples of a sine wave. It's the result of the array look up that is output to the resistor ladder.
Or use those 8 bits to fetch sin values from the PROM table. Probably slower.
*****************************************
* Frequency Synthesizer demo v1.1 *
* Author: Beau Schwabe *
* Copyright (c) 2007 Parallax *
* See end of file for terms of use. *
*****************************************
Original Author: Chip Gracey
Modified by Beau Schwabe
*****************************************
}}
{
Revision History:
Version 1.0 - original file created
Version 1.1 - For Channel "B" there was a typo in the 'Synth' object
The line that reads...
DIRB[Pin]~~ 'make pin output
...should read...
DIRA[Pin]~~ 'make pin output
}
PUB Synth(CTR_AB, Pin, Freq) | s, d, ctr, frq
Freq := Freq #> 0 <# 128_000_000 'limit frequency range
if Freq < 500_000 'if 0 to 499_999 Hz,
ctr := constant(%00100 << 26) '..set NCO mode
s := 1 '..shift = 1
else 'if 500_000 to 128_000_000 Hz,
ctr := constant(%00010 << 26) '..set PLL mode
d := >|((Freq - 1) / 1_000_000) 'determine PLLDIV
s := 4 - d 'determine shift
ctr |= d << 23 'set PLLDIV
frq := fraction(Freq, CLKFREQ, s) 'Compute FRQA/FRQB value
ctr |= Pin 'set PINA to complete CTRA/CTRB value
if CTR_AB == "A"
CTRA := ctr 'set CTRA
FRQA := frq 'set FRQA
DIRA[Pin]~~ 'make pin output
if CTR_AB == "B"
CTRB := ctr 'set CTRB
FRQB := frq 'set FRQB
DIRA[Pin]~~ 'make pin output
PRI fraction(a, b, shift) : f
if shift > 0 'if shift, pre-shift a or b left
a <<= shift 'to maintain significant bits while
if shift < 0 'insuring proper result
b <<= -shift
repeat 32 'perform long division of a/b
f <<= 1
if a => b
a -= b
f++
a <<= 1
DAT
{{
┌──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┐
│ TERMS OF USE: MIT License │
├──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┤
│Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation │
│files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, │
│modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software│
│is furnished to do so, subject to the following conditions: │
│ │
│The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.│
│ │
│THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE │
│WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR │
│COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, │
│ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. │
└──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┘
}}
? I do not follow the separate filters ?
Any DDS with a lookup table, has small triangular errors that are related to the number of steps.
For even a modest DDS, that spectral content is up at 76kHz, way above the 5kHz target.
The expensive AD9851 has content nearer 300kHz
For what the OP needs, a Prop COG will be fine.
Ah, ok - I thought you were saying a scaled filter was needed with DDS / AD9851 designs.
The Prop can manage DDS with faster PWM in a single COG.
Erlend