# Spectrum Analysis with FFT plotting

**URL:** <https://www.ruby-forum.com/t/spectrum-analysis-with-fft-plotting/169183>\
**Category:** GNU Radio\
**Created:** [May 30, 2009, 11:21pm UTC](https://www.ruby-forum.com/t/spectrum-analysis-with-fft-plotting/169183 "2009-05-30T23:21:36Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![ujala](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/u/cc9497/32.png) [@ujala](https://www.ruby-forum.com/u/ujala)\
**Post date:** [May 30, 2009, 11:21pm UTC](https://www.ruby-forum.com/t/spectrum-analysis-with-fft-plotting/169183/1 "2009-05-30T23:21:36Z")

</div>

hi,I have some raw data samples of FM from USRP. I now want to take  
their  
FFT and analyze the spectrum to see whether the data that I have  
captured is  
valid or not. My question is that when plotting FFT in MATLAB should I  
take  
the range of frequencies from 0 - 10 MHz (as the signal has been shifted  
to  
IF of 5.75 MHz) or the range of frequencies should be 88 - 100 Mhz.

Though, No matter what range I take I always see a peak right in the  
middle  
of my frequency range:

e.g. if I keep the range at 0 -10 MHz, I’ll get a peak at 5.0 MHz  
when I keep it at 88MHz - 108Mhz I get the peak at 98 MHz

Why is this so?

---

<div class="post-metadata">

**Author:** ![ujala](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/u/cc9497/32.png) [@ujala](https://www.ruby-forum.com/u/ujala)\
**Post date:** [May 31, 2009, 12:11am UTC](https://www.ruby-forum.com/t/spectrum-analysis-with-fft-plotting/169183/2 "2009-05-31T00:11:18Z")

</div>

Ujala

I don’t know what you mean by the range of frequencies? I’m guessing  
you’re just referring to the x-axis labels in Matlab. That would  
depend on your sampling frequency after the decimation and the number  
of points that you use for the FFT. Let’s say your sampling frequency  
is 16Msps and you’re taking 1s of data for the FFT. Your x-axis will  
look as follows:

-16000000/2:1:(16000000/2)-1 or  
-samp\_freq/2:samp\_freq/no\_samples:(samp\_freq/2)-1

If you get a peak in the middle of your data, then you have a DC  
offset somewhere.

Sebastiaan

---

<div class="post-metadata">

**Author:** ![ujala](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/u/cc9497/32.png) [@ujala](https://www.ruby-forum.com/u/ujala)\
**Post date:** [May 31, 2009, 9:57am UTC](https://www.ruby-forum.com/t/spectrum-analysis-with-fft-plotting/169183/3 "2009-05-31T09:57:33Z")

</div>

Hi,  
Thanks for your reply Sebastiaan,

I am taking some data samples with a piece of code in Windows that takes  
the  
raw data samples. Now, I want to analyze the samples, whether my data is  
correct or not. For this, I tune to the FM frequency of 106.2 MHz (a  
radio  
station) and pick some data samples.

I arbitaraily picked 956 samples and took their FFT, kept my x-axis  
label  
between 105 - 108 MHz and made a plot in MATLAB:  
[![](http://i695.photobucket.com/albums/vv318/ujalaqasim/fftplotWin.jpg) ](http://i695.photobucket.com/albums/vv318/ujalaqasim/fftplotWin.jpg)

The decimation rate is 250, so my sampling frequency in this case is  
64Msps/250 = 256KHz  
Now, shouldn’t I be seeing a peak at 106.2 MHz? Instead at 105MHz? There  
is  
no station at 105MHz.

For comparison I also took some data samples from GNURadio for the same  
frequency with Octave and plotted them in MATLAB:  
[![](http://i695.photobucket.com/albums/vv318/ujalaqasim/GNURadioSamples.jpg) ](http://i695.photobucket.com/albums/vv318/ujalaqasim/GNURadioSamples.jpg)

Even here I don’t see a peak at 106.2MHz

I also used the values that you told me:  
-samp\_freq/2:samp\_freq/no\_samples:(samp\_freq/2)-1  
as my decimation rate is 250, my sampling frequency is: 256kHz  
and the no. of samples I am using is 956  
so my range is: -128kHz:256kHz/956:127.999kHz

Here is the plot, again taken from Windows:  
[![](http://i695.photobucket.com/albums/vv318/ujalaqasim/samp_freq.jpg) ](http://i695.photobucket.com/albums/vv318/ujalaqasim/samp_freq.jpg)

Now I don’t see any peak at 106.2MHz in any of these plots. What could  
be  
the problem?

---

<div class="post-metadata">

**Author:** ![ujala](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/u/cc9497/32.png) [@ujala](https://www.ruby-forum.com/u/ujala)\
**Post date:** [June 1, 2009, 11:37am UTC](https://www.ruby-forum.com/t/spectrum-analysis-with-fft-plotting/169183/4 "2009-06-01T11:37:15Z")

</div>

Ujala

You have to use usrp.tune(self.u, 0, self.subdev,106.2e6). This will  
mix whatever is at 106.2MHz down to DC. set\_rx\_freq is used to  
control the DDC in the USRP and only works from -32e6 to 32e6MHz.

The tune function first uses the mixer in the TVRX db to mix the  
signal down to 5.75MHz (the TVRX db that I’m using mixes the signal  
down to 44MHz). If you’re using your db, the signal gets sampled and  
sits at 5.75MHz. The DDC now needs to mix it down to DC. The tune  
function takes care of both of these functions for you.

Try to capture a signal by setting decimation to 250 and tuning to  
106.2MHz. The result should be a signal shaped like a bell that  
nearly spans the entire length of the plot.

Sebastiaan

---

<div class="post-metadata">

**Author:** ![ujala](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/u/cc9497/32.png) [@ujala](https://www.ruby-forum.com/u/ujala)\
**Post date:** [June 2, 2009, 3:33pm UTC](https://www.ruby-forum.com/t/spectrum-analysis-with-fft-plotting/169183/5 "2009-06-02T15:33:06Z")

</div>

Hi,  
I am now getting the following plot, when I set my target\_freq to 89MHz  
(another radio station), with center\_freq in set\_rx\_freq() function to  
-5.75:  
[![](http://i695.photobucket.com/albums/vv318/ujalaqasim/bell.jpg) ](http://i695.photobucket.com/albums/vv318/ujalaqasim/bell.jpg)  
The decimation rate is 250 and the sampling frequency is at 256ksps.  
I am getting a bell shape but it is not taking the entire length of the  
plot. What could be wrong?

---

<div class="post-metadata">

**Author:** ![ujala](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/u/cc9497/32.png) [@ujala](https://www.ruby-forum.com/u/ujala)\
**Post date:** [May 31, 2009, 2:03pm UTC](https://www.ruby-forum.com/t/spectrum-analysis-with-fft-plotting/169183/6 "2009-05-31T14:03:12Z")

</div>

Ujala

With a decimation of 250, your USRP will only provide you with the  
samples from -128kHz to 128kHz-1. So, unless your station of interest  
is very close to DC, you won’t see it on an FFT of your data. If your  
signal is at an IF of 5.75MHz, you will need to sample at 16Msps in  
order to digitise it.

Try an experiment. Tune your USRP to 106.2MHz (so that your radio  
station now sits at DC). Set the decimation to 250  
(Fs=64e6/250=256ksps). Now capture 1s of data and do a 256000 point  
FFT in Matlab. You should now see a nice FM signal at DC.

You can use the usrp\_wfm\_rcv.py gnuradio-examples script to see what  
happens in the FM band where you are.

Sebastiaan

---

<div class="post-metadata">

**Author:** ![ujala](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/u/cc9497/32.png) [@ujala](https://www.ruby-forum.com/u/ujala)\
**Post date:** [June 2, 2009, 4:03pm UTC](https://www.ruby-forum.com/t/spectrum-analysis-with-fft-plotting/169183/7 "2009-06-02T16:03:36Z")

</div>

Ujala

That looks like an FM signal at DC with another FM signal about 150kHz  
away. The modulating signal of the FM wave in your picture is  
probably speech. If you capture another set of samples using the same  
procedure, but with rock/rap/hip hop music, etc. (in other words  
anything with a lot of spectral content), you should see a better bell  
shape. The signal should then sit between about -50kHz and 50kHz on  
your plot. FM’s maximum frequency deviation is 75KHz either way of  
the carrier, so music should give you something close to that (hence  
the -50kHz to 50kHz). Hope this helps.

Regards

Sebastiaan
