0
$\begingroup$

I have very little knowledge of DSP, I'm trying to implement an FM synthesis algorithm in code / software.

So far I've successfully implemented a FM algorithm using the following:

sine (hz * (integrate (s 0 t)))

where hz is the frequency, s is the 'signal' and t is the time. And integrate is the function I've implemented that does integration using the "Trapezoidal rule".

However if I then try to generate a bunch of samples (amplitude over time), it has to run the integrate function n times for each sample - which adds up to a lot of operations I assume and hence is rather slow.

Are there efficient algorithms I could look into? Or alternative implementations worth considering?


One approach I've considered is instead of integrating the modulating frequency on each sample, is being able to calculate these discrete and allow them to be reused between samples.

So instead of integrating:

sample 1: 0s -> 1s
sample 2: 0s -> 2s
sample 3: 0s -> 3s

Do:

sample 1: 0s -> 1s
sample 2: integrated(sample1) + (1s -> 2s)
sample 2: integrated(sample2) + (2s -> 3s)
$\endgroup$
  • 1
    $\begingroup$ In a digital implementation you would normally use frequency-shift keying. $\endgroup$ – Matt L. Dec 24 '18 at 21:18
  • $\begingroup$ Maybe have a look at the Octave/Matlab script in this answer: dsp.stackexchange.com/a/53834/28112 . In discrete time, integration is just a cumulative sum (cumsum() in that script). $\endgroup$ – Andy Walls Dec 25 '18 at 2:30
2
$\begingroup$

I think you're overthinking the integrator:

Since your $s$ is a discrete signal in itself (you're doing DSP!!), the integral $S(T) = \int\limits_0^T s(t) \,\mathrm dt$ of it at any time $T$ actually collapses to the running sum!

So, as you've noticed, when you've got the value for any time $T$, the value at time $T+T_s$ (one sample later) is simply $S(T+T_s) = S(T) + s(T+T_s)$.

This should really be the least complex step in your FM.


Now, when you think about real-world FM radios, you'll find that the simple circuits (but also the more complex ones) don't actually contain an actual integrator (which you could build with an Operational Amplifier and a capacitor, for example).

What they really contain, and what makes the spectral side of things much nicer to understand, is a low-pass filter (you'll notice an integrator acts as low-pass filter). You'll notice there will be other filters in real-world broadcasting systems, so-called preemphasis filters. I'd call them a historical artifact from when receivers couldn't be trusted to equalize overly well, and that leads to a noise shaping that leads to decreased SNR (much noise) at higher audio frequencies, if you don't pre-amplify these selectively.

Now, the classical FM transmitter thus consists of an integrator-alike low-pass filter, and a preemphasis filter with a slight high-pass characteristic. You could probably combine these two.

My conclusion to that topic always is that FM is super easy to explain superficially, but looking deep, it gets really ugly, and the way the sausageaudio is actually produced at the receiver is loosely defined by the imperfections of 70 years old radio electronics and the technological abilities of that time. On an analytical level, FM gets especially cumbersome to deal with; try yourself on the derivation of the Bessel-shaped spectra of a single audio tone in FM. This, in fact, lead to us (as in: the communications theory basic course at university) dropping FM from the curriculum alltogether: if you'd build an audio transceiver system in this time and age, you can always get better and more resilient than FM utilizing the same power·bandwidth product by going digital. Thus, we try to avoid weighing down students with hard math and questionable applicability, even if it means that they aren't taught how the most prolific broadcasting standard of the world works.

This really shouldn't stop you, though! This is a worthwhile experiment, and building an FM transmitter is actually pretty satisfying soon as it works. Note that real-world receivers are pretty resilient to choosing wrong filters; we've actually had a bug in GNU Radio for what I guess was more than a decade in which the filter coefficients for the de-emphasis (ie. receiver side) filter were plain wrong, and no-one noticed. People simply don't expect exactly great-sounding audio over FM.

$\endgroup$
  • $\begingroup$ Really appreciate the informative answer! $\endgroup$ – Chris Stryczynski Dec 27 '18 at 14:17

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.