IQ frequency shifting (software radio tuning)

Started by Quazil 8 years ago6 replieslatest reply 8 years ago1996 views

I have IQ (FM radio) data sampled at 2.5 MHz centered at 100.2 MHz but the station is at 101.1 MHz.
My plan is to shift the data -0.9 MHz then decimate and low-pass filter to isolate the 15 kHz mono signal to get started.
Next I need to isolate the stereo sub-carrier which is at +38 kHz +/- 15kHz which I am hoping can be accomplished with the same (or similar) algorithm just shifted -0.938 (or perhaps -0.923).
The front-end tuner can be controlled and set to 101.1 et. al. but I still need to isolate the stereo sub-carrier (and RBDS etc...).
For the decimation I plan to use a FIR filter (perhaps using the new linear-phase complex coef. constraints blogged by Rick Lyons) and for the subsequent isolation low-pass filter I am leaning towards a Bessel IIR filter as it needs a rather sharp cut-off between 15 kHz and 19 kHz (pilot tone) but I want to maintain linear-phase as much as possible.

I am open to Plan B if there are better/alternative methods.

I read some older post about frequency shifting and have some concerns/questions:

1) Is the math to frequency shift this simple:
z'(t) = z(t) · e ^ ( -i · 2 · PI · f_shift · t)

2) Does using IQ data prevent the RF/IF aliasing that occurs when frequency shifting?
It is my tepid understanding that this aliasing occurs because of the mirrored negative frequency components of a real signal and I am lead to believe that IQ data does not have mirrored frequency components.
Does the aliasing not occur or does it still occur but is now less predictable in frequency content?
e.g. How can I determine if my subsequent low-pass filter will attenuate the potentially aliased components?

3) The older post started with real data and it was suggested to throw away the complex data after shifting.
I presume I would keep the complex/IQ data for my use-case and I want to verify that the frequency shifting does not distort the IQ in some way that invalidates the Q?

4) Does this method of frequency shifting maintain linear phase delay?
e^t isn't a constant so I can't convince myself that it trivially is.
Ignore if #1 is wrong and in which case can someone point me to me to more reference material.

[ - ]
Reply by Tim WescottJune 8, 2016

1: assuming that z(t) is complex (or IQ), yes

2: Yes, but.  Your understanding about why aliasing occurs is correct, but quadrature mixing done in the real world can be imperfect, letting the negative frequencies bleed in.  If the quadrature mixing is being done digitally (if, for instance, the "real" sampling is happening at 10MHz and then it's all being mixed down) then you're OK.

3: That older post was probably for something else.  Sometimes you throw away the quadrature data after shifting, sometimes not.  I think you want to keep it in this case (read on).

4: Yes.  Actually, this method of frequency shifting doesn't create any delay at all in theory-land: the only delay is caused by whatever time it takes to do the computation, and that's linear.  Furthermore, any memoryless multiplication (i.e., the n-th sample out is something independent times the n-th sample in) won't introduce frequency-dependent delay.  It may screw you up horribly in other ways, but not by introducing frequency-dependent delay.

5: No, your proposed demodulation method won't work (What?  You didn't ask that?  Too bad -- here's an answer anyway).

As best as I can judge from what you're planning on doing, you don't understand what FM is, or how to demodulate it.  Once you get your signal centered and bandpass filtered (with a filter that's somewhere between 200 and 400kHz wide), you need to demodulate it, and then you need to undo the preemphasis.  Once you've done that you'll have a signal that's the sum of your "normal" audio channel from 0 to 15000Hz and the stereo stuff centered around 38kHz - and isn't there even more stuff that may be in there?

At any rate, the audio that you want will not just be frequency-shifted to center around the carrier frequency -- that's what single-sideband does, not FM.

[ - ]
Reply by jyaJune 8, 2016

Since you already have I and Q, you can do FM demod with the function arctan(Q/I). That's a teaser; you don't want to compute arctan at the sample rate. Rick Lyons has an easier (though only approximate) way. See http://www.embedded.com/design/configurable-systems/4212086/DSP-Tricks--Frequency-demodulation-algorithms- It's a good approximation, and a better one can be had by using the five-term differentiator that he also describes somewhere.


[ - ]
Reply by QuazilJune 8, 2016

Once I get to writing the DSP assembly I'll come back to this.
Do you have any links to share for how to handle recovering the stereo data after demod/deemp?

[ - ]
Reply by QuazilJune 8, 2016

Oh wow, I was not thinking that whole channel was FM - I was thinking each sub-carrier was it's own FM. Thank you. Now I understand why all the FM demod code I look at puts the entire 200/400 kHz thru the dw/dt(atan2(q,i)).

New plan is:
1) Decimate & FIR filter 20MHz ~ 40MHz IQ stream to 2MHz ~ 4MHz
2) Demodulate
3) Deemphasis - duplicate this data for each sub-carrier
4) Low-pass to recover the mono
5) Shift, low-pass to recover stereo (repeat for other sub-carriers)

Is that on the right track?

Thanks for the response & help.

[ - ]
Reply by jyaJune 8, 2016

For FM audio, there is only one subcarrier. (There may be others for ancillary services. Look up SCA) The main signal, that which would be recovered by a simple detector such as a Foster-Seely discriminator or an Avins*-Seely ratio detector, is the sum channel -- L+R. The subcarrier at 38 KHz carries the difference signal -- L-R. There is a low-level pilot tone at 19 KHz whose second harmonic allows synchronous demodulation of the suppressed-carrier AM subcarrier. This arrangement provides compatibility (a mono receiver can usefully get stereo stations and a stereo receiver correctly reproduces mono signals,) but it necessitates some computation to get the full stereo signal. (L+R) + (L-R) = 2L; (L+R) - (L-R) = 2R. Of course, the gains of the two channels have to be closely matched. Since in audio there is usually less information in the difference channel than in the sum channel, it gets by with less bandwidth. 

Set aside your preconceptions about broadcast FM stereo and dig into the actual specs. Contrary to many CS courses, we can't code up what we don't understand.


* My cousin Jack.

[ - ]
Reply by jyaJune 8, 2016

There is only one subcarrier. That is the AM, suppressed-carrier difference signal. Don't forget the 19 Khz pilot tone that you need to extract and frequency double in order to demodulate it. Get a firm idea of the signal you need to deal with. https://en.wikipedia.org/wiki/FM_broadcasting#Ster... will give you a start.