Tuesday, January 1, 2013

Making an FM Stereo modulator work properly with streaming audio sources

Like many these days I often listen to streaming audio and podcasts, but there's a sticking point when it comes to listening to any of these while moving about the house, yard and garage:  How do I get the audio content from the source to where I am at that instant?
Figure 1:
An inexpensive stereo modulator - one of many varieties available.

A portable audio (e.g. MP3) player is fine, but not much good for a live stream.  There are other ways to stream audio - such as with some of the fancier players that WiFi interconnect, or even my smartphone, but I find this a bit awkward and would rather not burn through the batteries' charge on my phone - and I'd much rather not walk around the house wearing headphones, especially when I already have several decent audio systems in my house!

I could get a Bluetooth audio device that takes the source from the "Internet Radio" appliance, tablet or computer and then, to each of the other audio systems connect a Bluetooth audio receiver, but this seems to be a bit redundant and expensive - and this still doesn't really help when I'm outside in the yard or in the garage where WiFi coverage gets a bit spotty and Bluetooth isn't likely to be much better!  The other issue with some Bluetooth devices is that they can have slight amounts of audio delay, the amount varying between devices - something that can be really annoying if there are overlapping audio sources within earshot!

The obvious thing (to me) would be to throw the audio content - from whatever source - onto a cheap FM stereo modulator and use that to distribute it.  Not only will any FM radio in the house already pick it up, but it's pretty easy to get good enough coverage so that I can be in the yard or the garage and still pick it up using any portable device (including many MP3 players) that can receive FM radio.

With this in mind I picked up a cheap FM Stereo modulator from one of the (many!) online stores that sell such things.  The audio may (or may not) be quite as good as bluetooth, but it can be plenty good for background, casual listening and relatively "low-fi" audio such as that from many podcasts.

I've used these types of modulators for several years and they work "Ok" - but there's a problem:  The audio tends to "tear" a bit on the highs in the audio.  When I was playing audio from the laptop, this wasn't too much of a problem since I could just go into the graphic equalizer and roll off audio above 10-12 kHz.  Not perfect, but it helped.

More recently I got an "Internet Radio" box and soon discovered that when I plugged the modulator into it, I got nothing but "shash" (I'll let you figure that one out...) for audio when I tuned it in on an FM receiver.

I'd been afraid that this would happen!

A few boring bits about how FM stereo works:

First, let's talk a bit about how FM stereo works.  To make an FM stereo signal they do two things with it:
  1. They take the Left and Right channels and add them together in an audio mixer, the result being old-fashioned mono FM.  They stick this right on the FM signal.
  2. They take the Left and Right channels and subtract them and the result of this is a signal that contains the differences between the two channels.  They take this audio and up-convert it to 38 kHz.
The beauty of this system is its relative simplicity - after all, it was designed in the 1950's!  Compatibility with non-stereo receivers is maintained since the original mono audio is still where it always was - but the "new" signal (the left and right subtracted signal, or "L-R" as in "L minus R") is stashed way up there in the ultrasonic frequencies and really doesn't bother anyone since it was too high to be effectively be reproduced by many amplifiers and speakers and could be trivially removed on inexpensive (mono) sets.  You can see this displayed in figure 2 where one sees these various audio components on the audio spectrum from a source with really active audio with lots of synthesizers and snare drums.
Figure 2:
The anatomy of an off-air FM stereo signal.
At audio frequencies, below 15kHz (15000 Hz), you can see the "monaural"
portion (L+R) of the audio while centered about 38 kHz you can see the
"L-minus-R" signal.  At 19 kHz you can see the "pilot" carrier that is
used to help reconstruct the "L-R" and tell the receiver that a stereo
broadcast is being received.  Also evident is the "brick-wall" filtering
to remove audio above 15 kHz.
Click on the image for a larger version.

When you receive a stereo audio signal they do something clever.  When the "L-R" signal is converted up to 38 kHz they also generate a 19 kHz signal which, you might notice, is half of the 38 kHz up-converted frequency of the "L-R" signal that we need to reconstruct our original stereo signal.

When transmitted, they send that same 19 kHz signal which is then doubled in frequency and used to convert that "L-R" signal from 38 kHz down to its original audio frequency.  That 19 kHz signal has another function:  It lets the receiver know that there's a stereo signal!

Once you have that "L-R" signal again using simple math you can combine it with the mono "L+R" signal that you already had - which can be done with audio mixing:
  • (L+R) + (L-R) = 2L - The two "R's" cancel out and you are left with just the left channel
  • (L+R) - (L-R) = 2R - The two "L's" cancel out and you are left with just the right channel

Here's the problem:

In order for this scheme to work you can't have any audio higher than 1/2 of the frequency to which the L-R audio is converted in your original audio which means that everything below 19 kHz must be removed.  Practically speaking one can't easily make a filter that will allow everything up to 19 kHz get through and then absolutely block everything above it so the standard in broadcasting is to knock out everything above 15 kHz.  Since practical filters aren't perfect, by the time one gets to 19 kHz, the filter - which starts to filter at about 15 kHz - has done its job and removed the signals.

Why is this important?  We run into the same problem here in this analog system as we do in any sampling system whether it be digital or analog:  The Nyquist limit (link).  What this says is that we can't accurately represent any signal above one-half of our sampling rate which, for FM stereo, is 19 kHz - half of our 38 kHz sampling rate.  If we allow signals above this to be "sampled" (a term that works for our analog up-conversion and for analog-to-digital conversion alike!) they will re-emerge later as being "folded back" with portions of the audio present at the wrong frequency and the result can be rather annoying distortion of the original signal.

There's another problem:

This cheap FM stereo modulator doesn't really have any filtering in it to assure that audio above 15 kHz doesn't get through, but it does have the 75 microsecond equalization curve standard in FM broadcasting which boosts the highs:  This equalization can also work against us as we'll see.

For an analog source such as a tape player, it's a pretty safe assumption that there's not much content above 15 kHz, and for my laptop computer - which has a half-decent sound card built into it - the hardware generally puts out only those signals that it's supposed to:  If I set the graphic equalizer program to cut off signals above, say, 12 kHz, nothing much above 12 kHz comes out! (To be sure, I actually checked it using an oscilloscope and audio spectrum analyzer program - and it's clean.)

This is not true for all audio sources!

These days, there are a number of ways to make digital signals into analog ones for things such as MP3 players, computers, audio streaming devices, etc. and not all of them are created equal.  On many of these devices, the low-cost hardware doesn't filter the artifacts of digital-to-analog conversion very well.  If the sample rate is 48 kHz, there are "images" of audio near 96 kHz - twice the sample rate - with a two versions of the audio:  One starts at 96 kHz and goes up while the other is a mirror image and goes downwards from 96 kHz.
Figure 3:
Spectral output of the Internet Radio from 0 to 96 kHz. The "audio" is
seen below 15 kHz (15000 Hz) or so, but white noise from the
digital circuitry dominates above about 40kHz or so, raising havoc
with the modulator!
Click on the image for a larger version.

Practically speaking, this 96 kHz (or other ultrasonic-related) energy isn't a big deal since most audio amplifiers (and speakers!) can't really reproduce it, but if it gets into the modulator - at even low levels - it can raise havoc by making the transmitted signal wider than it should be!

There's yet another problem:

In the interest of low cost and high power efficiency, many audio amplifiers are of the "Class-D" type (link) and similar.  These aren't "true" audio amplifiers since they don't amplify the original signal in the conventional sense (e.g. each successive stage makes the original signal "bigger") but they sample the original audio signal, convert it into a digital waveform that consists of only "On" and "Off" voltages (e.g. "1's" and "0's") and then "amplify" it using a really fast on/off switch.

The advantage of this is that a simple on/off switch is very efficient:  Being either "on" or "off" it doesn't produce heat since it either allows all of the power through it with little loss when it's on, or it's completely turned off so no heat will be produced in that case, either!  Using simple components (capacitors, coils and the speaker itself!) this digital signal gets converted back into a decent representation of the original analog signal - provided that the intermediate digital signal was of high enough frequency to avoid the Nyquist problem we talked about before.
Figure 4:
Scope trace of the audio output of the Internet Radio showing the
low-level 400 kHz energy from the audio amplifier.
This, too, is causes severe problems when fed to the modulator!
Click on the image for a larger version.

For my Internet radio device the "Audio Out" actually takes a sample of the output intended for the speakers and in so doing since it comes from a Class-D amplifier.  Because of this it injects into the FM stereo modulator some of that high-frequency digital signal used in the audio amplification - in this case, around 400 kHz.


This further explains that "shash" that resulted from connecting the FM stereo modulator to the output of the Internet Radio box:  The extra "grunge" splattered the signal all over the place.

To see how bad this was, I plugged the output of the Internet Radio box into a computer with a 192 kHz sound card and, using the "Spectrum Lab" program, took a look at the output.  In the plot in figure 3, you can see the audio going from 0 to about 15 kHz where it drops off, but you'll also notice that by the time it gets to 40 kHz, we have noise!

To see higher frequencies, I connected it to an oscilloscope and quickly found the rather strong 400 kHz signal produced by the class-D audio amplifier as can be seen in figure 4:  The scope trace shows that this signal is at about 140 millivolts - a significant percentage of the roughly 1 volt peak-to-peak audio output at full volume!

Figure 5:
A 15 kHz passive low-pass filter using inexpensive coils and capacitors.
For stereo, two of these filters are required - one for each channel.
Click on the image for a larger version.
Filtering required:

As mentioned, this cheap FM stereo modulator had little or no filtering at all in the audio path so I needed to add some of my own.  To be sure, I could find on the web a myriad of low-power FM transmitters - both pre-built and already in kit form, many intended for uses not legal without licenses! - but I didn't really want to spend $100 plus to find such a device when it would be pretty easy to make this modulator work fine for my purposes.

There are two ways that one could build a filter:  Active - with some transistors or op-amps along with some capacitors and resistors, or passive, using just some inductors, capacitors and resistors.  An active filter would work just fine, but it would need its own power source and this would be fairly inconvenient, either as a "wall wart" to power it, or batteries that one would have to replace every time you forgot to turn the filter off!

Figure 6:
Completed passive  2-channel low-pass filter on a small piece of
"perf board", ready for testing.
Click on the image for a larger version.
Passive, it was, so I rummaged around in my inductor collection to get an idea of what I had laying around and then cracked open my copy of "Electronic Filter Design Handbook" by A.B. Williams (available via Amazon.com - link) - one of the very best library references around for understanding and designing all sorts of analog filters and well worth the price even if you buy it new.  Poring over graphs and tables I determined that an "Elliptic" filter (more details here - link) using two inductors and 5 capacitors (per channel) would provide adequate filtering so I crunched some numbers to see what I could make using the inductors that I had on hand.

Ultimately, I came up with the design shown in figure 5 that would make use of a 18 mH and a 27 mH inductor (both being fairly standard values) along with standard capacitor values while providing a decent amount of filtering above 15 kHz.

As a sanity check, I decided to simulate the filter using LTSpicetm - a very useful program - and it looked to be pretty good.  While I was at it, I checked to see how much of an affect the source and load impedances had on the response and observed that the filter was fairly forgiving:  Anything between 1k and 10k on the input and output yielded reasonable results but it seemed to look the best with something around 2k on the input and the output.  For my version, I chose 1k and 4.7k (respectively) for the input and output resistors as this seemed to be a good compromise between flat response and insertion loss.

Figure 7:
This is a simulated low-pass response of the filter showing the predicted
response with the amplitude response shown using the solid line. 
This simulation was done using "LTSpice" - a free program offered
by Linear Technology Corp.
Click on the image for a larger version.
The design was intended to be fairly insensitive to source and load impedance and as such, it is intended to be fed from a "Line Out" or "Speaker Out" connection and then terminated in a high-impedance input, typical of many "Line-In" devices, including my modulator.  As-built and tested, the low-pass filter exhibits several dB of insertion loss when terminated with a typical "line in" input impedance (which is typically 30k to 100k for consumer devices) - most of this loss being due to the 1k input resistor (which is necessary for proper response) and the subsequent 4.7k resistor on the output used to guarantee a maximum load impedance with a small additional amount due to the losses in the coils.

Rummaging around, I found the necessary capacitors, inductors and resistors and then built the entire circuit on a small piece of phenolic prototype board, making a nice, compact package.  For testing, I connected to it two short lengths of 3-conductor cable (2 wires plus shield) with one having a 3-conductor (stereo) 3.5mm jack on the "input" end to plug into the audio source and a 3.5mm plug on the other end into which the modulator connected allowing me to insert the filter inline.

The result?

Figure 8:
Bottom of the filter board showing the rather simple wiring.  I prefer using
the perf board material with copper rings as it makes for much more
reliable and solid construction than that without the copper.
Click on the image for a larger version.
It worked just as it should!

Without the filter, connecting the FM Stereo Modulator to the Internet Radio box resulted in the aforementioned "shash" that badly "noised-up" and distorted the audio whereas with the filter inline, the audio sounded great!

Measuring the filter's performance:

As for the predicted attenuation, the rejection compared to 1 kHz looked quite good:
  • -6dB at 14.0 kHz
  • -12dB at 14.6 kHz
  • -20dB at 15.0 kHz
  • -40dB at 16.1 kHz
  • At least 50dB of attenuation at the 400 kHz PWM frequency from the Internet radio device.
Using LT-Spice, the component values shown in the diagram resulted in a slight (about 2dB) "peaking" at the higher audio frequencies, the worst occurring at about 9.5 kHz - this being largely due to the slight (intentional) mismatch in source and termination impedance noted above.  If this slight peak bothers you and you can tolerate an additional 3-4dB or so of total insertion loss (for a total of 6dB) lowering the load impedance (mostly using R2) to 2k-2.2k will take nicely flatten the filter's response.

Since simulations are just that, I decided to check the actual filter response in two ways:  The first was with the oscilloscope connected to the output and an audio generator capable of producing up to 2 MHz output to the input terminal.  In the quick examination I observed that above 100 kHz the output was less than 1% of the input indicating at least 40dB of attenuation.

Figure 9:
Measure response of the filter as built.  Limited to about 24 kHz, this
measurement shows that the frequency response agrees well
with the simulation.  A logarithmic frequency scale was used to better-show
the response characteristics of the filter.
Click on the image for a larger version.
In the other, more graphical, method I used computer tools to "sweep" the filter.  Using the "Audacity" program (a free, open-source audio tool) I generated a segment of white noise and playing it back, I "looked" at the result using the Spectrum Lab program and found that it was flat to about 23 kHz - as it should be with a 48 kHz sampling rate.  Owing to the nature of the measurements (e.g. FFT settings and the "bin width", limited resolution of the display etc.) the true depth of the "notch" at around 19 kHz is not well depicted. 

I then inserted the newly-built filter into the path and the result may be seen in Figure 9:  The attenuation was about where it should be, indicating that the filter was working at least as well as the simulation!

So, there it is:  A simple, passive 15 kHz low-pass filter!

  •  There are programs that will do this entire measurement in one operation, that is sweep the input and display the response, all using a sound card, but I haven't gotten around to putting one of these on my computer. 
  • Some day, I hope to get around to putting everything in a nice box.


Figure 10:
The FM Stereo modulator, filter and Internet Radio box being tested.

For the inductors, they aren't particularly critical and they are fairly cheap (less than $2 each) and readily available from Mouser.:
  • 18 mH (18000 uH):  Mouser P/N:  43LJ381 or 434-02-183J or 434-01-183J
  • 27 mH (27000 uH):  Mouser P/N:  43LJ327 or 434-02-273J or  434-01-273J or 652-RLB9012-273KL

If you want to build one of your own, it's worth reiterating that you should not use ceramic capacitors as they are (usually) too unstable with temperature: Use inexpensive (less than $0.25 each) metal-film plastic capacitors instead, as noted below.   Some suggestions for various suitable capacitors (metal film, polyester with 5% tolerance) may be found below:
  • 1nF (1000pF, 0.001uF):  Mouser P/N:  871-B32529C1102J or 80-R82EC1100DQ50J 
  • 2.2nF (2200pF, 0.0022uF):  Mouser P/N:  871-B32529C1222J or 80-R82EC1220DQ50J
  • 4.7nF (4700pF, 0.0047uF):  Mouser P/N:  871-B32529C1472J or 80-R82EC1470DQ50J
  • 10nF (10000pF, 0.01uF):  Mouser P/N:   871-B32529C1103J or 80-R82EC2100DQ50J
For the resistors you are on your own!

  • It would appear that DigiKey didn't have 18mH inductors when I checked, but they had everything else.
  • This filter was built using through-hole components, but it could have been built using surface-mount parts.  Smaller surface-mount inductors may have somewhat worse operating characteristics (e.g. higher internal resistance, lower Q, etc.) but they should work fine in this application. 
  • The only types of ceramic capacitors that would be suitable for this would be "NPO" (a.k.a. "C0G") types with low temperature coefficients, but at the capacitance values required, these types will likely be more expensive than those suggested above.  Again, "normal" cheap capacitors (e.g. X7R, Y5Z, etc.) can be all over the map - especially with varying temperature - and should not be used!
  • The prototype board used was P/N:  15918 PB available from Marlin P. Jones and Assoc. (web site:  mpja.com) and was about 1-3/4" x 1-1/2" (approx. 44mm x 38mm).  These boards are pretty cheap - $4.90 for 10 of them - and are good for small projects such as this.
  • For the connections to the audio cable I made small loops using scrap pieces of wire (such as cut resistor leads) that connect to the input, output and ground points on the bottom of the board.  After soldering to the bottom of the board, the loop is then twisted a turn or two to make cheap (free!) and convenient connecting points for input/output/ground connections to the board. 
  • Yes, I know that I could buy an FM stereo transmitter of some sort that is purported to have "proper" low-pass audio filtering, etc. designed for "low power FM broadcasting" (whatever that is...) but these are much more than the $15 or so that this modulator cost me - and it would take the fun out of building a filter such as this! 

This page stolen from ka7oei.blogspot.com

No comments:

Post a Comment


While I DO appreciate comments, those comments that are just vehicles to other web sites without substantial content in their own right WILL NOT be posted!

If you include a link in your comment that simply points to advertisements or a commercial web page, it WILL be rejected as SPAM!