Wednesday, November 28, 2012

How FM Killed the Additive Star, Part II

Now that we've looked at at some of the mathematics behind FM synthesis, let's try to attain a more concrete, intuitive grasp of the concepts. Firstly, I've provided some code zipped up, which you can get here. Extract it and follow the instructions in the README.

The code is fairly straightforward. I pulled elements from previous wave synthesis work, including the WavWriter, ByteConverter, and Oscillator base class. the FmOscillator simply implements the nextSample() method which Oscillator defines. One issue which has not yet been addressed is that of overflow in the phase. If the note is sufficiently long, eventually the floating point variable representing current phase will overflow, causing some potentially undesirable effects in the audio. While this issue is easily rectified in most other synthesis techniques (simply subtract 2 pi from the current phase when it exceeds 2 pi), the FM wave actually has two frequencies, and therefore 2 phases, one for the carrier frequency and one for the modulating frequency. Finding the exact point in which they align might be tricky (or even impossible, I'm not certain), but it's definitely an interesting problem which ought to be addressed.

The two parameters which vary in this sample program are harmonicity and modulation index. Harmonicity, from a mathematical standpoint, is the ratio of the modulating frequency and the carrier frequency of the FM wave. This ratio is convenient, since it allows us to express our modulating frequency in terms of our carrier frequency, rather than defining two distinct frequencies. Modulation index scales the sinusoid generated by the modulating frequency.

So, let's take a look at a few wave forms and see how varying harmonicity and modulation index affects them. First, we shall generate a wave with a harmonicity of 1.0 and a modulation index of 1.0. The resulting wave looks like this:


With our parameters, the resultant output is reminiscent of a simple additive sine wave we produced earlier in this blog series.

Now, keeping the harmonicity constant, let's increase the modulation index a few times:



The above waves have modulation indices of 1.1 and 1.5, respectively. Harmonicity is held at a constant 1.0. It appears that not too much has changed visually about these waveforms; the extent by which the wave is altered by that "additive-esque" bit simply increases. Perhaps then, we can think of the modulation index as the amount by which the carrier wave is affected by the modulating wave.

Now let's keep modulation index constant at 1.0, and vary harmonicity:



Woah, that's a bit of a difference! The waveforms are still periodic, but it's difficult to see the carrier frequency sinusoid at all now! Using a non-integral multiple of the carrier frequency as the modulating frequency puts it out of phase with the carrier frequency, generating these longer periods of repetition in the wave. Listening to these generated waves makes it sound a bit like a bell tone, much like a ringing phone or a door bell.

Finally, let's vary both parameters a bit:

harm = 1.1, mod = 1.1

harm = 1.1, mod = 1.5

harm = 1.5, mod = 1.1

harm = 1.5, mod = 1.5

We can see here that the observations we have made above apply to these waveforms as well. As modulation index increases, so does the amplitude of the subsidiary "humps". As harmonicity increases, we get more interesting phase differences between the carrier and modulating frequencies. Another way to think of these parameters is as such: the harmonicity dictates our modulating frequency's value. The modulating frequency, which is faster than our carrier frequency, forces our phase to deviate from its linear path. The modulation index determines the amount by which the carrier frequency phase deviates. This deviation leads to the production of audio sidebands in the wave spectrum, which is described mathematically by the infinite sum identity of the FM equation. Our modulation index determines the bandwidth, or number of sidebands generated, while the modulating frequency determines the frequency locations of those sidebands. Choosing a harmonic (integer multiple of the carrier) modulating frequency gives us harmonic sidebands, while non-integer multiples will give us inharmonic sidebands.

Cool stuff, no? I wish I could show just where the sidebands appear in the frequency domain, but unfortunately, I don't have a way to spectrally analyze the waveforms... yet. Perhaps this implies an adventure with Discret Fourier Transforms, and their implementations, Fast Fourier Transforms? We shall see...

The Things Yet to Come

Well, the semester is coming quickly (too quickly) to a close, and so I'll only have time for a few more topics. I hope to touch upon the following items:
  • DFT's and FFT's
  • MIDI format
  • JACK Audio
Additionally, I would like to create a project which appropriately sums up my semester's work. I think a simple sequencer application will be a nice piece with which to end my work for this independent study.

--- end transmission ---

No comments:

Post a Comment