IQ to frequency spectrum with FFT - half of bandwidth?

Show off any of your RTL-SDR or cheap SDR related projects.
Post Reply
MrMarian
Posts: 2
Joined: Sat Mar 02, 2019 11:37 am

IQ to frequency spectrum with FFT - half of bandwidth?

Post by MrMarian » Sat Mar 02, 2019 12:03 pm

Hi friends.
Recently I was discovered an RTL-SDR dongle. This is awesome device!
Now i'm trying to write my own software which gets IQ signal from dongle, and present it as frequency spectrum.
I can't resolve one thing.
Im setting frequency by calling rtlsdr_set_center_freq to eg. 100000000Hz (100MHz) with 2048000 samplerate.
In SDR# i see spectrum from about 99MHz - 100MHz(center freq) - 101MHz, so the spectrum has about 2MHz (2,048M samplerate).

In my program i'm getting from rtl-sdr IQ byte array in format: IQIQIQ... where values are unsigned, so now i'm creating array of complex samples in this way:
samples.I = (data[i*2]-127.5)/127.5; //-1 to 1
samples.Q = (data[i*2+1]-127.5)/127.5; //-1 to 1

Now this samples are fiddled into FFT alhorithm, and as result i have frequency spectrum.
But this spectrum not looks like i was expected. My center freq is 100MHz in 2,048M samplerate, so i want to see 99-101MHz as a result of FFT (like in SDR#), but what i'm getting is only half of spectrum i gess: 99-100MHz and second half is mirrored, so finnally it is something like:
99MHz-100Mhz-99MHz spectrum. What about 100-101MHz part? How to get it? SDR# can do this if I set center frequency to 100MHz.
I've tried to find response for my question, but i can't, so i decided to ask question here :oops:
Thanks

hotpaw2
Posts: 101
Joined: Sat Jan 14, 2017 11:07 pm
Contact:

Re: IQ to frequency spectrum with FFT - half of bandwidth?

Post by hotpaw2 » Sat Mar 02, 2019 4:46 pm

Make sure you are sending both I and Q channels to a single complex-to-complex FFT.
Use N samples of I and N samples of Q to create N complex samples for a length N FFT.
Don't use 2 real-only FFTs or a complex FFT with all the imaginary components zero, instead of Q data.
(Read up on complex numbers, complex multiplication, and Euler's identity, if needed).

For a length N complex FFT with the RTL-SDR set to a frequency of f0 and sample rate of sr :
you should see spectrum from f0 to f0+(sr/2) in FFT complex result bins from 0 to N/2,
and spectrum from f0-(sr/2) to almost f0 in complex result bins from N/2 to N-1.
If the imaginary components of the FFT input are not zero, then the FFT results should not be complex conjugate mirrored.

Make sure to take the magnitude (abs) of the complex results to view spectral power.
For ease of visualizing the FFT results, I usually do an fftshift after the FFT,
which rotates the data to center f0 at bin N/2.

MrMarian
Posts: 2
Joined: Sat Mar 02, 2019 11:37 am

Re: IQ to frequency spectrum with FFT - half of bandwidth?

Post by MrMarian » Sat Mar 02, 2019 9:03 pm

Thank you hotpow2!
I finally got a full spectrum with you advices!

In my first post i wrote the totally untruth.
As you say: i need fftshift to properly reorder FFT result array, here is visualisation for your words:
Figure 5: https://www.gaussianwaves.com/2015/11/i ... -fftshift/

Here was my mistake, and fftshift resolved the problem. I will digg into other topics you mentioned.
Thank you very much!

Post Reply