Wednesday, 15 May 2013

Algorithms of the street - Part 2: Amplitude Modulation

So, I've already shown you Frequency Modulation (FM) in pure data, it's an algorithm, or recipe for Pure Data, meaning you can use it in other contexts, change some parameters to vary your sound and if you're really lucky, reading Algorithms of the Street - Part 1: Frequency Modulation will have told you exactly what FM is.

Given that you might well have read that post by now (if not, I would recommend you do) you'll have noticed that there's some similarity between the title of that post and this one. The fact that there's only one word and one number different, perhaps?

As the name suggests, Amplitude Modulation is a lot like Frequency Modulation. Only instead of modulating (changing, in a regular way) the pitch, or frequency of our tone, it modulates the volume (amplitude).

If you've read the FM tutorial, some of this will sound quite familiar. If you're feeling confident you could always skip to the end of this one and see if you can see the difference in the patch.

Step 1: No Modulation Yet

Once again, I've used a version of the generative patch from Pure Data and BACON (Part 2) as a starting point. Clicking the toggle at the top there will start a random stream of numbers, converting to frequencies and creating a random, continuous melody. But the tone being used is fairly dull, a simple sine-wave. It's hard to listen to for a long time, and we can take a lot more control of this tone.

Step 2: Modulate the amplitude

First, notice that I added a frequency within the oscillator box, and cut the wire connecting it to our random melody generator. Secondly you'll notice that I've added another audio multitiply (*~) and a second oscillator, which is only working at one hertz, a single cycle every second.

Your ears will be telling you, at this stage, that the sound is fading in and out with a regular pattern, on the same note. This is the simplest form of AM, with an oscillator going very slowly (a Low Frequency Oscillator or LFO) and no extra control.

So what's going on here? Let's look at some 'known facts' I've mentioned in earlier blog posts:

  • Digital audio is a high-speed stream of numbers which are converted to control signals for a speaker or speakers
  • These numbers range from 1 to -1
  • An oscillator in Pd outputs this same range, 1 to -1
  • Because they're numbers, they follow the same multiplication rules as numbers:
    • If you multiply it by 1, it is unchanged
    • If you multiply it by 0, the result is 0
  • Sine waves (which are also the output of osc~), plotted on a graph, are this shape.

We're multiplying a tone (called the carrier) by a much slower tone, which is changing it in some way, and so is called the modulator. So the volume starts at 0, silent, increases, arcs through it's maximum value, then back down below zero? 

Once again, we can rely on the multiplication rules from the world of maths here. If you multiply a number by -1, the result is the same, but on the other side of zero. So what we're actually doing here is turning our sine wave upside down, then producing the same volume arc as before. Although we can't tell the difference because it's shape is unchanged, we just hear the a repeated volume arc.

So effectively, the amplitude modulation we're hearing is more this shape:

Also, because we're hearing both the up and down parts of the modulating sine wave as an increase in volume, we're hearing this pattern twice a second, instead of once. 

Step 3: Bringing it up to speed

Phew, that was easy.

Okay, so we've increased the frequency of our modulator to half that of the tone itself. We're hearing a thicker, more interesting sound. But why?

Well, as I discussed in Pure Data and BACON (Part 1), the human ear can only recognise around 30 separate sounds in each second. When sounds are more regular than that (have a higher frequency), we hear a continuous sound instead of separate events. So our modulation is now part of a complex tone, instead of making the volume lurch, you can't hear the process as it happens, only that the tone sounds different. 

So... With this algorithm in place, we can just add our melody generator back in, right?

Step 4: The Fly in the Ointment

It seems such a simple idea, we add melody to a tone generator, and we get a melody produced in that tone. 

Our ears, however, tell us that it's not at all like a clear melody. Just like this step in my Frequency Modulation tutorial, we've exposed a weakness in our modulation algorithm. The frequency of the carrier changes but the modulation frequency (literally, the frequency of our modulating oscillator) doesn't.

Unlike FM, however, there's an additional problem. Once again, the world of maths tells us that multiplication can be changed around and the result doesn't change (2 x 4 is exactly the same as 4 x 2, and so forth). Because of this, it's not at all clear in our algorithm which is the carrier and which is the modulator, they act on each other in exactly the same way.

So the rather unpleasant sound we're hearing now is two tones competing with each other to become the note you're actually hearing, and they clash. 

There is a solution, however...

Step 5: Control the depth and use a proportion

Okay, the first thing you'll probably have noticed here does nothing to the sound. I've added a couple of comments (ctrl + 5), to tell you which oscillator is the modulator, and which is the carrier. These literally do nothing at all except say something on-screen. Don't believe me? Right-click on one and check it's help patch.

More importantly, I've added another multiply below the modulator, which means it will only change it's volume from 0.5 to -0.5, having half the effect (which we call the modulation depth). Also (as a side-effect) reducing the volume of our sound by half. 

The most important thing here, however, is the multiply above the modulator. This means that whatever frequency of the carrier, the modulator will be at half of that. They are changing frequency in synchrony, so you can hear what is effectively one tone, changing it's pitch, as opposed to two warring frequencies. 

This will produce something like an organ tone, this specific ratio reminds me of the music from the classic game, columns. Happy memories.

We can vary the tone it'self by changing the modulation frequency and depth, just as we did in the FM tutorial. However, before we start playing around, there's a problem we must take care of...

The modulation depth typically just controls how much effect the modulator is having, but here it's also vastly changing the volume of the resulting tone. The best way to do this is by adding an offset to keep the modulating tone from crossing zero.

Step 6: An offset to solve the depth issue

Again, the most noticeable thing here is not what I'm trying to show you, I've changed out the numbers in the multiplies above and below the modulator. These are set to range from 0 to 1 and control the modulation frequency and depth, respectively.

Below the lower of those, however, I'v done something unusual. Two pieces of fixed arithmetic on our modulator frequency. So:

  • Adding 1 (with +~) changes the range from 0 to 2
  • Multiplying by a half changes it to 0 to 1
This means that while changing the depth will affect your volume, a depth of 0 does not mean a volume of 0. It means a volume of 0.5, and a depth of 1 means a changing volume that centres around 0.5. This also means that we no longer have the arcing waveform of earlier. The graph of our modulation volume now looks like this:

Notice how it's all above that centre point (zero). 

Step 7: Two things to control? Use a grid

The first thing you'll notice here, is that I've added a grid (to create your own make an object (ctrl + 1) and type the word 'grid' into it), I've also set the properties like so (to get to the properties dialogue, right click and select properties).

I made it big with the Height and Width fields, then set the range of both axes to 0 to 1 with a small step size. 

I've then taken the output of the grid to two sends, mod_frequency and mod_depth, and replaced the two sliders with the corresponding receives. 

Hey presto, we're generating a melody and changing the sound of an AM tone generator with a dot on a grid. 

Secret extra step: shhh, don't tell

Okay, so there's tutorials for both AM and FM synthesis here on the blog and I've stressed that these are re-usable algorithms, and once you understand them you can swap them out for oscillators in other places. The inquisitive mind is now probably thinking "does that mean I can make a synthesizer with both frequency modulation and amplitude modulation?" 

Of course you can, if you've read both posts you'll know all the parts of this, so I'll just whip up an AM/FM synth patch...

Well, there you have it, I've assumed an FM modulation depth of 0.5 and an AM depth of 1 (you don't need any objects to multiply by 1, I removed that one entirely). 

You can probably work out what each part of this is doing, so you can now have a play with the grid, as in both individual cases, when the frequency is low, you get a thick, heavy kind of sound, and when it's high it's richer, more bell-like. But this effect is compounded by two modulation frequencies. 

Near the bottom left of the grid, when both are low the sound can be heavy, and you may even hear a regular rhythm in the modulation in the bottom left square. To the top right it's more rich and complex than you will have heard so far in this series of tutorials. 

It's starting to get more complex now, and I promise I will eventually get around to blogging about hiding bits of Pure Data patch away so you can concentrate elsewhere, but for now, everything's on show. 

Well, that's it for now. I hope this all made a reasonable amount of sense and enlightened you a little about Amplitude Modulation. 

Did you find this tutorial helpful? Get stuck anywhere? Don't know what on earth I'm blathering on about? Feel free to comment here or get in touch with me direct at @MarmiteJunction

 Thanks for reading, God bless.


  1. Thank you a lot for providing individuals with a very spectacular possibility to read critical reviews from this site.

    big data training in chennai

  2. Awesome post. Really you are shared very informative concept... Thank you for sharing. Keep on updating...

    Article submission sites
    Guest posting sites

  3. The blog which you are shared is very much helpful for us to knew about the web designing. thanks for your information.
    Web Designing Institute
    Best Web Design Courses
    Web Design Training Courses
    Learn Website Design
    Best Way to Learn Web Design

  4. Awwsome informative blog ,Very good information thanks for sharing such wonderful blog with us ,after long time came across such knowlegeble blog. keep sharing such informative blog with us.
    Airport Ground Staff Training Courses in Chennai | Airport Ground Staff Training in Chennai | Ground Staff Training in Chennai

  5. I am obliged to you for sharing this piece of information here and updating us with your resourceful guidance. Hope this might benefit many learners. Keep sharing this gainful articles and continue updating us.
    RPA Training in Chennai
    Robotics Process Automation Training in Chennai
    RPA courses in Chennai
    Robotic Process Automation Training
    RPA course

  6. Hi, Your post is quite great to view and easy way to grab the extra knowledge. Thank you for your share with us. I like to visit your site again for my future reference.
    Java Training in Chennai
    PHP Training in Chennai
    Core Java Training in Chennai
    Java Training center in Chennai
    PHP Training
    Best PHP training in chennai

  7. You have provided a nice article, Thank you very much for this one. And I hope this will be useful for many people. And I am waiting for your next post keep on updating these kinds of knowledgeable things
    Selenium training in chennai
    Selenium training institute in Chennai
    iOS Course Chennai
    Digital Marketing Training in Chennai
    hp loadrunner training
    Loadrunner Training in Velachery

  8. This information is impressive. I am inspired with your post writing style & how continuously you describe this topic. Eagerly waiting for your new blog keep doing more.
    ccna Course in Bangalor
    ccna Training in Bangalore
    Best ccna Institute in Bangalore
    ccna Institute in Bangalore
    ccna Training Institute in Bangalore

  9. Do not pass by, go to the online casino and try your luck best casino slot Do you like to play online casino? Then come to us and win like the last day.

  10. Когда человек задает вопрос где купить лед ленту я всегда отвечаю в ekodio, супер качество и супер цены.

  11. تنتج أفضل شركة تنظيف في شقق الدمام مستوى رائع وقوي ومحترف مع أقوى الخدمات والخصومات على مدار العام لجميع عملائنا للتخلص من الأوساخ والتربة معنا
    شركة النجوم لخدمات التنظيف
    شركة تنظيف خزانات بالرياض
    شركة تنظيف بالرياض
    شركة تنظيف شقق بالرياض

  12. This information really amazing thanks for share this article thank you..

    tamilrockers malayalam

  13. السلام عليكم ورحمه الله وبركاته عملائنا الاعزاء كلنا نعرف اهميه المسابح فى حياتنا خاصه فى فصل الصيف بسبب ارتفاع درجات الحراره
    شركة الصفرات لتنظيف المسابح بالرياض
    ومن ثم يجب علينا الاعتناء بنظافه المسبح والحفاظ على حيويه المياه بداخله من اجل الحفاظ على صحتنا وصحه اطفالنا علينا ايضا ان نعرف ونتسأل ما سبب تلوث مياه المسبح
    نجد ان السابحون هم المصدر الرئيسي لتلوث مياه المسبح عادة. فهناك البعض من العادات السيئة يقوم بها زوار المسبح، الذين لا يلتزمون بقواعد النظافة العامة،
    فيتبولون في المياه أثناء السباحة دون إكتراث للأخرين. أيضاهنالك من يتجاهل تنظيف نفسه قبل السباحة، ما يؤدي إلى انتقال العرق إلى المياه.
    السيدات أيضا اللواتي لا يزلن مواد التجميل عن البشرة بشكل كامل قبل ممارسة السباحة، ينقل من خلالهن زيوت ومواد التجميل إلى المياه في المسبح
    نعتقد اننا عندما ننزل المسبح ان المياه تبدو نظيفه جدا ولكن العين المجرده لا تستطيع النظر والشعور بالبكتريا والفطريات لان حجمها يكون ظئيل جدا
    ومن ثم تقدم شركتنا افضل الطرق فى تنظيف المسابح وافضل ادوات التنظيف اتصل بشركتنا نصلكم فى الحال بأحسن الاسعار وافضل العماله المدربه فى تنظيف المسابح
    كما ان فى الأونه الاخيره نشرت الكثر من الصحف والمجلات العالميه عن الامراض التى تنجم عن عدم نظافه المسبح
    مثل احمرار العيون ومنها الأمراض الجلدية وأمراض الجهاز التنفسي وأن أكثر الأمراض شيوعاً خلال الصيف هي الدمامل، وحروق الشمس
    والالتهابات الفطرية مثل النخالية المبرقشة «عدوى فطرية في الفخذ»، وتسبب الحرارة الشديدة بتعرق الجلد، وتظهر على الجلد كحبوب مؤلمة، وحكة شديدة في جميع أنحاء الجسم،
    بقع بيضاء اللون أو داكنة على الصدر والظهر أو تقرحات وحكة بين الأصابع، التي تسمى «سعفة القدم»، التي تمثل عدوى فطرية وتنتشر في فصل الصيف وتسبب حكة في القدمين،
    وتحديداً بين الأصابع، وبقعاً متقشرة بيضاء اللون، مؤكداً أن التعرق الشديد الذي يحدث في الصيف، وخاصة بين الرياضيين، هو الذي يزيد من حدوث هذه العدوى الفطرية،
    شركة الصفرات لتنظيف المسابح بالرياض

  14. You have provided a nice article, Thank you very much for this one. And I hope this will be useful for many people. And I am waiting for your next post keep on updating these kinds of knowledgeable things
    Android Training in Chennai
    Android Course in Chennai
    Android Training in Bangalore
    Android Course in Bangalore
    Android Training in Coimbatore
    Android Training in Madurai