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

Posted: 7/7/2014 4:01:42 PM
dewster

From: Northern NJ, USA

Joined: 2/17/2012

Spent some time looking at CIC filters and I think I understand them better now.  Here is a good paper:

http://www.dspguru.net/sites/dspguru/files/cic.pdf

Equation 8 is the key, though it is clearer when explicitly expanded.  CIC I/O response is:

  1 + (z^-1) + (z^-2) + ... + (z^-(RM-1))

This is obviously a FIR filter with all coefficients =1, which is the definition of a boxcar or moving average filter with a rectangular window of width RM and a gain of RM.  When decimating with a CIC we can place the comb downstream of the decimation, which is quite convenient because it reduces the required comb delay by a factor of 1/R.  If M=1 and the comb is sampling every R samples, then what it is sampling is the last R input samples added together, which is the definition of an integrate and dump filter.

CIC makes sense in scenarios where the oversampling ratio is high and one needs to radically filter and decimate in order to get the sampling rate down to something more reasonable.  A cascade of 3 seems to be the norm to get a good cutoff slope.  Bit growth is an issue, particularly when cascading, though modulo math in the accumulators eases this.  And the decimation ratio takes the place of lots of M storage, which is really convenient, but if you don't want to decimate then you have to pony up the storage.

Anyway, I'm back to first order integrate and dump with power of 2 periods.  Though since interrupts shouldn't come in at more than a 1.5MHz rate I'm toying with the idea of putting an interrupt time stamp in the Hive register set, which could enable period timing with the interrupt mechanism alone, though it would pretty much tie up one thread.  (But first I'm off in an attempt to rearrange the Hive guts for full 32 bit memory access.)

I'm still kind of concerned about aliasing.  I don't believe I've really thought it out, particularly in the context of heterodyning.  To reduce the probability of it, one could take the LC oscillator output and LPF the phase with a PLL or DPLL before heterodyning.  Sampling and filter internal node truncation are huge cans of worms, analog filtering is a breeze compared to digital filtering.  Even something as trivial as the CIC, which boils down to almost nothing, just about breaks my brain.  (Though the CIC itself is a very clever arrangement.)

Posted: 7/7/2014 5:24:31 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

"analog filtering is a breeze compared to digital filtering.  Even something as trivial as the CIC, which boils down to almost nothing, just about breaks my brain." - Dewster

LOL ;-) - Thats the one thing in the above post which I can fully understand and fully agree with!

;-)

Posted: 7/15/2014 11:09:11 PM
dewster

From: Northern NJ, USA

Joined: 2/17/2012

More monkeying around with Hive:

http://www.mediafire.com/view/ghtn03wqe4a6k0z/Hive_Design_2014-07-15.pdf

http://www.mediafire.com/download/9iloxic8535cdt7/HIVE_SV_2014-07-13_v06.01.zip

The main change is full 32 bit memory reads / writes / literals.  I haven't updated the simulator yet.

===============

If time were more pressing (i.e. if I was smart) I would have used the tiniest FPGA available, done the minimum in there, and lashed it to a beaglebone black, hummingboard, or similar credit card sized ARM processor.  You could have a real screen, implement any kind synthesis, and dial up more delay / reverb then you could shake a stick at.  But it wouldn't feel as "embedded" to me, and there would likely be boring ass boot times to contend with.

Still debating whether to use LEDs or LCD for the data display.  Got a 2 line LCD with tri-color LED backlight from Adafruit but haven't hooked it up to anything.  LCDs are dogs to communicate with, but they are cheap and can show a reasonable amount of data.  It's too bad they don't seem to make calculator LED displays anymore, I'd probably go with that, though the multiplexed drive might drive the capacitance sensing crazy, and there is always the awkward alpha representation problem.  Am thinking of turning off any display electronics during play (except for the tuner which will likely NOT be multiplexed, but it will be PWM) for that reason.

Posted: 7/16/2014 12:41:46 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

Hi Dewster,

You can still buy individual and dual 7 segment and 14 segment (alphanumeric) LED's @ about $1 / per display (Dual displays are fractionally cheaper than singles, per seg) and you can get LED dot matrix.. They do work out a lot more expensive than LCD though.

The only theremin related product I used an LCD display on was "Epsilon" - it was in the early days when I knew even less about theremins than I do now ;-) and had low antenna voltage... It was a nightmare! - The LCD was the major source of trouble, orders of magnitude more noisy than anything else.

As you will know I abandoned that project and started my long descent into theremin hell - I think Epsilon set me on the path to pedantic research and design leading me nowhere slowly... But experiments before I gave up Epsilon indicated a big (proportional) improvement the higher the antenna voltage, and other improvements from shielding the LCD cables - I desperately tried synchronising the LCD to the reference or some division thereof, but it was a complete module (I destroyed one trying to hack its smd circuitry).

"Am thinking of turning off any display electronics during play (except for the tuner which will likely NOT be multiplexed, but it will be PWM) for that reason."

I think my problems were mostly down to ignorance and stupidity - a kind of reckless confidence that seems to inflict many newcomers to theremin technology - it all looks so easy... ;-) With the series LC configuration you are employing, and if you build in the option of having the data display inactive when playing, I think you may well get away with PWM'in the pitch display..... And if it causes problems, IMO, omitting this display would be no great loss... ;-)   - Sorry, its the only feature of your instrument who's value I doubt.

(I do wish I had thought about turning the display off when switching to "play" mode... Would have been a bit tricky - the display gave instructions to perform auto-calibration and low noise was required when doing this... but it could have turned off after issuing the instruction, then back on after acquiring the data, and then off when the user selected "play")

Fred.

Posted: 7/16/2014 10:38:52 PM
dewster

From: Northern NJ, USA

Joined: 2/17/2012

"You can still buy individual and dual 7 segment and 14 segment (alphanumeric) LED's @ about $1 / per display (Dual displays are fractionally cheaper than singles, per seg) and you can get LED dot matrix.. They do work out a lot more expensive than LCD though."  - FredM

Thanks!  Yes, I see them at Mouser and other places.  Brightness is quite high for some of them.  Might be able to get by with 2 lines of 8 chars, or a single line of 16.  8 chars is 32 bits hex, the largest I expect any value to be.  Could have one line of 14 segment and one line of 7 segment if, for example, the top line is the identifier of the value and the bottom the hex value.

I suppose the LCD could be completely powered down to disable it if necessary.  Gave mine 3.3V today and snooped around very briefly with a scope lead, but didn't see anything in the way of emissions.  Perhaps I need to initialize it to see emissions?  Other than what it's doing on its own, the LCD can be a fairly static thing, with no active data or clock going to it when no change is required.  I don't think it will be terribly visible through a slab of red frosted plexiglas though (thinking of going red clear).

I wish the FPGA demo board had a better physical design for the on-board voltage regulators, I could power gobs of LEDs directly from all the spare pins.  As it is the regulators get kind of hot.  I could clip the leads and mount new ones off-board but that would be kind of fiddly. 

One thing that occurred to me was the use of day-glo orange or other similarly tinted plexiglas, with UV LEDs underneath for the tuner - that might look pretty snappy!

Posted: 7/16/2014 11:53:45 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

"One thing that occurred to me was the use of day-glo orange or other similarly tinted plexiglas, with UV LEDs underneath for the tuner - that might look pretty snappy!" - Dewster

Depends on whether you want the LEDs to blur into each other or not - You certainly dont get sharp florescence, also, you lose a lot of the energy through the process - it is worth trying though.

I did an evaluation on an idea (pending patent) once where the inventor wanted two 'de-tuned' LEDs to illuminate a special translucent graduated (phosphorescent) filter - The idea was a simple analogue "bargraph" type display using just 2 leds who's brightnesses were inversely adjusted.  ... Sadly it didn't work (the theory was so fatally flawed it should have been rejected at the first "crazy ideas" phase) - but it was one of those fun jobs which I actually got money for ;-)

Fred.

Posted: 7/23/2014 12:13:46 AM
dewster

From: Northern NJ, USA

Joined: 2/17/2012

Trivial first order integer low pass digital IIR filter with fixed cutoff:

http://www.mediafire.com/download/jq6n9u00brzjvn6/trivial_lpf_2014-07-21.xls

Multiplication is single right shift (divide by 2) and it employs a single adder.  I/O gain is 1.  The form was found by taking the LPF form and setting the attenuation to 1/2, which allowed the replacement of the add and subtract with a single add.

Fcutoff should be Fsample/(4*pi).  In reality, Fcutoff is quite a bit higher than this at ~Fsample/8.716 which was determined via graphical means (I was unable to find a simple mathematical expression / justification). 

Maximum attenuation at Fsample/2 is around -9.5 dB.

Since it uses only a single add, a single register, and no multiplication, this filter can be quite inexpensively placed anywhere some rough and ready LPF action is desired (provided the fixed cutoff point is acceptable) and should run at high speed.  Cascade 2 for more filtering!

Posted: 7/28/2014 2:27:23 PM
dewster

From: Northern NJ, USA

Joined: 2/17/2012

Was laying in bed this morning thinking about pitch quantization / correction.  If you want a "hardness" control ala the Theremini, you need to be able to morph between smooth pitch and hard pitch changes.  This means the fully quantized notes will necessarily have bins, or plateaus of constant pitch, which vary in width according to the distances to the adjacent quantized notes.  One could also have "one size fits all" bins or plateau widths, and assign each quantized note to a bin, but that would preclude a continuous morph, and might be kind of confusing as it would oddly scrunch up the playing field in places where the note intervals are larger than half steps.

Another issue is vibrato.  It would be nice to have it available for even fully quantize pitch settings.  At minimum I imagine this might be doable via high pass and low pass filtering of the pitch number.  Send the low pass to the quantizer, and let the high pass influence the pitch somewhat in an AC kind of way.  This might help minimize abrupt pitch change when all you really want is some vibrato on a single note.  A peaky highpass or bandpass with the peak set to 5Hz or so for the vibrato channel might work better at interpreting the intent of the user.

This kind of stuff is a lot easier if you go the log2 / exp2 route with the pitch number: 

Heterodyne => filter => threshold & measure period => variable filter & downsample if necessary => fixed filter & offset & downsample=> log2 => * => LED tuner => exp2 => NCO

* a miracle occurs here.

Posted: 7/28/2014 8:58:33 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

"Send the low pass to the quantizer, and let the high pass influence the pitch somewhat in an AC kind of way... " - Dewster

That could be a really neat and clever solution! All sorts of other ways to exploit this kind of idea spring to mind as well.. From the HP one should (?) be able to determine rate of change, so perhaps allow gliding between source and target intervals in a natural manner when the change is rapid.. as the player gets to the target area, they will slow down their movement, reducing the HP output and passing greater control to the quantizer..

To me, the thing which makes pitch quantization (as implemented on the theremini) so horrible is the "emphasis" of "unwanted" intervals between the source and target intervals - these 'blips', to me, make any and every performance (be this the theremini, or a swept synth fed to a CV quantizer, or my own OKE system) using pitch correction / quantizing unbearable, regardless of the degree to which the correction is applied (although IMO, "Stronger" = "worse").

I had seen no way to overcome this on an instrument like the theremin - But I think your idea may hold the answer! - Pitch correction only "kicking in" when the rate of change was low, and only starting to act below some threshold, and perhaps increasing to maximum only when there was no rate of change (hand was stationary or only slight 'slow' movement).

This would (?) allow a player with only moderate pitch 'awareness' to play in tune without losing (?) much of  the theremins expressive ability, and without suffering intermediate 'blips' as they go over 'legal' intervals to get to the area of the interval they are trying to play.. Even if they "settle" on an interval 25 cents off target, as soon as their hand stops moving (and as the movement decreases) the quantizer will pull to the correct pitch (provided the player is closer to this pitch than to any other 'legal' pitch).

I fear that even suggesting the above will make me hugely unpopular with many who have sweated blood to master precision theremin pitch control - There was never any danger to them IMO from the theremini or other pitch correcting toys - But if possible and ever implemented, perhaps the above might pose a "threat" ... I do think however that players who can manually play in tune and hear pitch accurately for themselves will always be the only ones capable of extracting the best from the instrument, as this ability is required for deliberately adding musical expression through vibrato and other fine accentuation's that people without that ability could never achieve.

And whatever "thresholds" one sets, one is adding constraints that just aren't there on a "real" theremin - Any kind of automated real-time control is, IMO, "trimming the wings" of the theremin "bird" to make it more controllable by those who cannot tame this bird.. But there is probably a bigger market for "impaired"  tame birds than for wild ones the owner needs to tame.. And a lot of people who would get more pleasure from a tamed theremin than they could get from a wild one.. OK, as long as these people dont post their "Greatest theremin performance ever" videos to you tube! ;-)

Fred.

Posted: 7/28/2014 10:11:17 PM
dewster

From: Northern NJ, USA

Joined: 2/17/2012

Fred, I wasn't thinking of doing pitch correction in a dynamic way (I was thinking more along the lines of the simple morphing / bias method of the Theremini, but with some added allowance for vibrato) but slow-ish locking is a very good idea.  I bet a lot of this stuff has been worked out previously and finessed in vocal pitch corrector products.  The big advantage one has in a digital Theremin is the pitch number is just sitting there and you can do anything you like with it.

I feel like you do that (unless it is used as a special effect) the bad thing about pitch correction is the loss of smooth glissando.

==========

Looking at Chamberlain's book today I see he has a corrected tuning equation for his first order low pass digital filter:

  k = 1-e^(-2*pi*Fc/Fs)

or

  Fc = -Fs*ln(1-k)/(2*pi)

so for my trivial LPF where k = 1/2:

  Fc/Fs ~= 0.1103178 ~= 1 / 9.0647

Chamberlain doesn't present this as an approximation but likely is because graphically I get ~1/8.7153.  Not a huge deal but I'm a little surprised.  I suppose no one really cares where the 3dB down point is exactly for a first order filter.  You would notice deviation from the ideal tuning more for, say, a second order bandpass filter with high Q.

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