Let's Design and Build a (mostly) Digital Theremin!

Posted: 11/7/2013 2:55:50 PM
dewster

From: Northern NJ, USA

Joined: 2/17/2012

"moreover,  one of multiplications can be excluded if the amplitude symmetry between sine and сos is not required."  - ILYA

True, but then the sine frequency would be related to square root of the multiplier input, which is kind of awkward.

I (perhaps too) quickly sketched out what this would look like in digital logic:

This is basically an infinite Q state variable filter that is initially stimulated and allowed to ring forever.  Quite surprisingly, round off errors don't cause it to gain or lose energy over time.  The blocks "SIN", "COS", "FREQ", and "AMPL" are dual port BRAMs.  Not shown here (for clarity) is the additional registering between multiplies, adds, etc. to pipeline and speed things up, nor is address generation shown.  It would take three 18x18 multipliers and 16k words (18 bits wide) of BRAM.  Given a top speed of 200MHz for the multipliers, it could generate over 4000 sine waves of arbitrary frequency and amplitude at the sampling rate of 48kHz.  Though changing the frequency on the fly might alter the amplitudes.

A more direct method is this:

Here a phase accumulator indexes a sine wave ROM.  The blocks "FREQ", "PHASE", and "AMPL" are dual port BRAMs; "LUT" is the single port ROM.  There are ways to drastically reduce the size of the ROM (store 1/4 wave, linear and higher polynomial interpolation, frequency / phase dither, etc.).  It uses two less multipliers, and one less BRAM but that is taken up by a potentially larger ROM.  It is basically stable because there is no ringing or feedback going on, just phase accumulation.  It could supply the same ~4k sine waves as the previous circuit.

[EDIT] Oops, I screwed up on the input to the phase accumulator in the second method.  It should sum both the current phase value and some input value, so a multiplier isn't needed there (but one is still required for the amplitude section following).

In the first method I also left out a mux going to the sine input, similar to the one on the cos input, but with a fixed input of zero.

If I were to pick between these methods I'd probably go with the second.

Posted: 11/7/2013 10:26:16 PM
FredM

From: Eastleigh, Hampshire, U.K. ................................... Fred Mundell. ................................... Electronics Engineer. (Primarily Analogue) .. CV Synths 1974-1980 .. Theremin developer 2007 to present .. soon to be Developing / Trading as WaveCrafter.com . ...................................

Joined: 12/7/2007

"Given a top speed of 200MHz for the multipliers, it could generate over 4000 sine waves of arbitrary frequency and amplitude at the sampling rate of 48kHz." - Dewster

Thats fine if one is producing an output waveform at audio frequency.. I dont think it will work for what I am doing - I want an adjustable (additive synthesis) reference waveform - the fundamental of this being say 100kHz (certainly not lower than 48kHz) with the 24th harmonic being a sine wave at 2.4MHz (assuming F1=100kHz)..

This waveform is to be down-converted to anything in the audio range (say 16Hz to 8kHz).. so in order to get a resolution equivalent to an audio sample rate of 48kHz, one would need a reference waveform to be composed of 3k samples (in order to provide 3k samples when played back at 16Hz, which is what you get from a 48kHz sample rate) - which works out at 144MHz (Msps) if the reference is running at 48kHz, or 300MHz (Msps) for a 100kHz reference waveform.. (and I am actually running my reference oscillator running at 150kHz, with the actual resultant down-converted waveform having effectively a variable sample rate between say 140 and 150 kHz, or between say 150 and 160 kHz)

For a digital theremin (this threads topic) or other monophonic digital instrument , your method (direct digital synthesis - waveform produced by whatever means you choose) which directly outputs with 48kHz sampling, is ideal..

But I am not sure that what I want can be done exclusively using digital processes - or at least, not with available low cost parts.. As I say - I am not sure - but this may just be down to ignorance.

I fully realize that I am not going about things the way a real digital / FPGA designer would - I am still using these incredible parts as if I was using glue logic and MSI parts one bolt together - my head is looking at and thinking analogue, and the digital is an economy measure to use reluctantly because getting 24 custom cut crystals and implementing high frequency VCA's isnt practical, LOL ;-)

Fred.

Posted: 11/7/2013 11:16:10 PM
dewster

From: Northern NJ, USA

Joined: 2/17/2012

"I fully realize that I am not going about things the way a real digital / FPGA designer would - I am still using these incredible parts as if I was using glue logic and MSI parts one bolt together - my head is looking at and thinking analogue, and the digital is an economy measure to use reluctantly because getting 24 custom cut crystals and implementing high frequency VCA's isnt practical, LOL ;-)"  - FredM

Yes, combining multi-rate processes (using different sampling rates) and shoving the result out a single D/A converter is quite painful in an FPGA due to the rate conversion filtering (necessary to minimize aliasing).  D/A's aren't exactly a dime a dozen, ones that work at higher sampling rates can be tricky to employ as they usually don't contain quality reconstruction filters, and their price tends to rise with sampling rate.  So the order of the day when doing DSP audio is to have one standard sample rate all the way through, and if necessary adapt the algorithms to this.

Posted: 11/7/2013 11:39:56 PM
FredM

From: Eastleigh, Hampshire, U.K. ................................... Fred Mundell. ................................... Electronics Engineer. (Primarily Analogue) .. CV Synths 1974-1980 .. Theremin developer 2007 to present .. soon to be Developing / Trading as WaveCrafter.com . ...................................

Joined: 12/7/2007

"Yes, combining multi-rate processes (using different sampling rates) and shoving the result out a single D/A converter is quite painful in an FPGA ....... " - Dewster

Oh - Thats not what I am trying to do! ;-) .. I know the folly of that!

I am happy for the reference waveform to be fixed sample rate - but im not sure I can get the waveform produced / converted fast enough.. I need the waveform out at say 100kHz, for it to be a fixed frequency,and for it to be of sufficient resolution that when converted down to audio frequency the quality is good (equiv to CD sampling).

But yes - D/A is a problem at high frequencies.. Particularly if one wants lower cost.

Fred.  

Posted: 11/9/2013 5:12:13 PM
dewster

From: Northern NJ, USA

Joined: 2/17/2012

Ran across this TI paper the other day:

http://www.ti.com/lit/an/slaa379/slaa379.pdf

Title: "MSP430 Capacitive Single-Touch Sensor Design Guide"

Nice discussion of sensor geometry, dielectric coverings, adhesives, ESD, low pass filtering, and thresholding.

Posted: 11/9/2013 8:42:54 PM
FredM

From: Eastleigh, Hampshire, U.K. ................................... Fred Mundell. ................................... Electronics Engineer. (Primarily Analogue) .. CV Synths 1974-1980 .. Theremin developer 2007 to present .. soon to be Developing / Trading as WaveCrafter.com . ...................................

Joined: 12/7/2007

Yes - that article has some interesting details - particularly with regard to adhesives etc.. Thanks Dewster.. What follows is not me trying to 'knock' the substance of this article - it is excellent for the application described.. But I feel I need to caution anyone who wants to take this approach as a basis for a theremin..

The LPF and thresholding discussed is ok for simple switches, but doesnt (usually) fully solve problems when the C-sense needs a fast analogue (or numeric) output ..Oh, apart from the digital filter implemented in Cypress Cap-Sense, I havent used or devised other digital filters - tried analogue filtering mostly.. but I found that a filter capable of getting rid of mains modulation gave a resulting latency of >20ms.. Fine for a switch, not so nice for a pitch antenna IMO.

This was one of the killers for my Epsilon project - the low voltage on the antenna meant that there was a lot of noise on the signal - (by noise I am talking about LF mains and HF digital stuff induced or coupled to the antennas via the player and the circuitry) .. My antenna was at hi-Z with a <5V triangle wave on it.. the induced signals just caused utter havoc, particularly when I put it all together in its box and the LCD cables were closer to the antennas.

A big advantage of having a series inductor in the antenna circuit is the great increase in voltage on the antenna.. If one has 50mV of induced 'noise' on 5V antenna signal, this is 10x worse than having that 50mV on a 50V signal.

If one is forced to have a series inductor in your antenna circuit, and one is using conventional theremin topology (where the oscillator frequency is determined by the hand capacitance) then sticking to the standard LC tank oscillator is probably sensible.. If one is doing things more "digitally" (As I was with Epsilon) then one can still use a series antenna inductance to improve the signal to noise ratio..

But my expierience is that simple RC schemes like described in the article are far from ideal for theremins.. But it may, of course, be that I am just an incompetent oaf!  ;-)

Fred.

Ps.. Dewster - it looks like something happened to your cats wavefunction.. ;-) .. No, I DONT understand the maths!  ;-)

Posted: 11/9/2013 10:03:57 PM
dewster

From: Northern NJ, USA

Joined: 2/17/2012

"...But I feel I need to caution anyone who wants to take this approach as a basis for a theremin...

...but I found that a filter capable of getting rid of mains modulation gave a resulting latency of >20ms.. Fine for a switch, not so nice for a pitch antenna IMO.

...A big advantage of having a series inductor in the antenna circuit is the great increase in voltage on the antenna.. If one has 50mV of induced 'noise' on 5V antenna signal, this is 10x worse than having that 50mV on a 50V signal..."  - FredM

Yes, so true.  RC methods don't generally have enough voltage swing to swamp environmental interferers.  And the LC (series "EQ" L & antenna stray C) forms a natural high Q peaky low pass filter.  To me, this one-two punch was Lev's biggest and best in his bag of Theremin tricks.  It seems that low voltage broadband approaches are rather doomed to failure for long-range pitch control. 

Minimum LPF latency is inversely proportional to the frequency you want to squash, for 50Hz this is 20ms.  From my experiments I believe latency shouldn't be more than a few ms or so.  Squashing single frequencies and their even harmonics can be done fairly effectively with high Q digital comb filters, but it's much easier to kill most interferers up-front with a high voltage & Q LC front end.

"it looks like something happened to your cats wavefunction"  - FredM

Ha ha!  It's actually an animated gif, too bad that doesn't work.

Posted: 11/24/2013 11:16:36 PM
dewster

From: Northern NJ, USA

Joined: 2/17/2012

Speaking of sine wave generation, thought I'd pass along a couple of good papers I ran into recently:

http://lionel.cordesses.free.fr/gpages/DDS1.pdf

http://lionel.cordesses.free.fr/gpages/DDS2.pdf

A bit OT but this one's a lot of fun:

http://sites.ieee.org/scv-cas/files/2013/02/2012Galanopoulos.pdf

Posted: 11/25/2013 9:42:32 AM
FredM

From: Eastleigh, Hampshire, U.K. ................................... Fred Mundell. ................................... Electronics Engineer. (Primarily Analogue) .. CV Synths 1974-1980 .. Theremin developer 2007 to present .. soon to be Developing / Trading as WaveCrafter.com . ...................................

Joined: 12/7/2007

Interesting stuff in some of those!

I found this site: http://www.vias.org/about.html which has some technical books (old radio theory, magnetics etc) now in the PD..

Alas, as yet I havent found a way to download the books, and the site is cluttered with ads which squash the contents - howver, im sure there must be other sites hosting some of these books as they are pd.

Fred.

Posted: 11/25/2013 8:21:42 PM
dewster

From: Northern NJ, USA

Joined: 2/17/2012

Thanks for that pointer Fred!  I was able to download the books I was looking at there: click on the book, then click on "download and release history", then click the zip file.  The books are in HTMLhelp file form which is kind of nice.

You must be logged in to post a reply. Please log in or register for a new account.