A dirt cheap “spectrum analyzer” with an RTL-SDR dongle.

Frequency response of the 137MHz filter

Frequency response of the 137MHz filter (don’t mind the spurs)

If you want to see the frequency response of a filter, a spectrum analyzer with a tracking generator will be the tool of the trade. There’s only one problem: I don’t have one. An alternative is to hook up an RF signal generator, measure the output power of the filter with a power meter at multiple frequencies, and plot the result manually. But here too I have a problem: I don’t have a signal generator. Or a power meter. Besides, it’s a lot of work. So when I wanted to test a 137MHz bandpass filter, at first I didn’t think it would be possible. Fortunately I found a way that works reasonably well, and cost me nothing.

Using an RTL-SDR dongle, you can sample a piece of the spectrum up to 2 or 3MHz wide at a time. That’s not really enough for use as a spectrum analyzer. However, what you can do is to make the dongle hop from one frequency to the next, and make a composite spectrum. There is software that does just that: rtlsdr-scanner. This is fine if you want to scan the bands to spot interesting frequencies, but I still can’t measure filters with it.

If only I had a transmitter that transmits at every frequency: I could pass it through the filter and see what remains at the other side! Something like a wideband noise generator. After asking Google, it turns out that generating such noise is quite easy: a diode, when operating at the reverse breakdown voltage, generates a fair amount of noise, hundreds of megahertz wide! Then it’s just a matter of blocking the DC voltage with a capacitor, and there you have it, you are now the proud owner of a noise source! You then send this noise through an amplifier stage, but I used the amplifier of the dongle instead (I can set the gain between -1 and +42dB). Not ideal, because there are lots of other signals picked up too, but changing a slider in software is much less work than making a wideband amplifier. I also added an extenal 6dB attenuator immediately after the noise source to get better impedance matching to 50Ω.

A current source (D1, D2, R1 and Q1) feeding a zener diode. Any diode will do really, just make sure the breakdown voltage is reached. R1 determines the current (there's a 0.6V drop over the resistor so i=V/R).

A current source (D1, D2, R1 and Q1) feeding a zener diode. Any diode will do really, just make sure the breakdown voltage is reached. R1 determines the current (there’s a 0.6V drop over the resistor so I=V/R. 10K will do fine, or experiment).

The setup is now ready for prime time. When I turn on the noise generator, the noise floor of the dongle increases by 30dB around 130MHz. So far so good. I set the start- and stopfrequencies to 125MHz and 150MHz, and do a sweep. I repeat the measurement with the filter in between, and save both sweeps. Then in Tools->Compare, I can subtract the two signals. This sets the noise level as the 0dB reference. The result is seen in the image at the top (the “difference” scale is at the right, the left scale is not used as the two individual plots are hidden).

Apart from the spurs, the technique works quite well! It sure has limitations, but so does a professional spectrum analyzer. The difference is that with this dongle, you bump into them a lot sooner. Well, ok, almost immediately. The biggest problem is the dynamic range. If your dongle measures 30dB of noise from the noise source, it means that after 30dB of attenuation, you have nothing left to measure. So while you can get accurate readings of the filter loss at the passband (2.5dB in this case), you’ll hit the noise floor of the receiver before you reach the stopband attenuation of the filter. Also, the ADC of the dongle is 8 bit, so the difference between the largest and the lowest possible sampled voltage (the dynamic range of the ADC) is 20*log(256) or 48dB. Even if you can increase the noise level, you are limited by this 48dB. You could start playing with changing the amplification of the LNA, a bit like High Dynamic Range Imaging. Maybe this could improve the range, maybe it will block the receiver. In any case, the first improvement should be to make the noise source better. Both the amplitude and the frequency range. at 100MHz I get roughly 30dB noise increase, but at 640MHz I only have 10dB left. that means that I have almost no dynamic range at that frequency.

Another problem is that the noise floor of the dongle isn’t flat. It’s more like the Alps. So the dynamic range varies, and you may see some bumps in the frequency response that aren’t really there, it’s just the noise of the receiver itself. If you have a dongle you can see the bumps yourself by setting full LNA gain and doing a large sweep with no antenna connected. You’ll see the power spectrum go up and down, and all kinds of spurs will show up. If you take a look at the FM broadcast band around 100MHz, you’ll see the signals leak through. This device is designed to do the job it’s meant to do at the lowest price point possible, not to have the best shielding and superb RF performance.

Nonetheless, there’s a lot to experiment with. What I’ve shown here is just the results of a few days of hacking. There’s definitely improvements that can be made, both in software and in hardware. So just make yourself a noise source and start playing!

Oh, and if you’re wondering what the filter is used for: it’s for improving NOAA weather satellite reception with a dongle. With these receivers it really helps a lot when the strong signals at other frequencies are removed first.

References:

Spam fail

This blog has always attracted some spam. In the beginning it was small enough to delete by hand, but it has grown to the point that I installed a plugin called Akismet. It works fine, but since nobody has ever commented on any single article I wrote, it could be having a lot of false positives, or at the worst case it could simply mark every comment as spam. I just don’t know.

So I took a look at the spam messages, and I came across this small jewel:
{
{I have|I’ve} been {surfing|browsing} online more
than {three|3|2|4} hours today, yet I never found any interesting article like yours.
{It’s|It is} prety wortth enough for me. {In my opinion|Personally|In my view}, if all {webmasters|site owners|website owners|web owners} and bloggers made good
content as you did, the {internet|net|web} will be {much more|a lot more} useful than ever before.|
I {couldn’t|could not} {resist|refrain from} commenting.
{Very well|Perfectly|Well|Exceptionally well} written!|

Etc, etc… It goes on for another 25kB.

It seems like this spammer is even too stupid to correctly install his software. I don’t think a simple facepalm is going to cover this one. We’ll need a double facepalm!

Playing with a vector network analyzer

I’ve been playing a lot with my N2PK VNA lately. Not only learning how to measure things (using the wonderful VNA tutorials of PA4TIM), but also how it works internally, and how I can control it from an Arduino. I can already set the frequency and phase of the two frequency generators, and I can read out the ADC.

Meanwhile, at the Radio Club Leuven, there has been a huge interest in WSPR lately, a low-power beacon-like digital mode, ever since Wim ON3ZOE demonstrated running WSPR with a Raspberry Pi. By hooking up an I/O pin to an antenna, with only a filter in between to remove the harmonics, he has gotten all the way to Greenland, 3500km away from Belgium. Hmm…

Arduino controlling the VNA

Arduino controlling the VNA

Continue reading

Making a crystal filter

A few weeks ago, I was given some hand-matched crystals at the radio club. My mission: to make a crystal filter for a Belthorn IF-module I’m going to build. Once again, something I’ve never done before. Let’s dive in with both feet.

To make a filter, there exist many software packages. I used Dishal from dj6ev, a windows program that luckily runs just fine under wine on Linux.

dishal
Continue reading

N2PK Vector Network Analyzer

N2PK VNA under construction
This is a very interesting build. If I were to make it again, I would go for a dual detector and the fast ADC, but even with its slow measuring rate (7 measurements per second), it’s still a very interesting piece of equipment to have. It can be used to measure complex impedances of all kinds of circuits. Using a bridge (I still have to build mine), you can also check antennas, something I’m looking forward to measure. You can find N2PK’s project page for this instrument here.
Continue reading

SMD soldering an SDR transceiver kit

After playing with RTL-SDR dongles and GnuRadio, I wanted to be able to listen on HF. The USB dongles are not suited for this, unless you buy an upconvertor. I looked around a bit I discovered the . As I was keen to learn how to solder SMD’s, this seemed like a great challenge. The kit was ordered and the soldering iron turned on.

There are two three pieces of advice I can give to anyone getting started with SMD soldering. Firstly, spend a good amount of time watching youtube video tutorials. If you hear things that keep getting repeated, then that’s probably important. I particularly recommend the soldering videos from EEVBlog, CuriousInventor, and W2AEW.

Secondly, use flux. If you followed the first advice, then that’s probably already one of the things you have seen everybody do. And for good reason: once you have used it, it will instantly convert you. It is a weak acid, that will do its work when heated. It will eat away the small layer of corrosion that forms around most metals, and allow for a good bond between the soldering tin and the PCB and component. Also, it will make the tin more fluid. It’s hard to describe, but if you use it you’ll clearly see how the flux influences the behavior of the tin. Without flux, drag soldering is almost impossible. With flux, it’s a breeze. I bought a syringe with flux gel, and I even use it for through-hole components when using old components.

And finally, get a good roll of solder wick. It’s like a towel for cleaning up excess solder. It’s simply a braided wire soaked with flux. When you hold it against some solder and melt it, the capillary force of the braided wire will suck all the solder up and leave your surface nice and clean. It’s also great for removing soldering shorts between pins of integrated circuits.

When the SDR kit arrived, it took me a weekend to put it together. It worked first time, and I use the radio for SSTV, WSPR and just general listening. As this also has transmit capabilities, getting a HAM license became a priority. Transmitting to a dummy load quickly becomes boring. To test how far I stood, I converted the publicly available exam questions database of the BIPT to SQL and made an online HAREC test page. A few months later I passed my exam and got the call ON8VQ.

Low latency video with a Raspberry Pi

Now that I have a camera board, I’ve been trying to get a real-time video stream out of the Raspberry Pi. First I tried using RTSP, but the problem is that a video player will start buffering an incoming stream, giving you a 10 second delay. I don’t know whether this can be avoided. Then again, I haven’t looked very hard.
I got rather decent results by just bypassing all the overhead, and sending the H.264 stream of the camera directly to a TCP tunnel. On the desktop side, you can then read the data and pipe it to mplayer. For the network transport, netcat comes to the rescue:

First, start listening on the desktop:
nc -u -l -p 6502 | mplayer -fps 15.1 -demuxer h264es -

Then, open the floodgates on your raspberry pi:
raspivid -t 0 -hf -w 320 -h 240 -fps 15 -b 500000 -o - | nc -u 192.168.1.7 6502

There are a lot of parameters you can play with, trying out tcp instead of udp, changing bitrate, size etc. Notice that I set the playback rate a bit higher, this keeps mplayer constantly hungry. If the camera sends even slightly faster than mplayer shows, the frames would start to pile up, and you would get an ever increasing lag (and memory usage).