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

Posted: 5/14/2012 8:49:11 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

This is impressive stuff, Dewster!

And you have done the same as I eventually did for my Epsilon design, on your AFE.. Having a fixed frequency oscillator in "mode 0".. When looking at 4 'antennas' in close proximity, having a common oscillator and determining X and Y co-ordinates (and Z from the sum) is a lot easier by determining phase relationships than trying to use FM.

Regarding the PSoC - Yes, you are absolutely right - I realized that I was going in the wrong direction with this quite early, but not quite early enough, LOL! Right at the start of my theremin venture (5 years ago !?) I thought I had cracked it - I had a working PSoC theremin, and joined TW to let the world know that the analogue theremin was about to be replaced... Ha Ha ! ;-)

- At that time, I had never seen a theremin being played - had no real understanding about any of the finer points - I simply assumed that no-one had bothered to innovate on the basic concept, and that it was time to get rid of the junk and drag the theremin, screaming, into the digital 21st century....

I know you are not an idiot like I was back then - I think my aversion to digital theremins may be partly because the idea reminds me of my folly!

I will look over your verilog ASAP - I have extremely little exposure to verilog (ABEL is the only language I used for CPLD's)

Thanks for revealing so much - It is a real pleasure to engage with people who share their knowledge freely.

Fred.

Posted: 5/14/2012 9:08:29 PM
dewster

From: Northern NJ, USA

Joined: 2/17/2012

"Right at the start of my theremin venture (5 years ago !?) I thought I had cracked it - I had a working PSoC theremin, and joined TW to let the world know that the analogue theremin was about to be replaced... Ha Ha ! ;-)"

Fred, you're really scaring me!  But you're in good company, even Bob M. couldn't seem to get the Theremin out of his hair.

"And you have done the same as I eventually did for my Epsilon design, on your AFE."

[EDIT] Let me extol the virtues of the AFE:

- Simple square (ish) logic levels at input and output.

- Exceedingly clear resonance point defined purely in the phase domain.

- Pretty darn linear without any complex tuning procedures.

- Single ended logic level power supply.

- High voltage sine wave at the antenna.

"I will look over your verilog ASAP - I have extremely little exposure to verilog (ABEL is the only language I used for CPLD's)"

After years of coding in VHDL I was forced on a major project to switch to verilog - and I'm quite glad I was forced.  verilog isn't perfect (neither is VHDL) but it is less verbose and friendlier.

"Thanks for revealing so much - It is a real pleasure to engage with people who share their knowledge freely."

In industry literally everything is a secret for no good reason, making employees too frightened to say anything to anyone - I've pretty much had it.  Corporate secrecy will be the death of us, cooperation is the only sustainable existence.

Posted: 5/14/2012 9:18:53 PM
dewster

From: Northern NJ, USA

Joined: 2/17/2012

"MIDI is too slow and innacurate for theremins."

Fred, you're probably aware of this but I just ran across it a couple of days ago:

http://www.wave-theremin.com/spec-intro-overview.php

MIDI seems to be working pretty well with it.  I particularly like the "finger drum" video at the end of this page:

http://www.wave-theremin.com/video-tutorial.php

Posted: 5/14/2012 10:09:07 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

>> "MIDI seems to be working pretty well with it.  I particularly like the "finger drum" video at the end of this page:"

To be honest, it looks like a fun instrument - with possibly some serious musical applications.. I am not going to comment much more on this particular theremin, or be pedantic about whether in instrument without a volume antenna con be called a theremin - I have given up on that battle, and now accept that any proximity detector connected to an oscillator is a "theremin" - but it still sticks in my throat!

However - (I may be wrong) - The only performance using MIDI remotely approaching a "theremin" in the way I percieve a theremin, is the first - and this lacks the smoothness - it is using the pitch CC message I think.. And it is, IMO, horrible!

Perhaps if there were MIDI Synths / "recievers" which processed the full CC message and took another CC for volume, without retriggering the EG's (in fact, EGs are not needed or wanted) it would be worth looking at - But one would really need an external MIDI theremin module.

This whole subject has been extensively debated here before - I will see if I can find the link.

Fred.

Posted: 5/14/2012 10:19:27 PM
dewster

From: Northern NJ, USA

Joined: 2/17/2012

"This whole subject has been extensively debated here before - I will see if I can find the link."

That's OK, I'm almost certainly not going to go the MIDI route.  MIDI seriously needs an update (more bandwidth, audio channels, etc.) but I don't think it will happen in the current climate as it tends to commodify products.

Confusingly on my part, I was pointing the product out as more of a digital approach to Theremin pitch than MIDI.  It appears to be a garden-variety Theremin circuit plus processor and some other stuff (from their FAQ):

"The sensing circuit with the antenna attached, is a proper Theremin Circuit (using inductors, reference oscillator and nearly identical pitch-antenna oscillator, finely tuned with matched, high quality components and electronic tuning circuit)"

It also has volume antenna stuff they don't populate unless you specifically ask and pay for it, and then they put it in a bigger case.  Kind of strange.

Posted: 5/16/2012 10:43:00 PM
dewster

From: Northern NJ, USA

Joined: 2/17/2012

THE REPOSITORY

For the last couple of days I've been adjusting and altering the digital Theremin FPGA logic.  The pitch numbers I was getting from the DPLL had too few significant digits above the noise floor at lower playing frequencies, and indeed this was something I anticipated - I spent at least a month on and off investigating with back of the envelope math and various simulations, trying to determine if this project even had a shot at working (which mostly boils down to the AFE Hz/pF sensitivity, and the whiteness of the phase noise from the DPLL).  I knew it would be close, if it indeed would work at all.

Anyway, I tried increasing the DPLL NCO and error accumulator width, as well as lowering the cutoff of the downstream first order filter.  Widening the error accumulator didn't help much, but lowering the cutoff of the filter did.  There's no problem increasing the SNR this way if you love all portamento all the time and hate vibrato :-)  but I think we'd all agree that vibrato is pretty important to the Theremin, as is highly responsive pitch.

Today I replaced the first order filter with a state variable second order filter, and that seems to have done the trick.  I can open it up to around 340 Hz (~3 ms response time) and the phase noise seems tolerable.  I need to move to a different development board with a DAC so I can start making noises other than square waves.

The repository of files, including my latest verilog code, is here:

http://www.mediafire.com/?w36b3brqyg2g3

Also there are several spreadsheets I wrote that helped me during the design process.  "Theremin_NCO_RLC_PLL_2012-04-15.xls" is kind of neat because it stimulates an RLC with an NCO and phase locks to the result.  "Theremin_frequency_display.xls" shows how to do either the CORDIC or the al Kashi log2 algorithms - I chose al Kashi because it doesn't require the storage of any constants and is more straightforward.  "filters_1st_2nd_4th_order.xls" and "filters_1st_2nd_4th_order_quickie.xls" show you how to build floating point and integer based multiplier or multiplier-less (power of 2 shifts) digital filters.  Spreadsheets are your friend when undertaking any numeric design job.

I'll post whenever there is a significant update or addition.

Posted: 5/17/2012 5:14:30 PM
dewster

From: Northern NJ, USA

Joined: 2/17/2012

"And you have done the same as I eventually did for my Epsilon design, on your AFE.. Having a fixed frequency oscillator in "mode 0".. When looking at 4 'antennas' in close proximity, having a common oscillator and determining X and Y co-ordinates (and Z from the sum) is a lot easier by determining phase relationships than trying to use FM."

For the pitch side I have the DPLL adjusting its frequency to maintain a quadrature phase relationship, and use this operating frequency as a numeric input to the audio NCO.  Phase locking allows a wider, more linear operating range for the AFE.

But for the amplitude side, where linearity isn't so important, I may go with what you are describing: multiple "antennae" connected to individual LC mode 0 circuits (probably without "linearizing" coils) and stimulated by a fixed frequency NCO (or just the output of a simple noise dithered divider).  Then have the digital side look at the small changes in the individual phase relationships with changing hand capacitance.

Posted: 5/25/2012 12:57:12 PM
dewster

From: Northern NJ, USA

Joined: 2/17/2012

I've tried many approaches in order to reduce low frequency phase noise, and came to a realization yesterday that much of what I've been fretting about for the last week or so was simply the result of looking at very small operating point numbers.  SNR is quite poor there because the signal is so small, not because the noise is particularly bad.

I've had a second order filter after the DPLL to trade response time for increased resolution.  Yesterday I found that the low pass filtering of the DPLL itself (if the design parameters are set for a roughly equivalent pass band) gives the same subjective performance.  So the filter is now out and the design is simplified.

I'm grappling with linearity and note spacing now.  If I adjust the DPLL offset to give the null point with my body about 2 feet away, I get the fairly linear open hand / fist octaves shown in the posted video.  But changing that to get wider note spacing farther out doesn't change the spacing near the antenna, where the notes remain rather cramped.  It would be nice to have a simple curve & offset that could correct this, or some piece-wise linear fit as long as it isn't too difficult for the average user to perform.  I'm loath to go from the semi-logarithmic domain to the linear domain and back again to do this as that would be more complex, and fear what it might do to the noise dither.  Squaring numbers in an FPGA isn't too difficult, but the polynomial fit I've looked at in a spreadsheet seems super sensitive to coefficients.  This might be best left to a processor, placing the linearity / spacing calculations in the audio update loop.

Posted: 5/26/2012 2:55:27 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

Ok, this problem is not a new one.. I am not sure what you mean by "go from the semi-logarithmic domain to the linear domain and back again".

My focus has always been on the analogue - I would (if I were you) be looking at linearizing the AFE rather than doing the main linearization digitally - but this is probably because I find this easier.. I wonder if there is a way to combine analogue and digital correction at your AFE - For example, if you had a seperate control signal from your FPGA and this adjusted (using a varicap or similar) the capacitive coupling to the antenna - This way, you could implement linearization by controlling the capacitance 'seen' on the antenna.

Fred.

Posted: 5/26/2012 4:08:23 PM
dewster

From: Northern NJ, USA

Joined: 2/17/2012

"I am not sure what you mean by "go from the semi-logarithmic domain to the linear domain and back again"."

I'm not sure what I meant either!  First: "semi-log"?  Second: it's going from exponential to linear and back. 

So I could take the operating point (low pass numerical) output of the DPLL which is roughly exponential with linear hand position, route it to a numerical log2 converter (like the tuner), play with the numbers in the linear domain where many things are easier, then do some kind of exponential conversion back.  But before I throw in that towel, I'm playing with offsets, multiplications, and divisions by powers of 2 (easy things to do in an FPGA) in the exponential domain to see if there are any relatively simple data manipulations that might yield a roughly linear (sounding to the ear) response.

One thing I really tried hard for on the AFE was to have only purely digital I/O (which it has).  In fact, one may (I haven't tested this yet) be able to dispense entirely with the 4000 series CMOS and just stick the inductors and caps right on the FPGA demo board, which would yield an incredibly simple analog arrangement.  So I'm rather loathe to introduce any analog complexity here.  Stability (drift) seems pretty good, and adding any components might negatively impact that.

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