I & Q

Status
Not open for further replies.

LubeckTech

Member
Premium Subscriber
Joined
Jan 22, 2010
Messages
204
Location
Parkersburg, WV
I don't mean to sound dumb but could someone give me a brief explanation of I & Q and how it related to RTL dongles?
After much searching & reading I just don't get the concept and fear my head might explode!!!!!!!!!!!!!!!!
 

Chance

Member
Joined
Dec 19, 2002
Messages
109
Location
Sachse, Texas
Layman explaination

I've spent many hours trying to understand why it is needed and how it works. Most of my understanding comes from the links above. Here is a recap of what I learned from the above and my personal twist on it.

Why is it needed?
If we could sample at twice the frequency, like we can easily do with audio, there would be no need for I/Q sampling. The utopia of software defined radios would be direct sampling. If you want to sample a transmission at 800 mhz, for example, you need to sample at 1.6 billion times a second! We're not there yet! You can mix to a lower frequency (heterodyne) but like resizing an image you lose resolution. So we have to get creative and do something to the original signal before it is down-converted that will yield clues to restore the required resolution.

How does it work?
The simple explanation to the two data points are "what are you now" and "which way did you come from".

The clock pendulum analogy is the best I found. If you take a photograph of a grandfather clock you can tell exactly where the pendulum is but not which direction it is going. So what to do? Take more pictures? Oh sorry your technology is limited to 1 photograph per second. Ok? How about we increase the exposure time? The result is a blur of the pendulum. We can now tell which direction it is going. (The beginning of the blur is Q, the end of the blur is I). Since a pendulum is a continuous wave signal you can calculate a complete reproduction of the signal with just one sample! Pretty ingenious.

So bottom line. I/Q is a hack. Split the original signal into two. Leave one alone and then slightly delay the other copy, which is easy to do with analog circuitry. Down convert both signals to a reasonable frequency for sampling. Do two Analog to Digital conversions, one for each of the signals, at the same exact regular intervals. I is the non-delayed sample and Q is the delayed sample. Now you know with good certainty if the signal is rising or lowering.

An MIT student would consider this a very butchered explanation. And I know it's not exactly 100% precise.. But that does not matter for our layman purposes of having a general understanding.

Hope that helps!

-Chance
 
Last edited:

slicerwizard

Member
Joined
Sep 19, 2002
Messages
7,776
Location
Toronto, Ontario
Sorry, I don't see it that way.

If you sample your ~800 MHz signal at 1600 MHz, you'll have a bunch of discrete sample values, each one about 180 degrees farther along in your signal's ongoing cycles. Since the stepping is not exactly 180 degrees, your samples will wander up and down - sometimes they'll be near zero (i.e. when you're sampling at zero and 180 degrees through the signal's sine waves) and sometimes they'll be higher, say +/-58, because they were sampled at/near the high and low points (90 and 270 degrees) in each sine wave. So +/-58 is the maximum output created from the sine wave's voltage feeding into the ADC.

So - at any given point, let's grab a sample - here's one and it's a 7; so what's the signal's strength at that point in time? We'd like to AM demodulate it, so we need to know the signal's RF strength at all points (or maybe every nth point, since we probably don't need that much time resolution). How are we supposed to get that from a 7? Or more importantly, how much work (math or data transformations or whatever) are we going to have to do?

Let's say this ~800 MHz signal is actually a dead carrier (constant RF power), but with non-I/Q sampling, we're handed a bunch of numbers that wander from zero to +/-58 - how do we take a sample at time x and say "RSSI=y"? We can't do that with a single number, or even with that number and its immediate neighbours, can we? Even if we can, can it be done with simple/fast math?


Meanwhile, with I/Q data, every time we sample that sine wave, I and Q get set to sine and cosine values that tell us where in the sine wave we are (e.g. what angle we're at) and the sine wave's magnitude/power at that instant in time.

RF power is just the length of the line from (0,0) to (I,Q), and since I and Q are 90 degrees apart, this is a simple Pythagoras problem (a squared plus b squared equals c squared, according to Google), so we take (I times I) plus (Q times Q) and voila, we have a power level at time x; do that at regular intervals, say 24,000 times a second, and we have AM demodulation and audio that can be sent to a speaker.

Examples:

If we happen to sample the signal right at zero, 90, 180 or 270 degrees into its sine wave, we get an I/Q pair where one of the values will be high (plus or minus 58 with our dead carrier), and the other will be zero (because it's 90 degrees off), so when we need to calculate power, we get 58x58+0x0=3364; same for -58x-58+0x0, etc.

If we sample 45, 135, 225 or 315 degrees into the RF signal's sine wave, I and Q will get set to the sine and cosine values of those angles, which are all plus or minus 0.70710678118, multiplied by the signal's magnitude, which is still 58, so we get +/-41.01219330844; when we want to know the power level, we wake up Pythagoras and get (41.01... times 41.01...) plus (41.01... times 41.01...) is... 3364, same as above. Same as above for any angle into the RF signal's sine wave.

If the signal's power level is not constant, our (IxI)+(QxQ) calculations will give us numbers that vary in direct relation to the RF signal's changing power levels.


For FM demod, we treat an I/Q pair as a dot on a circle. And the next I/Q pair as another dot. The angular distance between those two dots on the circle is a signed (positive or negative) angle measured in degrees and is easy to calculate (simple atan2 function). That angle tells us the instantaneous frequency of the RF signal. It also tells us what audio value to generate - a small positive angle change = a small positive audio sample, let's say +125; a big positive change = big audio value, let's go with +27,445 (that's fairly big for signed 16 bit audio); same deal with negative angular changes - we get negative audio values. Send those audio samples to a PC's sound hardware and we hear the FM signal in all its glory.

Now how do we easily/quickly generate FM demodulated audio from the non-I/Q stream of samples? Since we're sampling at almost 180 degree intervals, that 7 from above will likely be followed by another 7; a -58 by another -58; a zero by a zero, etc. So how do we get instantaneous RF frequency?


So:

I/Q data --> AM or FM demod = easy peasy, aka not "a hack"

A single stream of RF values --> AM or FM demod = how to do it? (it has to be simple and fast or it's pointless, since we already have a working easy/simple/fast approach)


Edited to add:

This doesn't even get into all the other useful things that I/Q data enables, such as the ability to losslessly rotate the entire spectrum of signals that an SDR has grabbed, i.e. to shift any targeted signal to baseband or wherever else you want it without the need to filter out or otherwise worry about the other signals that may be present in the SDR's passband. Again, how do we easily do that with non-I/Q data? Mix that data with a "shifting" signal? Now we've got aliasing products all over the place, including over our target signal...

And so on...
 
Last edited:

Chance

Member
Joined
Dec 19, 2002
Messages
109
Location
Sachse, Texas
Just by your user name, I know I can't hold an argument to what you said. :)

Like I said, to an expert I've oversimplified the explanation. No offense to either the original poster (or myself)....but this is like when a 5 year old asks where babies come from.....you give a simplified answer to solve the curiosity. I was that 5 year old (my intellect relative to this discipline) who just wanted to know why.

Perhaps my reference to it being a hack could be misunderstood. Many discoveries and inventions have been founded on the basis of a simplification or some kind of shortcut. Only sine waves exist in the real world and I/Q is a man made construct that adequately solves our current limitations. Like most things in life, you make comprises.

I realize the sampling rate would actually need to be much higher than 2x, not to mention the processing power required. I/Q sampling is clearly the answer to all the scenarios you described. I was finally able to get that understanding a year into playing with SDR's and looking at source code.

Hopefully my explanation without any mathematical equations get people on the right track.

So my question back to you is does my explanation do more good than harm in building a basic understanding? And if not, what should be changed?

One curiosity question. If I/Q sampling is superior, and not a compromise, why not apply to audio sampling? Standard sampling is 44khz. Audiophiles prefer 96khz. So would 22khz with I/Q sampling outperform 96khz? (For sake of possible example. I is real time, Q was sampled slightly early, a time interval equaling 90 degrees out of phase on say 10x 220khz reference signal. So 22k times a second qi.....qi.....qi.....qi...)
 

jonwienke

More Info Coming Soon!
Joined
Jul 18, 2014
Messages
13,409
Location
VA
One curiosity question. If I/Q sampling is superior, and not a compromise, why not apply to audio sampling? Standard sampling is 44khz. Audiophiles prefer 96khz. So would 22khz with I/Q sampling outperform 96khz?

No. I/Q sampling at 22KHz for the I and Q streams would improve upon standard 44KHz sampling in some ways, but would not equal or surpass 96KHz sampling because the 96KHz sampling would be the equivalent of doubling the I/Q sampling. Instead of just sampling at 0 and 90 degrees, you'd also be sampling at 180 and 270 degrees, which will give you additional signal data.
 

KA1RBI

Member
Joined
Aug 15, 2008
Messages
799
Location
Portage Escarpment
I/Q data --> AM or FM demod = easy peasy, aka not "a hack"

I/Q isn't a hack. I+Q are are actually just the Real and Imaginary parts of a complex number. The complex arithmetic is a tough road but a very rewarding one indeed for the serious student.
A single stream of RF values --> AM or FM demod = how to do it? (it has to be simple and fast or it's pointless, since we already have a working easy/simple/fast approach)

Converting a stream of real values of sampled RF to I/Q is super-simple, easy, and fast! We generate an I/Q stream from a real stream by setting the I's to the real sample value and the Q's to zero. In practice it's just a matter of stuffing a zero sample in between each real sample. It really is as easy as that!

This doesn't even get into all the other useful things that I/Q data enables, such as the ability to losslessly rotate the entire spectrum of signals that an SDR has grabbed, i.e. to shift any targeted signal to baseband or wherever else you want it without the need to filter out or otherwise worry about the other signals that may be present in the SDR's passband

true, we might want to LPF the "0-Q-stuffed" stream. If the mirror-image offends us we could do a hilbert, or we could just "losslessly rotate it" left by 1/4 the sampling rate and do and LPF-plus-decimate-by-2. If we did the latter our signal would now be back at our original size and rate and would still contain all the information in the original, but it would now be an "I/Q" signal at or as close to "zero IF" as the accuracy of our rotation allows.
. Again, how do we easily do that with non-I/Q data? Mix that data with a "shifting" signal? Now we've got aliasing products all over the place, including over our target signal...

We can start pretending the signal is "I/Q" as soon as the Q's are stuffed with zero values. That includes having the nice property of not generating spurs or aliases when we heterodyne (convert or mix or rotate) frequencies up or down...

Max
 

slicerwizard

Member
Joined
Sep 19, 2002
Messages
7,776
Location
Toronto, Ontario
Just by your user name, I know I can't hold an argument to what you said. :)
Appeal to authority fallacy detected! I am far from any sort of expert in this field.


I realize the sampling rate would actually need to be much higher than 2x, not to mention the processing power required.
No, 2.0001x would be fine.


I/Q sampling is clearly the answer to all the scenarios you described. I was finally able to get that understanding a year into playing with SDR's and looking at source code.
As Max has indicated, complex data is what one uses to do the work - in the scenarios I listed as well as in others.


Hopefully my explanation without any mathematical equations get people on the right track.

So my question back to you is does my explanation do more good than harm in building a basic understanding? And if not, what should be changed?
The main thrust of your post was that I/Q data was a hack to deal with limits in hardware sampling rates. I/Q only cuts the sampling rate in half - that's not a huge factor.

To be fair, yes, there are no doubt many cases where two x MHz ADCs in an I/Q configuration were chosen over a single 2x MHz ADC, but it's not always because a 2x MHz ADC doesn't exist or is prohibitively expensive. Going with a single ADC means you've created more work down the line. A digital filter running on that single 2x MHz stream is generally going to be twice the size of a comparable filter running on the x MHz streams. So let's say a 50 tap filter running on a 20 MHz stream - that's one billion operations per second. Or a 25 tap filter running on two 10 MHz streams (the I/Q streams) - that's 250 million times 2, or only 500 million operations per second to do the same work on the same signal. Your characterization of I/Q focuses on only one aspect of a much more complicated field.

Your 800 MHz signal must be mixed and downsampled to something reasonable (our PCs can't handle 1.6 billion samples per second). So how about I/Q at 10 Msps? Or if that's some sort of hacky compromise, how about just real at 20 Msps? Well, the Airspy, for example, with its single ADC, gives a developer just that choice, so which one and why? I/Q can be completely avoided - there is no sampling rate limit limiting our options here, so according to your summary, we don't need (or want?) I/Q? What will we do with this signal in the I-only representation?


One curiosity question. If I/Q sampling is superior, and not a compromise, why not apply to audio sampling? Standard sampling is 44khz. Audiophiles prefer 96khz. So would 22khz with I/Q sampling outperform 96khz? (For sake of possible example. I is real time, Q was sampled slightly early, a time interval equaling 90 degrees out of phase on say 10x 220khz reference signal. So 22k times a second qi.....qi.....qi.....qi...)
I/Q encodes negative frequencies, which we don't really deal with in audio signals, so we'd have recorded files with twice the size for the same data.

22.05 kHz I/Q has 44.1 thousand values per second, just like 44.1 kHz real, so it can hold exactly the same amount of information, but half of it would be those typically unused negative frequencies. Or you could record zero to 22 kHz in a 22 kHz I/Q file by rotating the signal by 11 kHz. But if we did that in hardware, we'd be raising the hardware cost just to do some something that can be done cheaply in software, given audio's low data rates.


Converting a stream of real values of sampled RF to I/Q is super-simple, easy, and fast! We generate an I/Q stream from a real stream by setting the I's to the real sample value and the Q's to zero. In practice it's just a matter of stuffing a zero sample in between each real sample. It really is as easy as that!
No, there is more to it than that. You've taken a stream of fs I samples per second, which holds signals from zero to fs/2 Hz, and turned it into a stream of fs I/Q samples per second that now encode the original zero to fs/2 Hz signal as well as a mirrored copy that occupies zero to -fs/2 Hz.

You now have twice as much data to deal with. That raises processing requirements. Or you can filter out the negative frequencies, which will let you halve your sampling rate (f I samples/sec --> f/2 I/Q samples/sec)


true, we might want to LPF the "0-Q-stuffed" stream. If the mirror-image offends us we could do a hilbert, or we could just "losslessly rotate it" left by 1/4 the sampling rate and do and LPF-plus-decimate-by-2.
As I said, it's not just "as easy as that"...


If we did the latter our signal would now be back at our original size and rate and would still contain all the information in the original, but it would now be an "I/Q" signal at or as close to "zero IF" as the accuracy of our rotation allows.
No, it would not contain all of the information from the original signal. Your low pass filter does not have zero Hertz wide transition bands - it's not a brick wall filter. You will end up keeping some small amount of your mirror signal as well as losing some of your original signal.


We can start pretending the signal is "I/Q" as soon as the Q's are stuffed with zero values. That includes having the nice property of not generating spurs or aliases when we heterodyne (convert or mix or rotate) frequencies up or down...
It also has the property of doubling the data rate. Now running a bunch of VCOs ends up using twice the CPU that it should...
 

adcockfred

Member
Joined
Apr 8, 2010
Messages
366
Location
Aldine, tx.
What he is trying to say is that even a prime number is not absolute. al gebra the average of the variables. all the rest of the diminutions are inward not outwards.
 

Chance

Member
Joined
Dec 19, 2002
Messages
109
Location
Sachse, Texas
Wow! I appreciate all the great feedback. I think I'm almost there.

Processing wise, I get it now. I/Q is *not* a hack or shortcut. Even if you were able to do direct sampling at a high enough rate to capture multiple points of a sine wave, working with only I data is not ideal. Your options for working with I data are limited to counting 0 point crossings or expensive FFT operations. I/Q data yields itself beautifully to mathematical formulas for not only demodulating data but also modulating data. No matter the advancements in technology I/Q is the method to transverse between the analog domain (as in the natural phenomenon of rf energy) to a digital form.

What I find extremely fascinating is how easy it is to obtain the I/Q samples which just conveniently fit into what is needed for processing. If I understand this correctly, analog circuitry is being used to shift (via a 90 degree shift of the reference sine wave, i.e. cosine). Saying Q is being slightly delayed is not correct because really it's just putting the original signal in a different phase (or view point) for sampling.

Most of my simplified explanation is not correct. I'll go back to the drawing board on that. Maybe two still images taken at the exact same time of an ocean wave looking straight on and perpendicular.

Thank you!
 

prcguy

Member
Premium Subscriber
Joined
Jun 30, 2006
Messages
17,129
Location
So Cal - Richardson, TX - Tewksbury, MA
Yes, Q is not simply delayed, it is what's happening 90 degrees from I at any particular time. With a properly sampled I/Q waveform, a computer with appropriate software can recreate the original signal in all its glory and also do further processing and functions as we see in modern DSP based SDR radios.

There are also other circuits that go along with an I/Q demodulator or quadrature detector like a sample and hold circuit before the A/D converter. I suspect modern A/D converters used with SDRs have the sample and hold built in.
prcguy

Wow! I appreciate all the great feedback. I think I'm almost there.

Processing wise, I get it now. I/Q is *not* a hack or shortcut. Even if you were able to do direct sampling at a high enough rate to capture multiple points of a sine wave, working with only I data is not ideal. Your options for working with I data are limited to counting 0 point crossings or expensive FFT operations. I/Q data yields itself beautifully to mathematical formulas for not only demodulating data but also modulating data. No matter the advancements in technology I/Q is the method to transverse between the analog domain (as in the natural phenomenon of rf energy) to a digital form.

What I find extremely fascinating is how easy it is to obtain the I/Q samples which just conveniently fit into what is needed for processing. If I understand this correctly, analog circuitry is being used to shift (via a 90 degree shift of the reference sine wave, i.e. cosine). Saying Q is being slightly delayed is not correct because really it's just putting the original signal in a different phase (or view point) for sampling.

Most of my simplified explanation is not correct. I'll go back to the drawing board on that. Maybe two still images taken at the exact same time of an ocean wave looking straight on and perpendicular.

Thank you!
 

KA1RBI

Member
Joined
Aug 15, 2008
Messages
799
Location
Portage Escarpment
There is no fundamental disagreement, the discussion is about questions of tradeoffs, which engineers go back and forth on all the time.

The example that I like to use in this realm is - we have a conventional scanner and would like to "modify" the unit for use with computer-based scanning. In the old days we'd have disc-tapped it and that would have been all we needed to do. However with for example LSM the disc-tap approach is guaranteed to be less than ideal as we already know the result of passing LSM through an FM demodulator. Why wouldn't we just use a $20 SDR for this? For one reason we observe that many such RXs have RF front ends superior to the SDRs - vastly so in some cases.

So we add an additional conversion stage to the scanner such that the final IF is within the PC soundcard range. At this point we could have attempted to build a hardware quadrature downconverter such A 455 KHz IF Downconverter for Digital Radio Reception (which generates I and Q in hardware and requires both soundcard L and R channels for one radio). Or we just simply connect our low-KHz IF signal directly from the scanner to the sound card. This still leaves one of the two channels in our sound card free for any other use.

Just to make the example concrete, the IF signal is taken from the scanner at ~24 KHz. The sound card sampling rate is set to 96 KHz, which limits the max. allowable signal at 48 KHz. The digitized IF stream is a real signal and is converted to complex (I/Q) by zero stuffing the Q values as previously mentioned (we could just as well stuff the zeros in the I's with no change in the system other than the random starting phase is changed to a different random value). Different numbers could be used, but the values here are the defaults used in OP25's "soundcard IF" mode

As I said, it's not just "as easy as that"...
Correct, it does require a few manipulations - all elementary DSP operations inside the PC. The tradeoff in the example is no need for the external quadrature hardware and it halves the number of needed audio ports

No, it would not contain all of the information from the original signal. Your low pass filter does not have zero Hertz wide transition bands - it's not a brick wall filter. You will end up keeping some small amount of your mirror signal as well as losing some of your original signal.
100% true, in theory. In practice our filters only need only be as good as the lowpass antialias filter ahead of the A/D, on the high side, and on the low side the DC spike (in Nyquist zone 1 anyway) would tend to swamp any differences between theory and practice.

It also has the property of doubling the data rate. Now running a bunch of VCOs ends up using twice the CPU that it should...

again 100% correct. In our example though there is never more than one VCO

Max
 
Status
Not open for further replies.
Top