Shop OBEX P1 Docs P2 Docs Learn Events
Prop Amplitude Modulation — Parallax Forums

Prop Amplitude Modulation

WNedWNed Posts: 157
edited 2009-05-01 00:37 in Propeller 1
Hello,
I'd like to try to recreate an accurate vibraphone sound, and thought of using one cog to modulate the tone output of another cog.
Cog0 generates a tone on Pin0, which goes to the base of a transistor. Cog1 generates a varying PWM output to Pin1 connected to the collector of the transistor. The result should be an amplitude modulated tone to a load (speaker) between the collector and emitter.
Question 1: Is that theory correct?
Question 2: Is there a better / simpler way to accomplish this?
Question 3: If this is a good way to go about it, what would be a good transistor for this type of circuit? (I know how transistors work, but never got the hang of how to select the right one)

Thanks,
Ned

▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
"They may have computers, and other weapons of mass destruction." - Janet Reno

Comments

  • Mike GreenMike Green Posts: 23,101
    edited 2009-04-29 16:51
    Basically you want to multiply the output voltage of one frequency synthesizer by the output voltage of another frequency synthesizer. Look at the Wikipedia article on analog multipliers (en.wikipedia.org/wiki/Analog_multiplier) and the links at the bottom of the page. Your scheme would "work", but not produce a very good tone.

    You could also do all the synthesis including the multiplication digitally and output PWM to an audio amplifier. The Demo Board's schematic includes a PWM output circuit with a headphone amplifier included. In assembly language, a 16 bit multiply takes about 2.5us, more than fast enough for a high quality vibraphone synthesis.
  • WNedWNed Posts: 157
    edited 2009-04-29 17:19
    Thanks Mike!
    I've got a demo board and will start picking away at the various PWM objects available for code examples.

    Ned

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    "They may have computers, and other weapons of mass destruction." - Janet Reno
  • Mike GreenMike Green Posts: 23,101
    edited 2009-04-29 17:34
    You will be able to do some experimenting using Spin and low frequency signals (like under 1KHz), but you'll have to switch to assembly to handle higher frequencies. There have been some examples using the built-in ROM sine table for synthesizing sine waves. I don't have the links handy, but maybe someone else has them or you might be able to find them with a search.
  • WNedWNed Posts: 157
    edited 2009-04-29 18:02
    Mike,
    Raymond Allen's ToneGen is sine wave generator in spin that uses the ROM table. The output from that is pretty decent in that the tones have a pretty smooth sound even in headphones. I've got Beau Schwabe's Freq Synthesis object I'll have to look into because Allen's ToneGen only goes down to 8hz, which is too fast for vibe modulation. Then I'll learn about signal multiplication in software!
    Mike, me boy, you're regular pillar of the community!


    Added: Oops, Beau's object creates square waves. No go on that idea.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    "They may have computers, and other weapons of mass destruction." - Janet Reno

    Post Edited (WNed) : 4/29/2009 6:32:25 PM GMT
  • Beau SchwabeBeau Schwabe Posts: 6,568
    edited 2009-04-30 05:12
    WNed,

    If you generate two PWM signals that have the same exact frequency and you only adjust the phase of one of the signals, you effectively can control the amplitude modulation of the signal. At 0 Phase difference, the amplitude is the greatest, at 180 Phase difference, the amplitude is the least.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Beau Schwabe

    IC Layout Engineer
    Parallax, Inc.
  • Carl HayesCarl Hayes Posts: 841
    edited 2009-04-30 06:31
    Beau Schwabe (Parallax) said...
    WNed,

    If you generate two PWM signals that have the same exact frequency and you only adjust the phase of one of the signals, you effectively can control the amplitude modulation of the signal. At 0 Phase difference, the amplitude is the greatest, at 180 Phase difference, the amplitude is the least.
    A most creative solution!· They can't be the same exact frequency, though, because if you adjust the phase of one, its frequency must change while you're moving the phase.

    Assuming they're mutually coherent, and the PWM signals are perfectly rectangular, the output amplitude will be maximum when the pulses coincide, and zero when they don't overlap·-- which may occur with only a very small phase (time) difference, depending upon the pulse widths.· It sounds kind of hard to control.

    In sum, I think I like WNed's original proposal better -- modulated signal on the base, and modulating signal as PWM on the collector supply.· I don't like his coupling method to the speaker, though.· Instead I'd use a resistor in series with the collector, chosen to give a load line in the linear region of the transistor's curves; and a small resistor in series eith the emitter to improve both linearity and stability.· Take the output signal off the collector through a capacitor, feeding a low-pass amplifier of some kind (to get rid of the PWM pulses)·which eventually feeds a speaker.· I might even use an LMF100 for the low-pass function, although really an RC would likely be good enough.· I just kind of like LMF100s, and I have a lot of LMF100s in my junk box.· They make stunningly good audio filters.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    · -- Carl, nn5i@arrl.net
  • Carl HayesCarl Hayes Posts: 841
    edited 2009-04-30 06:37
    Considering it a little more, if one used Beau's solution of two PWM signals, but with one generating a sine wave for the modulated signal, and another generating a sine wave at the (much lower) modulating frequency (not the same frequency as Beau proposd), I think it would work just fine -- and you could bag the transistor amplifier and use an AND gate instead.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    · -- Carl, nn5i@arrl.net
  • Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
    edited 2009-04-30 07:57
    Carl, I think you're on to something.

    If you look at the DUTY mode output from two counters, A and B, as independent random variables, such that the probability at any point in time of the output from x being high is P(x) = FRQx / 232, then the probability of both being high at once, P(A & B), is P(A) * P(B) which is proportional to FRQA * FRQB.

    Of course the outputs are neither random nor independent, but as long as FRQA and FRQB are relatively prime, they should act as if they are and provide a plausible simulation of a modulation product. (Addendum: But if both are constantly in flux, as they would be with two sine waves, this point is likely moot.)

    But I have to agree with Mike, in that there's ample time to do the multiplication in software, obviating the need for external hardware, save a lowpass filter for the DUTY doody.

    -Phil

    Post Edited (Phil Pilgrim (PhiPi)) : 4/30/2009 8:08:57 AM GMT
  • virtuPICvirtuPIC Posts: 193
    edited 2009-04-30 08:45
    Beau said...
    If you generate two PWM signals that have the same exact frequency and you only adjust the phase of one of the signals, you effectively can control the amplitude modulation of the signal. At 0 Phase difference, the amplitude is the greatest, at 180 Phase difference, the amplitude is the least.

    Yes, and what happens if the frequencies are a little different? You have something like two signals with the same frequency and linearly changing phase difference. Remember trigonometry: Generate two signals, one a little lower than the one to produce, the other one the same little higher, and get the desired frequency with an amplitude modulation of abs(sin(t)) and a phase modulation of 180° * sign(sin(t))! Your ear won't notice the phase modulation but the amplitude modulation.

    Okay, I don't know if you really want this modulation signal. Give it a try. It looks rather simple.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Airspace V - international hangar flying!
    www.airspace-v.com/ggadgets for tools & toys
  • Brian FairchildBrian Fairchild Posts: 549
    edited 2009-04-30 08:55
    I know real paper books are terribly unfashionable these days but for anyone interested in music synthesis I'd heartily recommend...

    Musical Applications of Microprocessors by Hal Chamberlin

    http://www.amazon.com/Musical-Applications-Microprocessors-Hal-Chamberlin/dp/0810457687/ref=ed_oe_h

    ...it's been out of print for years but if you can pick up a copy second-hand it would be an invaluable read.
  • Beau SchwabeBeau Schwabe Posts: 6,568
    edited 2009-04-30 15:14
    The two PWM frequencies should be the same.... if you change the phase relationship between the two exact frequencies you can modulate the combined amplitude. If the frequencies are different you get a beat note along with summing and difference frequencies and you don't want that. On the other hand if both frequencies are the same and in the same phase relation with one another, you have an accumulative amplitude. If the phase difference of one frequency is 180 from the other frequency, then they cancel each other out, and the amplitude is at its lowest.

    Check out the attached animated illustration.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Beau Schwabe

    IC Layout Engineer
    Parallax, Inc.

    Post Edited (Beau Schwabe (Parallax)) : 4/30/2009 3:55:43 PM GMT
    Sine.zip 577.6K
  • Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
    edited 2009-04-30 17:16
    Pursuant further to Carl's observation regarding ANDing two signals, you could also OR them to get the same effect if you invert the modulating (envelope) signal. This would allow two counters to output on the same pin, where they're ORed by the Propeller hardware. No externals needed!

    -Phil
  • lonesocklonesock Posts: 917
    edited 2009-04-30 17:28
    It occurs to me that if the ToneGen code already uses the sine table as provided in the prop ROM, you could simply perform the "modulation as a function of phase" inside the generator by grabbing 2 samples from the Sine table: the sample you were originally grabbing, and one N samples behind* and perform the subtraction. N=4096 would be 180 degrees out of phase, yielding an amplitude of 2x the original. N=0 would yield 0x. The frequency of the tone is unimportant since we are sampling from a fixed size table.

    Jonathan

    * this is (of course) complicated by the fact that the sine table is only 2048 samples covering 90 degrees, so the actual "lookup" requires the whatever cool wrapping and mirroring tricks you have to do to actually recover a sample from a full 360 degree sine wave.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    lonesock
    Piranha are people too.
  • WNedWNed Posts: 157
    edited 2009-04-30 17:42
    @PhiPi - BINGO!

    If you load ToneGen and edit it to send two signals to one pin, by playing with all the available parameters, you can achieve some fantastic sound effects (none of them sound like a vibraphone). But if you try to do wave summing that way, well... you can do 1+1, in phase, but as soon as you try to shift one of the tones, you start getting interference patterns rather than a modulated tone, so you need a way to filter those out. I think Phil's OR idea deals with that.

    @Jonathan - That's probably the easiest way to allow for dynamic modulation, rather than trying to shorten or lengthen the signal for one cycle.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    "They may have computers, and other weapons of mass destruction." - Janet Reno

    Post Edited (WNed) : 4/30/2009 5:52:26 PM GMT
  • Beau SchwabeBeau Schwabe Posts: 6,568
    edited 2009-04-30 18:19
    WNed,

    For reasons you mention, I would not try to directly combine the two PWM's.· Instead, use a simple RC filter to turn the PWM into a pseudo-sine wave.· Do this for·both PWM signals, and then use a Summing Amplifier to combine the sine waves together.

    http://hyperphysics.phy-astr.gsu.edu/HBASE/electronic/opampvar5.html


    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Beau Schwabe

    IC Layout Engineer
    Parallax, Inc.
  • WNedWNed Posts: 157
    edited 2009-05-01 00:37
    So, you think I should use two signals out, and mix them using hardware? Hmmmm... vaguely familiar.
    smilewinkgrin.gif

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    "They may have computers, and other weapons of mass destruction." - Janet Reno
Sign In or Register to comment.