# Can a Harmonics from an Raspberry PI FM Transmitter Interfere with Emergency Bands?

One of my neighbors is an emergency personal and has a police radio at home so he knows when to respond. Anyways, the other day, I saw an article on MAKE on how to make a radio station with a Raspberry PI. This uses GPIO pin 4 to generate a FM frequency and broadcast. I was wondering how legal this is and if it would interfere with my neighbors emergency radio. Thanks for any help

• Welcome to ham.stackexchange.com! We encourage all new users to take the tour. Since you're asking a legal question, what country are you in? – rclocher3 Feb 19 '18 at 19:01

So, this is a rather well-researched thing.

The theory behind using a raspberry pi to transmit FM is the following:

Many microcontrollers, and that in this case includes the Pi's processor, have the ability to generate what we call PWM signals, Pulse Width Modulation. I'll scratch an example from this class of signals to give you a feeling:

Think of signal that is either high or low, and has a fixed period. Within that period, the first part is high, the second part low. The percentage of high is what we call "duty cycle", and if you smooth that signal enough, varying that percentage would allow you to generate an adjustable voltage; that's what PWM is most often used for[citation needed].

Now, as said, the Pi has such a PWM unit, and that works simply the following way:

You have a counter that you load with an initial value start. Then it simply counts down by one every clock cycle of your CPU, until it reaches 0, and then resets to start – without you (as a programmer) having to do anything about it. It's just a hardware counter.
Now, the interesting aspect about that counter is that it is combined with a thresholder: As long as the counter value is over threshold, the hardware sets an output pin high, afterwards low.

 start=5    \     \     \     \
\     \     \     \
\     \     \     \   …………
threshold_____\_____\_____\_____\__
\     \     \     \
0      \     \     \     \

clock cycle 1234567890123456789

output      HHHHLLHHHHLLHHHHLL…


That way, by setting start with your software, you can set the period of your PWM ($\frac{\text{start}}{f_\text{CPU}}$) and by setting threshold the percentage of time it's on.

Now, assume that threshold is always programmed to be half start. That way, you always get a 50% duty cycle.

When you draw that, you'll notice it looks like this¹:

A square wave, with its period being adjustable by changing start! That's exactly what happens on the Pi for FM: by changing start the frequency of a square wave is modified.

Now, we're talking about keeping the spectrum clean. Luckily for us, the spectrum of a square wave is known; remember (or hear for the first time) that the spectrum of anything that is truly periodic consists only of a sum of complex weighted sines and cosines; we call that the Fourier Series.

In the case of the (odd symmetric) square wave, that series reduces to:

\begin{align} x(t) &= \frac{4}{\pi} \sum_{k=1}^\infty \frac{\sin\left(2\pi(2k - 1)ft\right)}{2k - 1} \\ &= \frac{4}{\pi} \left(\sin(2\pi ft) + \frac{1}{3} \sin(6\pi ft) + \frac{1}{5} \sin(10\pi ft) + \cdots\right)\text, \end{align} with $f=\frac1T= \frac1{\frac{\text{start}}{f_\text{CPU}}}=\frac{f_\text{CPU}}{\text{start}}$ being the fundamental frequency of your square wave.

So, what's interesting here is

1. the frequencies of those sine components and
2. their amplitude, as the square of these are the power that's on that frequency.

Let's start with the frequencies: you can read those from the argument of the $\sin()$: You get $1\times$, $3\times$, $5\times$, … every odd number the fundamental frequency (the sine makes a full period in $2\pi$, divide its argument by that).
That is used by the intentional FM transmission: That way, your PWM doesn't have to have a frequency of let's say 100 MHz itself; it's enough if it runs at $\frac13$ of that, for example.

Of course, you're right, the other harmonics are all going to be there, too!

But notice how they're all space $2f$ apart? That means if our PWM frequency is 33.33 MHz (to produce 100 MHz using the harmonic at $3f$), then the first unintentional sine tone is at 166.67 MHz. That's pretty far away, and one can relatively easily suppress that with a simple LC filter, or simply by using an appropriately narrowband antenna!

What also helps is that this 166.67 MHz tone has only $\frac15$ of the amplitude of the square wave; power goes with amplitude squared, so that's only $\frac1{25}=4%$ of the square wave's power. For higher harmonics, the attenuation is stronger!

So let's assume there's actually police radio around 166.67 MHz (I don't think so, but it's the worst case scenario): 4% of what power?

It's pretty hard to say without extensive measurements and hand-matching the antenna to your Pi's output impedance, but let's say the Pi actually is able to deliver full power during the High State, and exactly zero in the Low state, and would actually produce a perfect square wave. In that case, average power is

$$\frac 12\cdot I_\text{out,max}\cdot V_\text{high} = \frac 12 \cdot 16\,\text{mA}\cdot 3.3\,\text{V} = 26.4\,\text{mW}$$

You'll see less than 10% of that in real life, because matching is hard and no way in this world can the Pi ramp up the current to full 16 mA in that time.

So, that would imply about 0.1 mW at 166.67 MHz. Luckily, an electrically short antenna with a bit of curl and capacitive ballast (which I'd guess is what most people would use for this[citation needed]) would not have that amount of bandwidth, and dampen that by another 5 dB or so; that would drop that power to -15 dBm.

¹ figure by MrLejinad on Wikimedia Commons

• So suppose the OP's Raspberry Pi FM station is radiating -15 dBm at the fifth harmonic. Let's further suppose that the OP is intending to broadcast at the bottom of the FM broadcast band at 88 MHz, leaving the fifth harmonic at 146.67 MHz in the 2m band. Let's go further and assume the worst-case scenario, that the neighbor listens to a repeater near that frequency. Would the neighbor be bothered? – rclocher3 Feb 19 '18 at 18:59
• yes, yes he will. I don't know the sensitivities of police scanners, but -15 dBm - Free space path loss over let's say 50m? – Marcus Müller Feb 19 '18 at 20:32
• so what you are basically saying is that yes, the harmonics of a raspberry PI will interfere with a police radio and the FCC can kick down my door if I do intend to broadcast on that frequency. – AntiMalwareFlames Feb 20 '18 at 3:01
• Also, I will be turning on the transmitter when my neighbor is at work and see how far it will broadcast, as the harmonic frequencies will most likely not travel as far – AntiMalwareFlames Feb 20 '18 at 3:17
• Unlike many instances of RF bit-banging seen in the wild, most raspi FM transmitters actually don't use harmonics. The "general purpose clock" peripheral used by "pin 4" solutions is capable of generating a square wave up to at least 125MHz directly. So the harmonics will be of the carrier freq itself, not some submultiple. And then (at least for the ones that modulate by changing the clock divider) there are the huge spurs caused by the fractional-N division. There's one version that modulates the PLL instead, which is probably better, but I lack the gear to measure that accurately. – hobbs - KC2G Feb 21 '18 at 7:00