USB noise on C-Media audio dongles

29.11.2015 20:11

Cheap audio dongles based on C-Media chips are a convenient source of USB-connected audio-frequency DACs, ADCs and even digital I/Os with some additional soldering. Among other things, I've used one for my 433 MHz receiver a while back. Other people have been using them for simple radios and oscilloscopes. Apparently, some models can be easily modified to measure DC voltages as well.

Of course, you get what you pay for and analog performance on these is not exactly spectacular. The most annoying thing is the amount of noise you get on the microphone input. One interesting thing I've noticed though is that the amount of noise depends a lot on the USB bus itself. The same device will work fine with one computer and be unusable on another. USB power rails are notoriously noisy and it's not surprising that these small dongles don't do a very good job of filtering them.

USB hubs and dongles used for noise measurements.

To see just how much the noise level varies with these devices, I took some measurements of digital signal power seen on the microphone input when there was no actual signal on the input.

I tested two dongles: one brand new (dongle A) and an old one from the 433 MHz receiver (dongle B). Dongle B is soldered onto a ground plane and has an extra 10 nF capacitor soldered between +5V and ground. In all cases, the microphone input was left unconnected. I also took two different unpowered USB 2.0 hubs and tested the dongles when connected directly to a host and when connected over one of these two hubs. For USB hosts, I used a CubieTruck and an Intel-based desktop PC.

Noise power versus gain for dongle A

Noise power versus gain for dongle B

Each point on the graphs above shows signal power (x2) averaged over 15 seconds using 44100 Hz sample rate. 0 dB is the maximum possible digital signal power. Both dongles use signed 16-bit integer format for samples. I varied the microphone gain of dongles as exposed by the ALSA API ("Mic" control in capture settings). The automatic gain control was turned off.

You can see that dongles connected to the CubieTruck performed much worse than when connected to the PC. It's also interesting that dongles connected over hub A seemed to have a lower noise floor, although I'm not sure that difference is significant. It's likely that USB noise was also affected by unrelated activity in the host the dongles were connected to.

Signal power versus gain for dongle A

For comparison, above is how signal power looks like versus gain when a 10 mV peak-to-peak sine wave is connected to the dongle's input. You can see that the microphone gain control allows for a bit more than 20 dB of variation in gain.

Time-frequency diagram of noise from dongle B on CubieTruck

What is causing so much noise on CubieTruck? Looking at the spectrum of the noise recorded by one of the dongles, there appear to be two distinct parts: one is on low frequencies at around 100 Hz and below. I would guess this comes from the mains hum and its harmonics. The other part is between 2 kHz and 4 kHz and changes in frequency often. Sometimes it also completely disappears (hence strange dips on the graphs above). I'm guessing this comes from some digital signals in the CubieTruck.

There's really not much you can do about this. The small PCBs don't allow for much additional filtering to be botched on (the little ceramic capacitor I added certainly didn't help much) and it's not worth doing something more elaborate since then making your own board from scratch starts to make more sense.

Posted by Tomaž | Categories: Analog | Comments »

CC2500 radios and crystal tolerances

21.11.2015 13:05

While working on Spectrum Wars (during a live demo in fact - this sort of things always happens during live demos) I found a pair of Texas Instruments CC2500 radios that were not able to communicate with each other. Even more puzzling, radio A was able to talk to radio B, but packets from radio B were not heard by radio A.

After checking for software problems (I learned from experience to be vary of CC2500 packet drivers) I found out that very short packets sometimes got through, while longer packets were dropped by the packet handling hardware due to bad CRC. I also noticed that this problem only occurred at low bit rate settings and hence most narrow band transmissions. This made me suspect that perhaps the transmission of radio B fell out of the radio A's reception bandwidth.

When configuring CC2500 radio for reception, you must configure the width of the channel filter. Neither the Texas Instrument's SmartRF Studio software nor the datasheet is very helpful in choosing the correct setting though. What the datasheet does mention is that 80% of the signal bandwidth must fall within the filter's bandwidth and warns that crystal oscillator tolerances must be taken into account. Unfortunately, determining what the signal bandwidth for the given modulation and bit rate is left as an exercise for the reader.

Some typical occupied bandwidth values for a few modulations and bit rates are given in the specifications, but of course, Spectrum Wars uses none of those. As an engineer-with-a-deadline I initially went with a guesstimate of 105 kHz filter bandwidth for 50 kbps bit rate and MSK modulation. It appeared to work fine at that time. After I noticed this problem, I continued with the practical approach and, once I had a reproducible test case, simply increased the filter bandwidth until it started to work at 120 kHz.

Just to be sure what the problem was, I later connected both problematic radios to the spectrum analyzer and measured their transmitted signals.

Measured spectra of two nodes transmitting MSK modulated packets.

The signal spectra are shown with green (radio A) and black traces (radio B). The cursors are positioned on their center frequencies. The blue and red vertical lines mark the (theoretical) pass bands of 105 kHz and 120 kHz receive filters on radio A respectively.

For both radios, the set central frequency of transmission was 2401 MHz. Their actual central frequencies as measured by the spectrum analyzer were:

radio Aradio B
f [MHz]2401.044902401.02171
δf [ppm]+18.7+9.0

The crystals used on radios are specified at ±10 ppm tolerance and ±10 ppm temperature stability. The accuracy of the frequency measurement was ±6 ppm according to the spectrum analyzer's documentation (a somewhat generous error margin for this instrument in my experience). Adding this up, it seems that the LO frequencies are within the maximum ±26 ppm range, although radio A looks marginal. I was measuring at room temperature, so I was not expecting to see deviations much beyond ±16 ppm.

On the other hand, it is obvious that a non-negligible part of the signal from radio B was getting clipped by the 105 kHz receive filter on radio A. The situation with the new 120 kHz setting in fact does not look much better. It is still too narrow to contain the whole main lobe of the signal's spectrum. It does appear to work though and I have not tried to measure what percentage of the signal's power falls within the pass band (it's not trivial with short packet transmissions).

As for why the problem was asymmetrical, I don't know for sure. It's obvious that this radio link is right on margin of what is acceptable. It might be that some other tolerances came into play. Perhaps minor differences in filter bandwidth or radio sensitivity tipped the scale in favor of packets going in one direction over the other. I've seen weirder things happen with these chips.

Posted by Tomaž | Categories: Analog | Comments »

End of a project

15.11.2015 11:38

Two weeks ago, the CREW project concluded with a public workshop and a closed meeting with reviewers invited by the European Commission. Thus ended five years of work on testbeds for wireless communications by an international team from Belgium, Ireland, Germany, France and Slovenia. I've been working on the project for nearly four of these years as the technical lead for the Jožef Stefan Institute. While I've been involved in several other projects, the work related to CREW and the testbed clusters we built in Slovenia has occupied most of my time at the Institute.

Spectrum Wars demo at the Wireless Community meeting.

Image by Ingrid Moerman

It's been four years of periodical conference calls, plenary and review meetings, joint experiments at the testbeds, giving talks and demonstrations at scientific conferences, writing deliverables for the Commission, internal reports and articles for publication, chasing deadlines and, of course, the actual work: writing software, developing electronics, debugging both, making measurements in the field and analyzing data, climbing up lamp posts and figuring out municipal power grids from outdated wiring plans.

It's funny how when I'm thinking back, writing is the first thing that comes to mind. I estimate I've written about 20 thousand words of documents per year, which does not seem all that much. It's less than the amount of text I publish yearly on this blog. Counting everyone involved, we produced almost 100 peer-reviewed papers related to the project, which does seem a lot. It has also resulted in my first experience working with a book publisher and a best paper award from the Digital Avionics Systems Conference I have hanging above my desk.

Measuring radio interference inside an Airbus cabin mockup.

Image by Christoph Heller

Remote writing collaboration has definitely been something new for me. It is surprising that what works best in the end are Word documents in emails and lots of manual editing and merging. A web-based document management system helped with keeping inboxes within IMAP quotas, but little else. Some of this is certainly due to technical shortcomings in various tools, but the biggest reason I believe is simply the fact that Word plus email is the lowest common denominator that can be expected of a large group of people of varying professions and organizations with various internal IT policies.

Teleconferencing these days is survivable, but barely so. I suspect Alexander Graham Bell got better audio quality than some of the GoToMeetings I attended. Which is where face-to-face meetings come into the picture. I've been on so many trips during these four years that I've finally came to the point where flying became the necessary evil instead of a rare opportunity to be in an airplane. Most of the meetings have been pleasant, if somewhat exhausting 3 day experiences. It is always nice to meet people you're exchanging emails with in person and see how their institutions look like. Highlights for me were definitely experiments and tours of other facilities. The most impressive that come to mind were seeing Imec RF labs and clean rooms in Leuven, the w-iLab.t Zwijnaarde testbed in Ghent and Airbus headquarters near Munich.

Instrumented Roombas at w-iLab.t

(Click to watch Instrumented Roombas at w-iLab.t video)

One of the closing comments at the review was about identifying the main achievement of the project. The most publicly visible results of the work in Slovenia are definitely little boxes with antennas you can see above streets in Logatec and around our campus. I have somewhat mixed feelings about them. On one hand, it's been a big learning experience. Planning and designing a network, and most of all, seeing how electronics fails when you leave it hanging outside all year round. Designing a programming interface that would be simple enough to learn and powerful enough to be useful. If I would do it again, I would certainly do a lot of things differently, software and hardware wise.

Different kinds of sensor nodes mounted on street lights.

While a number of experiments were done on the testbed, practically all required a lot of hands-on support. We are still far from having a fully automated remote testbed as a service that would be useful to academics and industry alike. Another thing that was very much underestimated was the amount of continuous effort needed to maintain such a testbed in operation. It requires much more than one full-time person to keep something as complex as this up and running. The percentage of working nodes in the network was often not something I could be proud of.

For me personally, the biggest take away from the project has been the opportunity to study practical radio technology in depth - something I didn't get to do much during my undergraduate study. I've had the chance to work with fancy (and expensive) equipment I would not have had otherwise. I studied in detail Texas Instruments CC series of integrated transceivers, which resulted in some interesting hacks. I've designed, built and tested three generations of custom VHF/UHF receivers. These were the most ambitious electronic designs I've made so far. Their capabilities compared to other hardware are encouraging and right now it seems I will continue to work on them in the next year, either as part of my post-graduate studies or under other projects.

SNE-ESHTER analog radio front-end.

I have heard it said several times that CREW was one of the best performing European projects in this field. I can't really give a fair comparison since this is the only such project I've been deeply involved so far. I was disappointed when I heard of servers being shutdown and files deleted as the project wound down, but that is how I hear things usually are when focus shifts to other sources of funding. It is one thing to satisfy own curiosity and desire to learn, but seeing your work being genuinely useful is even better. I learned a lot and got some references, but I was expecting the end result as a whole to be something more tangible, something that would be more directly usable outside of the immediate circle involved in the project.

Posted by Tomaž | Categories: Life | Comments »

Egg carton theory

07.11.2015 21:30

Waiting in line at a grocery store is a common opportunity for random thoughts inspired by that particular locale. The other day I was buying some eggs and I saw someone in front of me opening up the cartons and inspecting them for broken eggs before taking them from the shelf. The cartons don't have seals on them, so this appears to be a pretty benign, if somewhat selfish behavior.

Having been tangentially involved in some game theory work recently at the Institute, it made me think about this in a bit more analytic way.

A half-empty carton of eggs.

Let's say that the price of one egg is c=1 and that each carton contains N=10 eggs. There is some fixed probability Pbad that each egg in a carton is broken. Let's say Pbad=1/100. The probability that an egg is not broken is Pgood = 1-Pbad.

If everyone is buying cartons without inspecting their contents, then Pbad is also the probability that an egg you've bought is broken, regardless of the size of the carton. You can calculate the adjusted cost cadj of a non-broken egg to you:

c_{adj} = c \cdot \frac{1}{P_{good}} = c \cdot \frac{1}{1-P_{bad}} \approx 1.01

In other words, for every 100 eggs you buy, you would have to buy one extra on average to make up for the broken one you unknowingly bought.

How would that change if everyone would inspect cartons before buying them? In that case, nobody would buy a carton if at least one egg is broken. These cartons would be left on the shelves and, assuming the shop doesn't reshuffle the contents of their cartons, thrown away when their best-before date passes. Of course, the shop would then raise the price of egg cartons to make up for those cartons it could not sell.

The probability that none of the eggs in the carton are broken is PN-good (assuming that egg breakings are independent events):

P_{N-good} = P_{good}^N = (1 - P_{bad})^N

The cost of a non-broken egg for you is now the same as the price you pay in the shop, since you make sure that you buy only good ones. However, the cost of an egg for the shop, and hence what you pay, is now:

c_{adj} = c \cdot \frac{1}{P_{N-good}} = c \cdot \frac{1}{(1 - P_{bad})^N} \approx 1.11

The difference with an unadjusted cost is now approximately 10 times higher. Again, this makes sense - instead of one extra egg for every 100 you buy, the shop must now buy an extra 10 to make up for the broken one and 9 good ones they threw away. In other words, 1% of broken eggs now make the final cost of an unbroken egg more than 10% higher. It doesn't seem so benign now, does it?

By the way, this is an interesting result also from the mathematical point of view. Notice, how the difference is approximately a multiple of N, even though N in the formula is in the exponent? This is the consequence of the following first order Taylor series approximation:

P_{N-good} = (1 - P_{bad})^N \approx 1 - N\cdot P_{bad}

This approximation holds for low values of Pbad. An intuitive explanation for it would be that it ignores the cases where multiple eggs in a single carton are broken.

Anyway, you can look at this as an example where selfish behavior makes things worse for everyone in the long term. Or you can think of it as a lesson in engineering. When a failure of any single individual component causes the whole system to fail, even low probabilities can quickly add up. In any case, calculating probabilities makes time waiting in lines pass faster.

Posted by Tomaž | Categories: Ideas | Comments »