Direct sampling to bandwidth output, how done?

Main forum to discuss RTL-SDR related topics.
tustinfarm
Posts: 6
Joined: Wed Jan 29, 2020 12:18 am

Direct sampling to bandwidth output, how done?

Post by tustinfarm » Sat Aug 01, 2020 3:17 pm

This is fairly deep technical question that applies to all SDRs, purely my curiosity, posting on the chance there is an SDR expert out there who can answer it in a simple manner, or post a hyperlink...

I have always wondered how the raw ADC samples in the RTL-SDR dongle (28.8 megasamples/second?) are processed and downsampled to the lower rates needed to transfer data out of the dongle to the PC software for a given bandwidth setting. In other words, a 2 MHz bandwidth setting requires a lot more bits/second from the USB connection than a 1 MHz setting, but how exactly is the original raw data from the ADC sampling transformed in the dongle? Is a FFT done, followed by filtering at the selected the bandwidth, then a reverse transform? Or some kind of mathematical averaging on the entire stream to downconvert it?

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

Re: Direct sampling to bandwidth output, how done?

Post by hotpaw2 » Mon Aug 03, 2020 3:44 pm

The mathematically correct solution is to use a perfect band-limiting anti-aliasing or low-pass filter before decimation or interpolation. In reality, no filter is perfect. So an anti-aliasing filter should have a stop band attenuation below the radio's desired noise floor at and above the new downsampled sample rate.

Anti-alias filtering can be implemented in software or hardware by many different methods, including using a high-order IIR filter, or using a windowed Sinc or computer optimized FIR filter. An IIR is usually implemented by sections of recursive arithmetic (biquads, corresponding to sections of analog LC filters). A IIR works similar to averaging, but due to feedback and multiple sections, is a lot smoother in the frequency domain. A FIR filter can be implemented by straight convolution (a lot of vector arithmetic), perhaps using a polyphase filter bank or Farrow interpolator for each set of FIR filter coefficients. or by overlap-add/save FFT/IFFT fast convolution for greater efficiency. There are other solutions including CIC filters and incremental multi-rate filtering and downsampling (reducing the sample rate in steps).

For fractional sample rate ratio changes, one can also upsample before downsampling, but I prefer polyphase interpolation methods to upsampling as more computationally efficient.

Band-pass filtering plus under-sampling can also be used for downsampling a tuned spectrum slice. But, more commonly, heterodyning down to complex or IQ baseband before low-pass filtering seems to be a more efficient and commonly implemented algorithm.

qrp
Posts: 53
Joined: Wed May 22, 2019 11:16 pm

Re: Direct sampling to bandwidth output, how done?

Post by qrp » Tue Sep 01, 2020 10:10 pm

hotpaw2 wrote:
Mon Aug 03, 2020 3:44 pm
Anti-alias filtering can be implemented in software or hardware by many different methods
Anti-alias filtering can be done in hardware only for analog signal (before ADC). This is impossible in software (in digital domain after ADC output). The only way is to apply anti-alias filter to the analog signal before ADC input.

For example you can use low-pass filter before ADC. If you don't apply anti-alias filter, you will get aliasing on the ADC output for frequency components above Fs/2 and you cannot remove it in digital domain, because there is no way to distinguish aliased components from real components.


RTLSDR ADC running at 28.8 MHz, so the ADC output bandwidth is 14.4 MHz. So, there is needs LPF with about 14 MHz cut-off. But RTLSDRv3 uses LPF for 30 MHz or something like that, so you can listen stations above 14 MHz through aliases. If you want to eliminate aliasing effect there is needs to add external LPF or BPF filter on the RTLSDR dongle input for specific frequency band. Just make sure that your filter pass band doesn't intersects with 14.4 MHz boundary.

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

Re: Direct sampling to bandwidth output, how done?

Post by hotpaw2 » Thu Sep 10, 2020 9:54 pm

qrp wrote:
Tue Sep 01, 2020 10:10 pm
Anti-alias filtering can be done in hardware only for analog signal (before ADC). This is impossible in software (in digital domain after ADC output). The only way is to apply anti-alias filter to the analog signal before ADC input.
If you decimate in software, and the sampled signal has a bandwidth higher than the new target sample rate, then it is required to do anti-alias filtering in software. Thus software filtering has to be possible (DSP IIR or FIR typically).

Whether anti-aliasing filtering is required in hardware before sampling depends on the bandwidth of the analog signal. A narrowband signal from a signal generator may not need it. But, yes, typical RF signals require filtering before sampling.

qrp
Posts: 53
Joined: Wed May 22, 2019 11:16 pm

Re: Direct sampling to bandwidth output, how done?

Post by qrp » Wed Oct 07, 2020 3:41 am

hotpaw2 wrote:
Thu Sep 10, 2020 9:54 pm
If you decimate in software, and the sampled signal has a bandwidth higher than the new target sample rate, then it is required to do anti-alias filtering in software. Thus software filtering has to be possible (DSP IIR or FIR typically).
Antialias filter can be done IN ANALOG ONLY. It cannot be done in digital domain, because if you don't apply antialiasing filter before ADC, then ADC output will be corrupted with aliases and there is no way to filter something, because aliases already folded into ADC bandwidth, so they cannot be removed anymore. And there is no way to distinguish it from real signals.

IIR cannot remove aliases, FIR cannot remove aliases. There is no way to remove aliases on DSP. If aliasing already happens, remove aliases is impossible at all.

In order to prevent aliasing, antialias filter should be applied BEFORE ADC, ON ANALOG SIGNAL SIDE.

Software filter working with digital ADC output, so there is NO WAY TO APPLY ANALOG ANTIALIAS FILTER IN SOFTWARE.
hotpaw2 wrote:
Thu Sep 10, 2020 9:54 pm
Whether anti-aliasing filtering is required in hardware before sampling depends on the bandwidth of the analog signal. A narrowband signal from a signal generator may not need it. But, yes, typical RF signals require filtering before sampling.
Any ADC requires analog filtering on the input in order to prevent aliasing. Because aliasing happens inside ADC.

If you don't apply analog filtering on the ADC input, ADC will produce aliases and it cannot be removed anymore. Filters cannot remove aliases if they are already present. Filter can help before aliasing which happens inside ADC.

The only way to eliminate aliasing is to remove frequency components which cannot fit into ADC bandwidth, it can be done on analog side only, before ADC input. It is impossible in software. ANALOG ONLY with no exception!

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

Re: Direct sampling to bandwidth output, how done?

Post by hotpaw2 » Thu Oct 08, 2020 7:03 pm

Sorry. That's incorrect. Maybe you didn't read the fine print in your textbooks.

Anti-alias filtering in software is quite common. This filtering should be done in software (or FPGA gateware) any time the sample rate is reduced to below the previous sample rate (for spectrum or signals that potentially fill the bandwidth of the previous sample rate).

And hardware anti-alias filtering in analog hardware is not needed for spectrum that has a guaranteed narrow bandwidth (from a high quality signal generator, for instance). Only for sampling spectrum that potentially includes aliasing RF signals. Even under-sampling can be done for narrow-band signals higher in frequency than the sample rate (although clock jitter noise will increase).

I've done both, in the hardware lab, and in software in working SDR apps.

qrp
Posts: 53
Joined: Wed May 22, 2019 11:16 pm

Re: Direct sampling to bandwidth output, how done?

Post by qrp » Fri Oct 09, 2020 9:30 pm

hotpaw2 wrote:
Thu Oct 08, 2020 7:03 pm
Sorry. That's incorrect. Maybe you didn't read the fine print in your textbooks.
Sorry, but you're wrong.

You can found some of my software for SDR receivers, transceivers and vector network analyzers, include firmware and apps here, on rtl-sdr site and on github. I'm told you that thing not because I read it somewhere, but because I know it very well. I read a lot of DSP literature and wrote my own DSP code. So, I know what I'm talking about.


Analog signal has infinite bandwidth, it is not discrete, but continuous. This is why you're always needs to put analog filter on ADC input. You cannot replace analog LPF on ADC input with digital signal processing.

You're just don't realize what digital signal processing is. DSP working with discrete signal. It cannot fix issue related to analog continuous signal with infinite bandwidth.

ADC performs conversion from continuous analog signal with infinite bandwidth into discrete digital signal with limited bandwidth SR/2. This is why it is very important to remove all frequencies from SR/2 and above from analog signal before it come to ADC input. If you don't do it, all these frequencies will be folded into first Nyquist zone. This is what aliasing is.

For example, if ADC has sample rate 10 MHz, then ADC bandwidth is 5 MHz. It means that any signal above 5 MHz will be folded into frequency range 0....5 MHz. And if you put 7 MHz carrier on the ADC input, you will see 3 MHz carrier on the ADC output. And there is no way to distinguish if this is real 3 MHz or 7 MHz mirror. Both will be seen as 3 MHz, so software will be unable to distinguish them.

DSP cannot remove aliasing from analog-to-digital conversion because aliasing already happens in ADC which works before DSP, so there is no way to remove it on DSP side

hotpaw2 wrote:
Thu Oct 08, 2020 7:03 pm
Anti-alias filtering in software is quite common. This filtering should be done in software (or FPGA gateware) any time the sample rate is reduced to below the previous sample rate (for spectrum or signals that potentially fill the bandwidth of the previous sample rate).
Yes filtering in software is very common. But ADC filtering for analog continuous signal with infinite bandwidth cannot be done in software!

In software you can do filtering for a discrete signal with already limited bandwidth. But not for analog signal which is come to ADC input.

You cannot perform signal processing for analog signal before ADC. If you don't do filtering BEFORE ADC, you will lose key information about signal. Aliasing will happens inside ADC and software get already aliased discrete signal, so it's too late to do something in software after ADC. Filtering should be done on analog side, before aliasing.

When you do decimation in DSP, you're working with discrete signal. Decimation leads to lower bandwidth conversion, so it also needs to apply LPF in order to prevent folding frequencies above new sample rate/2 into new first Nyquist zone. This LPF is antialias filter. But it can be done on DSP side, because input signal is already discrete. It is not analog, like in case of ADC.

Don't confuse antialias filter for decimation with antialias filter for ADC. Antialias filter for decimation can be done in digital domain. But antialias filter for ADC needs to be done in analog domain. Just because ADC has analog input, not discrete like in case of decimation.
hotpaw2 wrote:
Thu Oct 08, 2020 7:03 pm
And hardware anti-alias filtering in analog hardware is not needed for spectrum that has a guaranteed narrow bandwidth (from a high quality signal generator, for instance). Only for sampling spectrum that potentially includes aliasing RF signals. Even under-sampling can be done for narrow-band signals higher in frequency than the sample rate (although clock jitter noise will increase).
Antialias filter is the filter that needs to guarantee that analog signal spectrum don't exceeds ADC bandwidth. If there is no analog antialias filter on the ADC input, then there is no guarantee that input signal "has a narrow bandwidth".

Antialias filter is a filter "that has a guaranteed narrow bandwidth". In case of ADC, this is analog filter and you cannot do it on DSP side. Just because there is analog signal on the ADC input and software processing is not applicable for analog signal. Analog signal should be filtered with analog filter.
hotpaw2 wrote:
Thu Oct 08, 2020 7:03 pm
I've done both, in the hardware lab, and in software in working SDR apps.
I think you're just used someone other code and didn't wrote your own DSP code. And this is the reason why you don't understand how it works. This is obvious from your message that ADC antialias filter can be done with DSP. People who knows DSP cannot say such thing. Because this is impossible :)

Just try to put signal generator directly to your lab ADC with no antialias filter. Put frequency above SR/2, where SR is ADC samle rate. And try to remove aliasing in digital domain as you said possible. This is impossible.

For example if your ADC works with 100 MHz sample rate, then ADC bandwidth is SR/2=100/2 = 50 MHz.

Try to put for example 70 MHz and 30 MHz carriers from a signal generator to the ADC input with no antialias filter. Due to aliasing you will see both carriers on 30 MHz at the ADC output. Now try to remove 70 MHz part from 30 MHz part in DSP. This is just impossible.

At the ADC output both carriers 70 MHz and 30 MHz will be seen as 30 MHz. So software cannot do something, because it cannot distinguish 30 MHz from real 30 MHz and 30 MHz from real 70 MHz.

The only way to remove 70 MHz and keep 30 MHz in such case is to put analog antialias filter - LPF with cut off at about 45-50 MHz. In such case 70 MHz will be removed on analog side and ADC will not produce 30 MHz alias for 70 MHz.

There is no way to do it with DSP.



You can also use analog BPF (band pass filter) instead of analog LPF on ADC input in order to receive signals with frequency above ADC bandwidth.

For example, if your ADC has 100 MHz sample rate, you can receive 120 MHz radio station. Just use BPF with 120 MHz center frequency and you can receive station through aliases on 20 MHz.

This technique known as "undersampling".

But these LPF and BPF should be analog before ADC input. This is impossible to do it in digital domain. DSP cannot help here.

If you don't apply analog LPF or BPF on analog ADC input, you will see 20 MHz, 80 MHz, 120 MHz, 180 MHz, etc all the same on 20 MHz at ADC output and you cannot fix it with software filter. Because it can be done on analog input signal and it requirest analog filter only. Software cannot filter analog signal.

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

Re: Direct sampling to bandwidth output, how done?

Post by hotpaw2 » Sat Oct 10, 2020 1:47 am

qrp wrote:
Fri Oct 09, 2020 9:30 pm
You can found some of my software for SDR receivers, transceivers and vector network analyzers, include firmware and apps here, on rtl-sdr site and on github.
Good for you. Note that I also have DSP software on GitHub, as well as multiple DSP and SDR apps in the iOS App Store, and a few (long ago) issued U.S. patents on hardware systems that included DSP capability. HP Labs had plenty of test gear, signal generators, and spectrum analyzers (in the good old days, before HP divided up into a pile of smaller outfits.)

You seem to think all signals are wide-band. That's true in many cases, but not all (for a given finite noise floor).

And some signals are wide-band, but are still partially usable without hardware RF front-end anti-alias filtering. For instance plenty of people use RTL-SDR v.3's in direct sampling mode, and those devices do not anti-alias out signals above and/or below 14.4 MHz. But the RTL2832 still does later anti-alias filtering to reduce the sample rate from 28.8M to 2400k or 300k IQ for USB transfer for instance to prevent a ton more aliases from overlapping. And then SDR software might do further anti-alias filtering before reducing the sample rate to 48k for AM demodulation, etc., or to 12k for FT8, etc.

e.g. The problem isn't just with any initial aliasing before the ADC, but also whether even more aliasing can occur during decimation or downsampling. The latter requires software (or digital hardware) anti-alias filtering to prevent even more aliases from piling up or folding into the resulting sampled spectrum.

qrp
Posts: 53
Joined: Wed May 22, 2019 11:16 pm

Re: Direct sampling to bandwidth output, how done?

Post by qrp » Sat Oct 10, 2020 11:42 pm

hotpaw2 wrote:
Sat Oct 10, 2020 1:47 am

And some signals are wide-band, but are still partially usable without hardware RF front-end anti-alias filtering. For instance plenty of people use RTL-SDR v.3's in direct sampling mode, and those devices do not anti-alias out signals above and/or below 14.4 MHz. But the RTL2832 still does later anti-alias filtering to reduce the sample rate from 28.8M to 2400k or 300k IQ for USB transfer for instance to prevent a ton more aliases from overlapping. And then SDR software might do further anti-alias filtering before reducing the sample rate to 48k for AM demodulation, etc., or to 12k for FT8, etc.
don't confuse antialias filtering for decimation and antialias filtering for analog-to-digital conversion.

You're said that ADC antialias filter is possible in DSP. This is wrong. This is impossible. ADC antialiasing should be done by applying filter before it come to ADC and this can be done with analog filter only! This is how our discussion started.

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

Re: Direct sampling to bandwidth output, how done?

Post by hotpaw2 » Sun Oct 11, 2020 3:35 pm

The question was about processing after direct sampling, not before. Not sure where you got the idea I was discussing anything before direct sampling. On after. And after direct sampling, anti-alias filtering in digital logic or firmware is required if the ADC downsamples the data inside the RTL2832 chip for USB transfer, in order to avoid potential further aliasing. And the ADC chip is reducing the front end sample rate from 28.8 MHz (or some multiple thereof for sigma delta) to the USB rates of 240 to 2400 ksps for USB transfer. Thus the RTL2832 chip is anti-alias filtering after the ADC to do the downsampling needed for the USB transfer rates selected. Which I think was the original question. Not your sidetracking.

Post Reply