i think i built a frequency shifter

Started by jaapie, December 10, 2013, 11:57:33 PM

Previous topic - Next topic

jaapie

i've had an intellectual fascination with ring modulators and frequency shifters for a while now-- i just think it's really cool that i can basically apply some boring identities that i learned in trig and calculus to sound waves in real time. plus it sounds cool. anyway, i fell down a thought-hole a few months ago while reading about XOR gates used as ring modulators (as in some korg synths) wondering if i could somehow cheat an XOR gate into working as a multiplier for analog signals. This is the result of the past few months of pondering on my daily 90 minute commute.

I'll spare everyone the convoluted thought processes that eventually led me here, so please ask questions if i'm not being clear or if i forget something. I'm sure this sort of thing is pretty textbook, but I'm relatively new to these things. Here's a simplified block diagram of the circuit on my breadboard right now:



The guitar is beefed up a little by a preamp and then run through a simple dome filter using 4 opamps. I calculated the values for the filter using a program i found online intended for SSB radio designs; 4 opamps seemed like the fewest possible to still get close to 90 degrees across the guitar spectrum (or up to 1.5kHz or so, i can't remember exactly). The sine and cosine signals are then each sent to the input of their own switch-hitter. The non-inverting inputs are either grounded or left floating by 1/4 of a CD4066, controlling whether the signal is inverted or not. Together, they act as pulse-width controlled multipliers.
I've got MSP430 microcontroller programmed to generate a PWM'd quadrature sine wave oscillator.This part probably needs the most work because i've got almost no programming experience with anything lower-level than an arduino; I managed to squeeze a quadrature oscillator out of it but it's pretty far from ideal.

To understand how the PWM signal and switch-hitters act like a multiplier, it helps to "zoom in" to one cycle of the PWM frequency. if the frequency is high enough, we can pretend the audio signal is DC since it's changing so much more slowly. As a result, if the duty cycle is 50% the output is in phase for half of the cycle and inverted for the other half and cancel each other out (mostly) in the following lowpass filter. As the duty cycle increases, the output is gradually inverted for more and more of each cycle until at 100% it is always inverted. The process works similarly as the duty cycle falls from 50% to 0% and the output is in-phase for a longer time each cycle. This is basically (to my understanding, at least) a balanced modulator of sorts, multiplying a voltage by the duty cycle (sort of).

It's getting late and my brain is getting tired-- that's about the best explanation i can give tonight. I'll try and record some sound clips tomorrow and post them with a real schematic and better explanation.

knutolai

Impressive stuff! I love ring modulators and SSB modulators. Could you share some resources on dome filters? I couldn't find any good resources that displayed simple schems through google. Would love to see your schem!

QuoteThe non-inverting inputs are either grounded or left floating by 1/4 of a CD4066, controlling whether the signal is inverted or not.
The switches of a CD4066 are either open or closed, no? Doesn't using these switches defeat the purpose of using a sinewave modulator, or is there some use of this chip I'm unfamiliar with?

The way I have understood it this is what makes sinewave ring modulation so complicated as you would need OTAs, transformers or expensive Analog Devices chips to achieve it.

noisette

#2
Hi!
I´m also really interested in this, though I can´t help much with it, since I´m already over a couple of different stuff.
Here´s a link to Ken Stone about Dome Filters, he redirects to J.Haible´s Design (link in there) and also mentions Electronotes.
http://www.cgs.synth.net/modules/cgs45_domefilter.html
Since I own all the EN stuff I could look up the dome filter articles and send them to people personally contacting me, demanding
they would not be put online...  :(  :)

To OP: There´s also a fairly simple quadrature sine oscillator by Ian Fritz based on OTA´s, but I don´t know if it is what you need?
I build it once on breadboard and got very clean sine signals...
http://electro-music.com/forum/viewtopic.php?highlight=quadrature&t=19841

Anyway, nice work, looking forward to schematics ;D
"Those who believe in telekinetics, raise my hand."
― Kurt Vonnegut

noisette

"Those who believe in telekinetics, raise my hand."
― Kurt Vonnegut

amptramp

The ring modulators aren't the difficult part, but the audio phase shifters that can handle a broadband audio signal and achieve a 90° phase shift across the whole band are.  Here is a page that will give you a number of implementations:

http://michaelgellis.tripod.com/mixerscom.html

including the Weaver method of getting around imperfections in the phase shift filters.

The function of a ring modulator depends on the trig identities such as:

sin (a) * sin (b) = -0.5{cos (a+b) - cos (a-b))

There are double angle, half angle and triple angle formulas that can be used to design octave up, octave down and octave plus a third circuits.  I have never seen an octave down implemented by trig functions, so you may be able to blaze a new trail here.  I am looking forward to your full chord / arpeggiator stompbox!

jaapie

Quote from: knutolai on December 11, 2013, 09:54:08 AM
The switches of a CD4066 are either open or closed, no? Doesn't using these switches defeat the purpose of using a sinewave modulator, or is there some use of this chip I'm unfamiliar with?

Since the switches only take a binary input (on or off) i'm using pulse-width modulation to cheat it into working as a lo-fi modulator. With this method, one input takes an audio wave (guitar, square wave, ramp, oboe, whatever) and one input takes a high-frequency square wave as its input. The square wave is PWM'd by the modulator, so if you PWM the HF square with a sine wave the pulses will gradually go from 0% to 100% duty cycle and back at the rate of your sine wave. This PWM'd high frequency square wave controls the 4066.


Quote from: amptramp on December 11, 2013, 11:00:12 AM
The ring modulators aren't the difficult part, but the audio phase shifters that can handle a broadband audio signal and achieve a 90° phase shift across the whole band are.

the dome filter is the part that i understand the least; i know what it does and why (on a VERY basic level) and i know i need one for a frequency shifter. this is what i'm using right now: http://i.imgur.com/ici2wcI.jpg. I lowered the BW some because 20Hz-20kHz is overkill for guitar; i think i probably went for something like 80Hz-1.5kHz. On the breadboard it's definitely not perfect, but the lissajous is circular enough for me!

Quote from: noisette on December 11, 2013, 10:48:33 AM
There´s also a fairly simple quadrature sine oscillator by Ian Fritz based on OTA´s, but I don´t know if it is what you need?

I tried a bunch of different quadrature oscillators and couldn't get any of them to work, probably because they're usually designed for 12-15V and i'm trying to stick with 9V (because it makes things harder, i guess). At any rate, the neat thing about this design is that it actually requires a PWMd modulator, which is pretty simple to create with a microcontroller. I'm trying to keep the number of chips as low as possible (2 quad opamps, one 4066 and one MSP430 right now). I hadn't found that one, though, so thanks for showing it to me!


jaapie

Here's a quick and dirty sound clip:
https://soundcloud.com/jaapie/freqshift1

The first few seconds is just clean guitar for reference, then playing around with shifting up for a minute or two, followed by downshifting. The snap crackle pop is coming from the uC, i think; either a problem with programming the oscillator or just noise. I'm about to draw up a schematic, i'll post it when i'm done.

jaapie

#7
Here's a schematic of what's on my breadboard right now. Obviously this needs a lot of refining, but i was trying to cobble together the absolute minimum possible to test the idea.

http://i.imgur.com/0UasFSb.jpg


And here's the clumsy MSP430 code. I don't know if anyone here is familiar with the MSP430, but any suggestions would be more than welcome!
https://gist.github.com/jaapie666/7917281

knutolai

#8
QuoteHere's a quick and dirty sound clip:
https://soundcloud.com/jaapie/freqshift1

Sounds cool. What's the popping noise coming from? I mean the sound that kinda sounds like super fast drumming that appear from time to time :icon_mrgreen:

QuoteSince the switches only take a binary input (on or off) i'm using pulse-width modulation to cheat it into working as a lo-fi modulator. With this method, one input takes an audio wave (guitar, square wave, ramp, oboe, whatever) and one input takes a high-frequency square wave as its input. The square wave is PWM'd by the modulator, so if you PWM the HF square with a sine wave the pulses will gradually go from 0% to 100% duty cycle and back at the rate of your sine wave. This PWM'd high frequency square wave controls the 4066.

That's really really very cool and awsome! So with your setup the 4066 kinda becomes a PWM-controller resistor of sorts right? Whats the samplerate of your PWM signal and how fast can the 4066 flip on and off? I'm looking at the datasheet for it atm, but I'm quite horrible at making sense of datasheets.

jaapie

#9
The PWM is at about 62.5 kHz, high enough to be able to filter it away pretty easily. I think 4000-series CMOS chips will work up over 1MHz at 9v; at any rate they're more than fast enough for this application. I wonder if i could get away with just using BJTs or FETs instead?

I haven't been able to track down the source of the popping yet, but it has something to do with the microcontroller. It could be distortion in the sine wave caused by my rudimentary programming skills, although i didn't have as much pop when i was testing it by itself (not connected to all the other circuitry). The other possibility is that it's noise from the microcontroller or the launchpad board-- i've been powering it through the launchpad development board plugged into the usb port of my laptop. Ive read that computers can have pretty noisy power supplies, so I'm working on getting the chip onto my breadboard powered by a regulator. Unfortunately, I fried the only uC i have at the moment by connecting it to the 9v power rail by accident (the MSP430's maximum supply voltage is only 3.5v). I ordered some new ones but it'll be a couple of days before they get here.

Listening to the sample again, I think the downshifting isn't actually frequency shifting. I've been switching between down- and up-shifting by reversing the inputs to the 4066, and i think one of the wires was disconnected when i thought i was downshifting. It sounds much more vibrato-like than the upshifting sample does, and i don't remember hearing as much of a tremolo effect when i was playing with the downshift previous to recording the sample.  unfortunately i can't re-record until i get the new uCs, but at the same time i think the vibrato sounds pretty good!

knutolai

QuoteI wonder if i could get away with just using BJTs or FETs instead?
Wouldn't those color the sound? From what I understand the 4066 is way more transparent. Also its cheaper than FETs  :icon_wink:

Quotei'm using pulse-width modulation to cheat it into working as a lo-fi modulator.
QuoteThe PWM is at about 62.5 kHz, high enough to be able to filter it away pretty easily. I think 4000-series CMOS chips will work up over 1MHz at 9v;
How come you qualify this as a low-fi modulator? Is there much modulator/carrier bleedthrough, tone-loss, Noise from the 4066 switch flipping?

jaapie

In this case, the 4066's aren't being used directly in the signal path; they're just being used to control whether the opamp inverts or not. I don't have a lot of experience with this sort of thing, but from past experiments i seem to recall control bleed being the main drawback. Since the control frequency is so high (62.4kHz, about 3x higher than golden ears can hear) and we already have to filter it, my line of thinking is that a couple BJTs would be cheaper and take up less space than a CMOS IC. It might not work for other reasons that I can't anticipate due to lack of experience, but it's worth a try!

I keep qualifying it as "lo-fi" for a few reasons, mostly because I only have a basic understanding of what's going on here and there are probably many aspects that can be refined. I can see a decent amount of bleedthrough on the scope, but I think my oscillator's highest frequency is still too low to hear so it's not really apparent. The popping is also pretty lo-fi, but i'm more confident that I can solve that problem. Apparently noise and bleed are pretty common issues in circuits using modulators or multipliers no matter how you go about doing it.

knutolai

QuoteIn this case, the 4066's aren't being used directly in the signal path; they're just being used to control whether the opamp inverts or not.
Is that all the that happens at the last opamp stages? I know how differential amplifiers work, and the stage does look like one where the Resistor from the positive input to Vref is swapped with a variable resistor/PWMd switch/magic device, thus altering the gain of the non-inverting input. When there is switch connection the non-inverted signal gain would be 0 (full attenuation) and the opamp would exit a inverted signal. but when the switch is not connected, from looking at the math (http://www.electronics-tutorials.ws/opamp/opamp_5.html), woun't the opamp exit near silence? Sorry my electronics understanding has not yet been very well developed (thinking out loud helps I find  :icon_lol:). Keeping in mind you said its a lo-fi design, but I don't understand how this diff amp is able to exit a non-inverted signal  ??? ??? ???. Is the signal gain somehow equal for both switch states?

I threw together my own, slightly more component heavy, take on these Ring modulator/phase shifter stages:

Would this maybe give a more even result? The SPDT switches flips between setting the inverting and non-inverting input to Vref while the other input is fed with a incomming signal.

Mark Hammer


noisette

jaapie I think your sample´s sounding really good!

For entertainment check out this one:
http://youtu.be/1mtySbBiGxM
Very nice...
"Those who believe in telekinetics, raise my hand."
― Kurt Vonnegut

knutolai

QuoteThe PWM is at about 62.5 kHz, high enough to be able to filter it away pretty easily. I think 4000-series CMOS chips will work up over 1MHz at 9v;

I though of something that might be a issue with using such a gate. Say the gate can operate at a frequency of 1MHz. If the pwm waveform has a 8 bit resolution the pwm samplerate can't exceed 1MHz/256 = 3k9Hz, at least without some form of distortion happening to the waveform. I cant really make sense of the 4066 datasheet so it might not be an issue

slacker

Quote from: knutolai on December 12, 2013, 07:17:35 PM
Is that all the that happens at the last opamp stages? I know how differential amplifiers work, and the stage does look like one where the Resistor from the positive input to Vref is swapped with a variable resistor/PWMd switch/magic device, thus altering the gain of the non-inverting input. When there is switch connection the non-inverted signal gain would be 0 (full attenuation) and the opamp would exit a inverted signal. but when the switch is not connected, from looking at the math (http://www.electronics-tutorials.ws/opamp/opamp_5.html), woun't the opamp exit near silence?

Using the picture in your link as an example, with R1, R2 and R3 as equal value resistors and R4 as the the switch. When the switch is open, it's as though R4 is not in the circuit, the gain for signals at the non inverting input is then 2 1+(R3/R1) and the gain for signals at the inverting input is -1 -(R3/R1) so the total gain is 1 (2-1), so it just acts like a non inverting buffer.
If all 4 resistors were equal value then you would get no output, because then the signal into the non inverting input would be halved by the voltage divider R2/R4 and then multiplied by 2 1+(R3/R1) to give 1 which is cancelled out by the -1 from the inverting side.

This is some nice work jaapie it sounds really good, hope you can figure out the noise issue.