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

Posted: 3/6/2020 1:32:51 PM
Buggins

From: Theremin Motherland

Joined: 3/16/2017

Dewster,

See my analysis of main hum noise problem in my thread

Posted: 3/8/2020 5:02:46 PM
pitts8rh

From: Minnesota USA

Joined: 11/27/2015

Back to the D-Lev for a moment...

1) On the subject of ACAL again, I'm thinking that this new smaller D-Lev II housing is going to be a problem for placement of a button.  No matter where I go near the bottom of the front panel your trigger hand is going to be within four inches of the volume antenna.  Even if you could compensate for this with your VCAL setting I am afraid that the close proximity is going to magnify any inconsistencies in your triggering hand position.  Plus I've already placed the headphone and pitch preview jacks near the bottom, and even these are getting uncomfortably close to the high impedance area that I'm trying to avoid as much as possible.

I'm still thinking that a delayed ACAL would be the best answer for anyone who does not want the added foot switch accessory. This is assuming that you could do it in the software. This would allow the ACAL button with a flashing led (like a camera's delayed shutter) to be placed in any convenient position on the panel and you could hit the button and get into playing position (and smile if you wish) before the calibration runs.

I'm open to other suggestions, but as much as I like the pedal I don't think it should be a requirement and some sort of panel button will be needed.  I just have doubts about how it would work out with an arm that close to the volume antenna.

2) Finding small dual-ganged audio taper pots in the right physical size for master and preview volume is not looking good.  I'm thinking of going ahead with linear pots and shunt resistors and hope that these spdif/audio converters can drive them.  I haven't measured the source z of the converters, but worst case we might end up with a slight tapering or even none at all.  With small diameter knobs on the volume controls, I don't think it's all that important.   Your thoughts?

Posted: 3/8/2020 7:31:44 PM
dewster

From: Northern NJ, USA

Joined: 2/17/2012

"1) On the subject of ACAL again, I'm thinking that this new smaller D-Lev II housing is going to be a problem for placement of a button.  No matter where I go near the bottom of the front panel your trigger hand is going to be within four inches of the volume antenna.  Even if you could compensate for this with your VCAL setting I am afraid that the close proximity is going to magnify any inconsistencies in your triggering hand position."  - pitts8rh

It could be narrower enclosures with the coils inside might be a bit touchier to ACAL, though I just tried an ACAL with my fingers 4" away from the volume plate edge and that needs Vcal=36 to position the field.  Vcal and Pcal are straight encoder values, if needed I could possibly scale them a bit with a polynomial or similar to extend their range.  One tends to need more positive range, so maybe the knob range could be biased.

One thing I like a lot about instantaneous ACAL is I can see immediately on the note display if the ACAL was good, as it always goes to the same note when it is.  If it seems a bit off I just do another ACAL, all of which takes a split second.  The tediously time consuming and indistinct Theremini ACAL process left such a bad taste in my mouth I don't want to do anything like that if I can avoid it.  The instructions and the procedure associated with a delay might be more complicated (where should I put my arms?, etc.).

[EDIT] So i guess my response is: stick the button somewhere on the case, preferably not right next to either of the axes antennas or "business ends" of the coils, and the current SW will probably be able to deal with it.  If it can't we can likely alter it to do so.  I would pick somewhere on the lower right of the front panel, like on my prototype.

"2) Finding small dual-ganged audio taper pots in the right physical size for master and preview volume is not looking good.  I'm thinking of going ahead with linear pots and shunt resistors and hope that these spdif/audio converters can drive them.  I haven't measured the source z of the converters, but worst case we might end up with a slight tapering or even none at all.  With small diameter knobs on the volume controls, I don't think it's all that important.   Your thoughts?"

I'd do what you're doing, linear pots & shunts, though I don't have a lot of experience with it.  Volume taper itself is a hazy subject.

Posted: 3/8/2020 8:17:47 PM
dewster

From: Northern NJ, USA

Joined: 2/17/2012

Volume Axis Setup

Here's a video on how to set up the volume axis parameters:

It's pretty simple once you know how.  The pitch axis isn't too difficult either, I need to make a video of that as well.

[EDIT] I should have noted in the video: once the settings on the V_AXIS  page are set the way you like, save the system preset (after 12:30 in the video), and you probably won't ever have to visit the V_AXIS page again.  Almost everything else is accomplished with the per-voice knee settings.

And just to be clear, when I'm discussing "moving the response down to the x axis, then tilting it, then moving it back up" I'm talking about the mathematics behind the axis processing, not hand movement or hand tilting or anything like that (I wish...).

Posted: 3/8/2020 9:26:34 PM
pitts8rh

From: Minnesota USA

Joined: 11/27/2015

"One thing I like a lot about instantaneous ACAL is I can see immediately on the note display if the ACAL was good, as it always goes to the same note when it is.  If it seems a bit off I just do another ACAL, all of which takes a split second."

Maybe I'm a bit dated on software, but mine always comes up on the same note after ACAL (which depends on my global PCAL setting).  I have to make sure ahead of time that my arms are in the right position and distance or else the calibration will be off.  Sometimes if the calibration doesn't feel right I'll go to reposition my arms so that the tuner is slightly above or below that post-calibration note (this is where the tuner is indispensable) , and then hit ACAL again.  This is usually quicker for touching up the calibration than adjusting the knobs.  But in all cases I'm doing the calibration with both arms in an easily repeatable withdrawn position, usually both forearms held vertically.

Whether this is the same as your procedure or not, I agree that the tuner is key to quickly setting up a good calibration.

"The instructions and the procedure associated with a delay might be more complicated (where should I put my arms?, etc.)."

On this I'm afraid I'll have to disagree, wholeheartedly.  It could be as simple as: 1) hit the ACAL button 2) get your arms in a home position within 3 seconds (or so), 3) listen for the note to change (or the led to stop flashing) to confirm calibration 4) repeat if desired.  A position with the arms withdrawn close to the body is easily repeatable.

The alternative is to try to explain to a user how to compensate for the close proximity of the ACAL button-pushing hand to the volume antenna by setting the VCAL to offset for it.  Then the user would need to push the ACAL button with the same hand in the same position with respect to the volume antenna (hardly repeatable). I understand that this may be second nature to you doing it this way, but there is no way I would want to try to sell that to a new user.

In my mind this would be like trying to set the zero-point on a badly designed analog theremin that has the pitch knob located right under the pitch antenna.  Sure, you can maybe learn that if you turn the knob until you hear an A5 pitch you will be properly zeroed when you move your arm to the home zero-beat position, but this would be a touchy and non-repeatable way to do it.

The bottom line at the moment is that I need to drill holes in this new panel for switches or push buttons, but there is no good place to put a "live" acal switch on this small panel with the volume antenna on the bottom unless there is something like a delay feature.  Otherwise, the foot switch or even a hand-held remote pushbutton would be the best bet. I'm trying to think of this theremin in the hands of a new user, not just you or me, especially if this model has any chance of ending up as a demo.

Posted: 3/9/2020 2:55:34 PM
dewster

From: Northern NJ, USA

Joined: 2/17/2012

I kind of knee jerked there re. the Theremini there (sorry) - just recalling it's vague & untrimmable & slow as molasses (v1.0) calibration procedure in my head gives me hives. :-)

"The alternative is to try to explain to a user how to compensate for the close proximity of the ACAL button-pushing hand to the volume antenna by setting the VCAL to offset for it.  Then the user would need to push the ACAL button with the same hand in the same position with respect to the volume antenna (hardly repeatable).

In my mind this would be like trying to set the zero-point on a badly designed analog theremin that has the pitch knob located right under the pitch antenna.  Sure, you can maybe learn that if you turn the knob until you hear an A5 pitch you will be properly zeroed when you move your arm to the home zero-beat position, but this would be a touchy and non-repeatable way to do it."  - pitts8rh

The ACAL logic changed substantially a little under a year ago, and I yakked about it some in this post:

http://www.thereminworld.com/forums/T/28554?post=215139#215139

Here's what's going on during an ACAL (pitch side shown, volume side is identical):

The ACAL process is located immediately after axis filtering (LP & hum), but before the influence of Pcal and Vcal, and the construct is entirely feed-forward (i.e. no feedback going on).  It basically just snags (registers) the current axis number, and this frozen value (P_ANUL) is then subtracted from the live axis number to null the axis.  The above image could be a bit clearer, but Pcal / Vcal is then subtracted from the result to offset the null.   So Pcal / Vcal can directly compensate for whatever you want them to, and there isn't anything tricky going on at all in terms of the math, or multiple offsets, or feedback, or anything like that.  (Long ago I thought some sort of feedback was necessary here and so there were two encoder values to tweak.  But I was mistaken, and in fact there was never any feedback necessary nor going on.  That's the reason for the crossed out box in the above pic.)

This construct is quite transparent in operation, and automatically adapts to the environment via the ACAL procedure.  That is, the feedback is contained in the overall ACAL procedure, and not the SW process.  Wherever your body / arms / hands happen to be when the ACAL button is pressed, if it's more or less repeatable and Pcal / Vcal have the range to compensate for it, then this procedure should work:

- ACAL TRIMMING PROCEDURE -
0. Body / arms / hands in repeatable position (e.g. left hand at side, right hand pressing ACAL - lately I've been placing both of my hands on the controller box, as I demonstrate in the video).
1. Press ACAL.
2. Trim Pcal / Vcal for proper response.
3. Save the system preset (this saves Pcal & Vcal).

So, the actual physical pressing of ACAL can be used to correctly position one's body, which is extremely intuitive and useful, as the position of the body & hands heavily figure into the calibration itself.

The only way it might not work well is if an axis is set to be really sensitive in some odd way.  This is because the gain of the fields can vary due to environmental (intrinsic) C, and ACAL doesn't (and really can't) compensate for gain variation, only offset.  That said, I often swing the volume plate over my workbench, so it's maybe 2" above it and near metal tools and such, and after doing an ACAL it seems to behave as expected well enough.

I too use repeated ACAL to set the pitch side rather than trimming (though I sometimes pitch trim afterward for far field playing) - so having it be highly responsive lets me do 2 or 3 ACALs if I want to in as much time as it take to repeatedly press the button.  If there were some sort of delay I would probably not use ACAL as much and resort to trimming.  I never have to trim the volume field - my volume plate is located rather out in space which might help, but I think just in general the volume side is less critical (for my setup and the way I play).  But having any non-linearity in the pitch far field, particularly higher sensitivity out there, really throws my playing off, and I imagine it's the same for analog players.

"The bottom line at the moment is that I need to drill holes in this new panel for switches or push buttons, but there is no good place to put a "live" acal switch on this small panel with the volume antenna on the bottom unless there is something like a delay feature."

I think the way forward is to install all of the very latest firmware and software on your latest creation, and then use the external ACAL switch input to test out possible locations for the front panel switch (e.g. by gaffer taping some small switch).  Things can possibly get a bit squirrely if hands are extremely close to the antennas during ACAL, but e.g. I'm able to use Vcal to compensate for my fingertips being 1" away from the volume plate during ACAL.

Posted: 3/9/2020 6:22:53 PM
Buggins

From: Theremin Motherland

Joined: 3/16/2017

Dewster, 

Do you have all these calibration, scaling, conversion to note/frequency/volume/amplitude in program or in hardware?

I'm reimplementing sensor for Zilinx FPGA. So far, implementation till measured period IIR smoothing filter for both axis takes about 400LUTs.
Now I'm thinking about implementation of the rest of sensor. It may be direct FPGA implementation, microprogram in some lite softcore, or just part of PS (ARM core) program.

Making log2, divider, several adders, table based interpolators will take a lot of resources. Does it make sense to use tiny cpu softcore to implement such processing? E.g. with 50MHz core, for each 48KHz sample there are 1000 clock cycles. Enough even for complex processing.
I tried to make simple 16bit 4-core barrel CPU with one cycle 16x16 multiplication and barrel shifters. Estimation of full implementation is ~200 LUTs + 1DSP.

Does it make sense to put all logic and calculations into program in such CPU.

Are you using log2 in axis processing? Where do I find good algorithm example for its implementation?

Posted: 3/9/2020 7:48:55 PM
dewster

From: Northern NJ, USA

Joined: 2/17/2012

"Do you have all these calibration, scaling, conversion to note/frequency/volume/amplitude in program or in hardware?" - Buggins

I filter in HW enough to downsample (or decimate) at 48kHz.  The rest is in SW.

"Making log2, divider, several adders, table based interpolators will take a lot of resources. Does it make sense to use tiny cpu softcore to implement such processing? E.g. with 50MHz core, for each 48KHz sample there are 1000 clock cycles. Enough even for complex processing."

Off-loading axis final filtering and processing could leave more cycles for your main processor(s).

"I tried to make simple 16bit 4-core barrel CPU with one cycle 16x16 multiplication and barrel shifters. Estimation of full implementation is ~200 LUTs + 1DSP.  Does it make sense to put all logic and calculations into program in such CPU."

If you make a really wide multiplier (I think the one in Hive is 33 x 33 = 65) you can do all of your algorithms with it, including barrel shifting.  But it will need a lot of pipelineing to make it as fast as the HW can go (Hive has an overall pipeline depth of 8, >half due to the multiplier).  A good multiplier is absolutely key to many algorithms which rely on polynomials (just about everything) and / or iteration (inverse).  The expense and depth of the multiplier makes it a good candidate for sticking in a threaded processor construct.  Wide multiply is what separates toy processors from the real deal.

"Are you using log2 in axis processing?"

Yes, for the linearizing fractional power I do log2 and then exp2.

"Where do I find good algorithm example for its implementation?"

I spent a long time (>1 year) researching algorithms, trying them out in a spreadsheet, and "fitting" them into Hive opcodes.  You often don't need "calculator" type precision, but only 16 bits or so for some of the DSP work, and this can help you reduce cycles where the extra precision isn't needed.  It isn't as simple as truncating infinite series coefficients, as you can reduce the error dramatically by hand adjusting the remaining coefficients.  Intermediate truncation error can be minimized that way too.  I've got a sine calculation that is good to 16 bits that I use in the oscillators.

Here is my latest spreadsheet detailing all of the math algorithms I implemented in assembly, including floats, ints, unsigned, fixed point, etc.:

http://www.mediafire.com/file/5mi3vyd5iqdekut/HIVE_algorithms_2018-05-15.xls/file

Hive code is in the spreadsheet too.  I could write a book just on this!

I've also got polynomials to correct the filter cutoff frequencies, and polynomials to keep the oscillator harmonic levels from aliasing (in other spreadsheets).

I wore this site out when working on algorithms, it's extremely handy:

http://polynomialregression.drque.net/online.php

Also, all of the "bit shift" algorithms out there (like divide) assume no multiplier.  Once you have a multiplier you can do these things in a lot fewer cycles.

Posted: 3/9/2020 11:23:11 PM
dewster

From: Northern NJ, USA

Joined: 2/17/2012

Axis Null Revisited

I just realized that Pcal & Vcal never really need to go negative, as they will always be compensating in one direction for the capacitance environment.  Specifically: players place the pitch null "behind them" to linearize the far field, and this rationale holds for the volume null as well.  That Pcal &Vcal could go negative was legacy from when each were (idiotically) "offset to offset to null", which is now (rationally) just "offset to null".  So I took the [-127:128] range of both and converted it to [0:255] (via the parameter type system), which should help with offsetting even very close hands to the antennas when doing ACAL.  Here's the current scheme which is currently running on the prototype (pitch side shown, volume side is the same except the scaling is <<18):

1. Pcal is shifted left 16 to multiply it up (scaling).
2. It is then added to p_nul_ds, which is the latched version of p_flt_ds (filtered axis value) which gets stored / snagged @ ACAL.
3. The result is limited to eliminate overflow (probably can't happen).
4. The pitch number p_flt_ds is subtracted from this, which gives an increasing value as the hand approaches the antenna.
5. The result is limited to eliminate underflow (negative results, limiting gives a hard stop at the null point rather than axis reversal).
6. If the output is zero it is incremented to 1 to avoid floating point zero (a denorm) going downstream.

Seems to be working fine, and there was no need to change the stored parameter values, as the scaling remains is the same.

[EDIT] Updated the pic to be a bit clearer about the storage of p_nul_ds.

Posted: 3/10/2020 7:48:10 PM
dewster

From: Northern NJ, USA

Joined: 2/17/2012

Pitch Axis Setup Video Warmup

Today I'm taking a closer look at something I should have physically quantified a long while back: the influence of the pitch axis "Lin" knob on the D-Lev.  After it was implemented (following extensive spreadsheet simulation where I discovered it, and which showed it to work), I was able to dial in something that was really linear pretty quickly, so after scaling the knob step size and range to seem useful, I let the issue drop.  In preparation for a pitch axis setup video (like my volume axis setup video above) I'm trying out various settings to see what they do in real life.  My beautiful assistant (the wife) aided me as "data girl" by writing down the numbers I called out, after which I as "spreadsheet boy" graphed them in WPS Spreadsheets (Excel clone).  The dynamic duo strikes again.

The "Lin" encoder has a detent range of [-15:15] and this corresponds mathematically to a range of [-3/8:-1/8] power applied to the filtered, nulled, negated, and offset pitch number described in my last post.  So the nominal power is -1/4, and we shall see that this is a good "ballpark" for the center of the control to be located.  A negative power is the mathematical inverse, and a fractional power is actually a root, so we could express the center point of the function as: 1 / (4th root of the input).  And if I never contribute anything more to Theremin research than just this, I'll consider the years well spent.

The Lin control affects the overall gain, so we have to adjust the Sens control to compensate.  The data was acquired by placing my open hand within maybe 5mm or so of the pitch plate and rapidly opening it and closing it, and the Sens control was set to give a 1 octave change (one full revolution on the 12 LED tuner) in the very near field, with Pcal adjusted to give a similar response in the very far field.  The data points were recorded as deviations from the octave response in half-steps (one LED change on the 12 LED tuner).  The data itself is quite noisy (I wish I'd had a barstool or similar to steady my body) but it does reveal useful trends.


Above we see the results of setting the Lin control to -15, 0, and 15.  It's clear that negative setting produces a more sensitive mid field, and the positive setting produces a less sensitive mid field.  A more intuitive way to think about this control is large negative settings makes the near and far fields droop down, and large positive settings makes them perk up.  The zero setting gives us something more or less in the middle, which is very, very (very!) good linearity, a deviation of +/- 1 one half step over the entire playable range of the pitch field.  Since the difference is referenced to an octave, or 12 notes, this corresponds to +/- 8.3% deviation.  We can also see that the control doesn't profoundly influence the general linearized response, making it amazingly non-critical to set, thank goodness.  (Difficulty of setup is a major impediment to the general use of these types of controls.)


Narrowing things down, above we see the results of setting the Lin control to -8, 0, and 8.  Same general trend, and I would still pick the Lin = 0 response here.


Zooming up on zero even more, above we see the results of setting the Lin control to -4, 0, and 4, and it's a tough call as to which one to pick as they are all within +/-1.  Zero wins for near field, it's kind of a tie for mid field, but -4 wins for far field.  So, based only on this, I might go with -2 or -4.  FWIW, I picked -4 long ago and have been playing the D-Lev with that setting ever since.  I actually don't entirely trust this graph for fine comparison purposes, as we would expect the far field to perk up for more positive settings, and here we're seeing mixed results.  So I think we're mainly looking at noisy data in the far field here, particularly for the -4 setting.  So maybe zero or +2 is the way to go for my particular plate antenna geometry.

Just how linear is this in real-world terms?  Let's compare it to a "perfectly linear" (not my claim) analog Theremin, the Phoenix, with (very) roughly the same type of graph scaling:


Note the vertical axis scaling here, which had to be really expanded to contain the data.  So the situation for the Phoenix, particularly in the near field, is much, much (much!) worse than the D-Lev.  Other analog Theremins will be similar.  In contrast, you can play the D-Lev right up to the (insulated) antenna and it won't squeal.  I often bump into the antenna when reaching for a high note, as response-wise there's no absolutely no indication you're about to hit it.  Sometimes the note is right on the antenna, and it plays just fine (though obviously with no vibrato!).

And, as I've said ad nauseam, I don't play with this kind of sensitivity, where the open / closed hand = 1 octave = 12 half steps.  I've instead picked a much lower sensitivity of open / closed hand = 1/3 octave = 4 half steps (and even this feels rather cramped now and then).  Unfortunately, and perhaps surprisingly, there isn't much you can do to change the basic sensitivity of the analog Theremin, it's largely set in stone by the physics.  It's my belief (IMO!) that this basic sensitivity is just too high for easy playing, and that this alone could very well be the reason why the Theremin never really took off in the first place, and why it remains in relative obscurity.  And (IMO!) non-linearity is another nail in the analog Theremin coffin - yes, with a lot of time and practice pros can accommodate just about anything, but it's one more impediment to having the thing just sweep you off your feet.  (And, yes, most fretboards are logarithmic, but they are "evenly non-linear" and so won't squeal if you move your finger a few mm.)

[EDIT] I'm thinking of reversing the sense of Lin, so that it can be thought of as a mid field boost / cut.  Though this seems to run counter to the gain side effect the that control has.

[EDIT2] Couldn't stop myself, Lin sense is now reversed.  So change the sign of all the above Lin knob settings.

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