## Trying to wrap my head around FFT and SDR...

Started by 12 months ago●8 replies●latest reply 11 months ago●281 viewsHi there!

First-time poster here and very new to DSP and the like, so please excuse any ignorance and falsities.

Pilots use a sequence of radio key-on's within a time period to enable runway lighting from the air at untowered airfields. I'm working on building something similar, however, to open my garage door from a UHF CB radio using a HackRF One SDR. It's a toe-in-the-water for SDR and the associated signal processing for me.

I've written a small program using the libhackrf library and fttw to isolate the signal however I'm having trouble isolating the signal to within the channel bandwidth. At its simplest, I've taken my RF samples on my centre frequency and have performed a DFT with FFTW_FORWARD and FFTW_ESTIMATE. I determine my bin size as __Sample Rate / Number of Samples__ and the frequency of the first bin as __Center Frequency - (Sample Rate / 2)__.

I've then used this to attempt to create a bandpass filter of sorts by determining the starting and ending bin as a function of __(Center Frequency - (Bandwidth /2)) - First Bin) / Bin Size)__ the resultant indices of which make sense given the centre frequency.

I then attempt to determine the amplitude of the signal by the cumulative sum of __(Real^2 + Imaginary^2) __of the FFT output within the bounds of the First and Last Bin, then average over the range.

My challenge lies in that, whilst the output of the amplitude changes with broadcast on these frequencies, they don't change discernably over the entire CB radio range, which is only space 1MHz, and there is no discernable difference observable between neighbouring channels which is the spacing I'm trying to filter.

I'm running the device at a sample rate of 20MHz and believe 12.5KHz steps should be easily filterable on the device. I'd really appreciate some advice and direction here (or even just another pair of eyes) to help point me in the right direction. I've published my code here: https://gist.github.com/alexanderturner/4db1ab2645...

I'll +1 that it's not entirely clear what you're doing so questions will be asked. On the other hand, your description of your processing steps sounds reasonable.

Are you saying that when you transmit there's energy everywhere rather than just in the band you're expecting? If so, and there's no input filter to reject out-of-band energy, you may just be seeing aliased energy from other channels. It is, however, difficult to tell what your receiver chain looks like from your description.

To your other point, if I understand it correctly, even if the CB signal is unmodulated, or partially modulated, or whatever, you'll detect the energy using your sum-of-bins approach. The sum will always be proportional to the detected power level, and most transmitters radiate a reasonably constant average power level, so summing the bins of the channel of interest should detect the power, regardless of the state of the spread due to modulation.

I hope that helps a little. For the most part it sounds like you're doing sensible things with the signal processing.

Alex,

Are you designing a receiver for the signal? What do you mean by "isolating the signal"? Do you mean you need to attenuate nearby signals? Can you be more specific about this? What is the center frequency and bandwidth of your signal?

regards,

Neil

- "I determine my bin size as __Sample Rate / Number of Samples"__

- "and the frequency of the first bin as __Center Frequency - (Sample Rate / 2__)"

I may understand your first line but can't understand your second line. DFT range is between DC and Fs(sampling rate) or Fs/2. The first bin is dc unless it is dc centered by remapping of bins.

Have you brought your signal down to dc?

With DFT you can just discard the out of band bins. This is equivalent to filtering.

Hi Alex,

as you mentioned Real an Imaginary parts I presume that your signal is sampled in complex mode (I ans Q channels). Therefore the effective frequency range of your FFT analys is [-Fs/2, Fs/2[ (Fs standing for Sample Rate).

To be able to help you, we need to know how the RF front end of your receiver works :

Is it a zero IF architecture ? (meaning that the center frequency is translated down to DC)

What is exactly the largest bandwidth of the signal you want to detect ?

Could you as well precise the time-domain characteristics of this signal ?

Finally did you translate your functional objective into requirements on the signal processing function you'd like to develop ?

regards

Joël

Hi All and thanks for your replies and expertise here - it's immensely helpful.

@Kaz, you mentioned the DC component and this is a new concept for me. Perhaps what I'm best trying to understand here is *what *is being sent to me from the SDRs frontend and what's actually happening when a center frequency is being set on the radio. From what I understand, the sample size (which is 131,072 @ 20Mhz) represents the frequency spectrum between the center frequency and the bandwidth of the radio (plus some function of the Fs?). This has been my logic in trying to determine the start and end bin for the DFT but I'm not sure (i don't) fully grasp this concept.

If the first bin is DC, what is the last signal and whats does say, bin 100 represent? Bin 1000?

A bit more about this signal. It's an analogue FM-modulated radio signal that's used for CB radio speech. The band is largely unused around me and there isn't a huge amount of background noise. The channel bandwidth is 12.5Khz, around the 470MHz range. In Australia (home) it's just known as UHF CB. I'm trying to isolate a single channel such that I can detect key-ons (someone transmitting) on a channel. As it stands, the program I shared will activate (i.e. I can detect noise) on every single channel in the spectrum (2MHz).

The radio I'm using is based on a max2837 and I'm unsure if it's 0-IF or not and it's dependent on the implementation, which doesn't seem overly well documented (the HackRF One). I know this isn't the forum for particular hardware support, but I'm still trying to get my head around the DFT itself and what exactly is presented by the hardware the output of the transform.

Thanks again for your interest and contribution

Let us focus on DFT: assuming your input is real only (not I/Q) then DFT outputs at bin resolution of Fs/N (Fs is sampling rate, N is FFT size).

The first bin is dc content 0*Fs/N, next bin is 1*Fs/N, next bin is 2*Fs/N...etc.

Expect coverage from dc to Fs/2 and there-after it mirrors till Fs

If your RF signal is outside Fs range then it will alias somewhere depending on math between Fs & Frequency.

So to have meaningful DFT you either:

-have Fs high enough to sample RF (this is not practical in many cases).

-Accept aliasing (undersampling). you need to know where your RF ends up.

-Bring it down to zero or within your chosen FS/2 range by mixing. (Undersampling can just do that for you at no extra cost).

Thanks @kaz,

I guess where I'm getting a little stuck (and perhaps it's slightly off-topic here) is in how SDRs present signal as 'raw rf'. Is the RF input (or, the input to my FFT) likely to be the entire range of the SDR (say some 100Hz to 6GHz) or some function of the "centre frequency" that the SDR can be tuned to? This obviously doesn't make sense, given the bin width is a function of sample rate and size (maxing it at the sample rate). Surely SDR functions aren't dependent on aliasing a _huge_ range of RF to the order of multiple Ghz across a 20MHz~ range?

I'm presently of the belief that it's of the latter (SDR centre frequency), where the 'bandwidth' is a function of the sample rate (Fs) and the sample size is a function of precision.

Therefore, if an SDR is 'centred' or tuned to 450Mhz say, 0*Fs/N actually represents 450MHz? In order to center this in the FFT do we realistically want to 'tune' the radio such that our target frequency becomes the Nyquist frequency?

Sorry if this is confusing, I'm trying to articulate this in a means I can make sense of and _think_ I'm talking about mixing but unsure.

The problem is that you are not familiar with either your radio setup or receiver principles. In the range of 100Hz to 6GHz you are having all sorts of signals from radio broadcast, TV broadcast, mobile phones...etc.

A possible receiver chain could be as follows:

1) Down-convert signal from its frequency centre to dc (mixer)

2) Apply a low pass analogue filter to only pass your signal, now at dc.

3) Sample at ADC at least twice highest edge of your down-converted signal. Usually sampling rate is much higher than twice.

4) Further digital filtering may be needed if analogue filter was relaxed.

5) apply fft. This will see signal center at dc bin if ideal.

Other tasks include clock recovery and frequency tracking. These could be done either in analogue domain or in digital domain.

You can directly visualise signal using spectrum analyser.