Frequency modulation using GLSL?

1. Context

I use GLSL to plot the amplitude of the waveform at a given frequency as follows:

GLSL plot

Displaying simple waveforms like the ones above is a trivial task, it's just a matter of using the right equations (the available GLSL code is here ). Now I am trying to show the results of frequency modulation between two waveforms.


2. Research

After some research, I found two possible ways to do this:


3. Questions

  • What would be the best approach to solve this problem?
  • Is it possible to use a DSP-like approach in GLSL?
  • If not, is there any general FM equation flexible enough to do all the work?

Given my lack of skills in all the disciplines involved here (audio dsp, computer science, gpu programming, math), I would not be surprised if I miss something really simple here. Be patient.

+4
source share
1 answer

You are right that the conventional dsp-like phase battery approach is not well suited for parallel computing on a GPU; therefore, the β€œpure mathematical” method is probably the best option.

A generalization of the simple FM Chowning formula to more general frequency modulation functions is provided on the Wikipedia page for frequency modulation (the very first equation on this page). The key point is that the argument to the cos function is the phase, which, as the equation in Wikipedia shows, is an integral over time of the frequency. In FM, the frequency is usually the carrier plus modulation: for example, with the Chowning formula for simple sinusoidal FM, the frequency as a function of time t is

 f(t) = f_c - M * f_m * sin(f_m * t) 

where f_c is the carrier frequency, M is the amount of modulation, and f_m is the modulation frequency. It integrates with phase

 p(t) = f_c * t + M * cos(f_m * t) 

which corresponds to the phase in the equation in your question.

To modulate the cosine with a sawtooth saw, f(t) will be a sawtooth wave (plus the carrier frequency), and therefore, to find p(t) , you will need to find the time integral of the sawtooth wave. It's relatively simple (it should be a piecewise-quadratic function), but the people from math.stackexchange should be able to help if you have difficulties.

(Note. I have formulated everything here in terms of time t , but it could also just be a space x .)

+2
source

All Articles