From 4bb749ce65a690dc646ad776f4bffb25cc41acc2 Mon Sep 17 00:00:00 2001 From: f4exb Date: Thu, 10 May 2018 22:17:39 +0200 Subject: [PATCH] Inf/Sup frequency shift scheme change to set bandwidth closer to device center frequency --- plugins/samplesource/bladerfinput/readme.md | 11 +- plugins/samplesource/hackrfinput/readme.md | 21 +- plugins/samplesource/plutosdrinput/readme.md | 13 +- plugins/samplesource/rtlsdr/readme.md | 13 +- plugins/samplesource/sdrplay/readme.md | 13 +- plugins/samplesource/testsource/readme.md | 11 +- .../testsource/testsourceinput.cpp | 9 +- sdrbase/dsp/decimators.h | 371 ++++++++---------- sdrbase/dsp/devicesamplesource.cpp | 60 ++- sdrbase/dsp/devicesamplesource.h | 5 + sdrbase/dsp/inthalfbandfiltereo.h | 48 +-- 11 files changed, 306 insertions(+), 269 deletions(-) diff --git a/plugins/samplesource/bladerfinput/readme.md b/plugins/samplesource/bladerfinput/readme.md index 94eea48b4..2f0e8f01e 100644 --- a/plugins/samplesource/bladerfinput/readme.md +++ b/plugins/samplesource/bladerfinput/readme.md @@ -72,9 +72,14 @@ The I/Q stream from the BladeRF ADC is downsampled by a power of two before bein Possible values are: - - **Cen**: the decimation operation takes place around the BladeRF Rx center frequency - - **Inf**: the decimation operation takes place around the center of the lower half of the BladeRF Rx passband. - - **Sup**: the decimation operation takes place around the center of the upper half of the BladeRF Rx passband. + - **Cen**: the decimation operation takes place around the BladeRF Rx center frequency Fs + - **Inf**: the decimation operation takes place around Fs - Fc. + - **Sup**: the decimation operation takes place around Fs + Fc. + +With SR as the sample rate before decimation Fc is calculated as: + + - if decimation n is 4 or lower: Fc = SR/2^(log2(n)-1). The device center frequency is on the side of the baseband. You need a RF filter bandwidth at least twice the baseband. + - if decimation n is 8 or higher: Fc = SR/n. The device center frequency is half the baseband away from the side of the baseband. You need a RF filter bandwidth at least 3 times the baseband.

7: Rx filter bandwidth

diff --git a/plugins/samplesource/hackrfinput/readme.md b/plugins/samplesource/hackrfinput/readme.md index 02e220dc5..8b9df7c7e 100644 --- a/plugins/samplesource/hackrfinput/readme.md +++ b/plugins/samplesource/hackrfinput/readme.md @@ -75,11 +75,7 @@ This is the HackRF device ADC sample rate in S/s. Use the wheels to adjust the sample rate. Left click on a digit sets the cursor position at this digit. Right click on a digit sets all digits on the right to zero. This effectively floors value at the digit position. Wheels are moved with the mousewheel while pointing at the wheel or by selecting the wheel with the left mouse click and using the keyboard arrows. Pressing shift simultaneously moves digit by 5 and pressing control moves it by 2. -

7: Rx filter bandwidth

- -This is the Rx filter bandwidth in kHz. Possible values are: 1750, 2500, 3500, 5000, 5500, 6000, 7000, 8000, 9000, 10000, 12000, 14000, 15000, 20000, 24000, 28000 kHz. - -

8: Decimation factor

+

7: Decimation factor

The device stream from the HackRF is decimated to obtain the baseband stream. Possible values are: @@ -90,6 +86,21 @@ The device stream from the HackRF is decimated to obtain the baseband stream. Po - **16**: divide device stream sample rate by 16 - **32**: divide device stream sample rate by 32 +

8: Baseband center frequency position relative the the HackRF Rx center frequency

+ + - **Cen**: the decimation operation takes place around the HackRF Rx center frequency Fs + - **Inf**: the decimation operation takes place around Fs - Fc. + - **Sup**: the decimation operation takes place around Fs + Fc. + +With SR as the sample rate before decimation Fc is calculated as: + + - if decimation n is 4 or lower: Fc = SR/2^(log2(n)-1). The device center frequency is on the side of the baseband. You need a RF filter bandwidth at least twice the baseband. + - if decimation n is 8 or higher: Fc = SR/n. The device center frequency is half the baseband away from the side of the baseband. You need a RF filter bandwidth at least 3 times the baseband. + +

9: Rx filter bandwidth

+ +This is the Rx filter bandwidth in kHz. Possible values are: 1750, 2500, 3500, 5000, 5500, 6000, 7000, 8000, 9000, 10000, 12000, 14000, 15000, 20000, 24000, 28000 kHz. +

10: Internal LNA gain

The LNA gain can be adjusted from 0 dB to 40 dB in 8 dB steps. diff --git a/plugins/samplesource/plutosdrinput/readme.md b/plugins/samplesource/plutosdrinput/readme.md index cc4507d74..11614c512 100644 --- a/plugins/samplesource/plutosdrinput/readme.md +++ b/plugins/samplesource/plutosdrinput/readme.md @@ -106,11 +106,16 @@ Use these buttons to confirm ("OK") or dismiss ("Cancel") your changes. The I/Q stream from the PlutoSDR is downsampled by a power of two by software inside the plugin before being sent to the passband. Possible values are increasing powers of two: 1 (no decimation), 2, 4, 8, 16, 32, 64. -

6: Decimated bandpass center frequency placement

+

6: Decimated bandpass center frequency position relative the the PlutoSDR Rx center frequency

- - **Inf**: Infradyne: the decimation takes place in the lower sideband - - **Sup**: Supradyne: the decimation takes place in the lower sideband - - **Cen**: Centered: the decimation takes place around the center + - **Cen**: the decimation operation takes place around the PlutoSDR Rx center frequency Fs + - **Inf**: the decimation operation takes place around Fs - Fc. + - **Sup**: the decimation operation takes place around Fs + Fc. + +With SR as the sample rate before decimation Fc is calculated as: + + - if decimation n is 4 or lower: Fc = SR/2^(log2(n)-1). The device center frequency is on the side of the baseband. You need a RF filter bandwidth at least twice the baseband. + - if decimation n is 8 or higher: Fc = SR/n. The device center frequency is half the baseband away from the side of the baseband. You need a RF filter bandwidth at least 3 times the baseband.

7: Antenna (input) connection

diff --git a/plugins/samplesource/rtlsdr/readme.md b/plugins/samplesource/rtlsdr/readme.md index cd0a60941..ebe304077 100644 --- a/plugins/samplesource/rtlsdr/readme.md +++ b/plugins/samplesource/rtlsdr/readme.md @@ -49,13 +49,16 @@ These buttons control the local DSP auto correction options: - **DC**: auto remove DC component - **IQ**: auto make I/Q balance. The DC correction must be enabled for this to be effective. -

4: Baseband center frequency position relative the center frequency

+

4: Decimated bandpass center frequency position relative the RTL-SDR center frequency

-Possible values are: + - **Cen**: the decimation operation takes place around the RTL-SDR center frequency Fs + - **Inf**: the decimation operation takes place around Fs - Fc. + - **Sup**: the decimation operation takes place around Fs + Fc. + +With SR as the sample rate before decimation Fc is calculated as: - - **Cen**: the decimation operation takes place around the BladeRF Rx center frequency - - **Inf**: the decimation operation takes place around the center of the lower half of the BladeRF Rx passband. - - **Sup**: the decimation operation takes place around the center of the upper half of the BladeRF Rx passband. + - if decimation n is 4 or lower: Fc = SR/2^(log2(n)-1). The device center frequency is on the side of the baseband. You need a RF filter bandwidth at least twice the baseband. + - if decimation n is 8 or higher: Fc = SR/n. The device center frequency is half the baseband away from the side of the baseband. You need a RF filter bandwidth at least 3 times the baseband.

4a: Transverter mode open dialog

diff --git a/plugins/samplesource/sdrplay/readme.md b/plugins/samplesource/sdrplay/readme.md index c955f62c1..8c99f42aa 100644 --- a/plugins/samplesource/sdrplay/readme.md +++ b/plugins/samplesource/sdrplay/readme.md @@ -75,13 +75,16 @@ You have the choice between various sample rates from 1536 to 8192 kHz. Some val Decimation in powers of two from 1 (no decimation) to 64. -

9. Center frequency position

+

9: Decimated bandpass center frequency position relative the SDRplay center frequency

-Relative position of center frequency of decimated baseband relative to the original: + - **Cen**: the decimation operation takes place around the SDRplay center frequency Fs + - **Inf**: the decimation operation takes place around Fs - Fc. + - **Sup**: the decimation operation takes place around Fs + Fc. + +With SR as the sample rate before decimation Fc is calculated as: - - Inf: infradyne i.e. in the lower half of original baseband: to be used with non zero IFs - - Cen: Centered i.e. around the center of the original baseband - - Sup: Supradyne i.e. in the upper half of original baseband + - if decimation n is 4 or lower: Fc = SR/2^(log2(n)-1). The device center frequency is on the side of the baseband. You need a RF filter bandwidth at least twice the baseband. + - if decimation n is 8 or higher: Fc = SR/n. The device center frequency is half the baseband away from the side of the baseband. You need a RF filter bandwidth at least 3 times the baseband.

10. Tuner gain mode

diff --git a/plugins/samplesource/testsource/readme.md b/plugins/samplesource/testsource/readme.md index 912a86bd4..8f64bffbd 100644 --- a/plugins/samplesource/testsource/readme.md +++ b/plugins/samplesource/testsource/readme.md @@ -56,11 +56,14 @@ This exercises the decimation chain.

2.3: Baseband center frequency position relative the center frequency

-Possible values are: + - **Cen**: the decimation operation takes place around the center frequency Fs + - **Inf**: the decimation operation takes place around Fs - Fc. + - **Sup**: the decimation operation takes place around Fs + Fc. + +With SR as the sample rate before decimation Fc is calculated as: - - **Cen**: the decimation operation takes place around the BladeRF Rx center frequency - - **Inf**: the decimation operation takes place around the center of the lower half of the BladeRF Rx passband. - - **Sup**: the decimation operation takes place around the center of the upper half of the BladeRF Rx passband. + - if decimation n is 4 or lower: Fc = SR/2^(log2(n)-1). The device center frequency is on the side of the baseband. You need a RF filter bandwidth at least twice the baseband. + - if decimation n is 8 or higher: Fc = SR/n. The device center frequency is half the baseband away from the side of the baseband. You need a RF filter bandwidth at least 3 times the baseband.

2.4: Sample size

diff --git a/plugins/samplesource/testsource/testsourceinput.cpp b/plugins/samplesource/testsource/testsourceinput.cpp index 5eaf39a63..65e39aa89 100644 --- a/plugins/samplesource/testsource/testsourceinput.cpp +++ b/plugins/samplesource/testsource/testsourceinput.cpp @@ -274,11 +274,10 @@ bool TestSourceInput::applySettings(const TestSourceSettings& settings, bool for if (settings.m_log2Decim != 0) { - if (settings.m_fcPos == TestSourceSettings::FC_POS_INFRA) { - frequencyShift -= (devSampleRate / 4); - } else if (settings.m_fcPos == TestSourceSettings::FC_POS_SUPRA) { - frequencyShift += (devSampleRate / 4); - } + frequencyShift += DeviceSampleSource::calculateFrequencyShift( + settings.m_log2Decim, + (DeviceSampleSource::fcPos_t) settings.m_fcPos, + settings.m_sampleRate); } if (m_testSourceThread != 0) diff --git a/sdrbase/dsp/decimators.h b/sdrbase/dsp/decimators.h index e94448b6c..18eec7b76 100644 --- a/sdrbase/dsp/decimators.h +++ b/sdrbase/dsp/decimators.h @@ -463,31 +463,27 @@ void Decimators::decimate2_u(SampleVector::i template void Decimators::decimate2_inf(SampleVector::iterator* it, const T* buf, qint32 len) { - StorageType xreal[2], yimag[2]; + StorageType buf2[4]; for (int pos = 0; pos < len - 7; pos += 8) { - xreal[0] = buf[pos+2] << decimation_shifts::pre2; - yimag[0] = buf[pos+3] << decimation_shifts::pre2; - xreal[1] = buf[pos+6] << decimation_shifts::pre2; - yimag[1] = buf[pos+7] << decimation_shifts::pre2; - m_decimator2.myDecimateInf( buf[pos+0] << decimation_shifts::pre2, buf[pos+1] << decimation_shifts::pre2, - &xreal[0], - &yimag[0], + buf[pos+2] << decimation_shifts::pre2, + buf[pos+3] << decimation_shifts::pre2, buf[pos+4] << decimation_shifts::pre2, buf[pos+5] << decimation_shifts::pre2, - &xreal[1], - &yimag[1]); + buf[pos+6] << decimation_shifts::pre2, + buf[pos+7] << decimation_shifts::pre2, + &buf2[0]); - (**it).setReal(xreal[0] >> decimation_shifts::post2); - (**it).setImag(yimag[0] >> decimation_shifts::post2); + (**it).setReal(buf2[0] >> decimation_shifts::post2); + (**it).setImag(buf2[1] >> decimation_shifts::post2); ++(*it); - (**it).setReal(xreal[1] >> decimation_shifts::post2); - (**it).setImag(yimag[1] >> decimation_shifts::post2); + (**it).setReal(buf2[2] >> decimation_shifts::post2); + (**it).setImag(buf2[3] >> decimation_shifts::post2); ++(*it); } } @@ -495,31 +491,27 @@ void Decimators::decimate2_inf(SampleVector: template void Decimators::decimate2_sup(SampleVector::iterator* it, const T* buf, qint32 len) { - StorageType xreal[2], yimag[2]; + StorageType buf2[4]; for (int pos = 0; pos < len - 7; pos += 8) { - xreal[0] = buf[pos+2] << decimation_shifts::pre2; - yimag[0] = buf[pos+3] << decimation_shifts::pre2; - xreal[1] = buf[pos+6] << decimation_shifts::pre2; - yimag[1] = buf[pos+7] << decimation_shifts::pre2; - m_decimator2.myDecimateSup( buf[pos+0] << decimation_shifts::pre2, buf[pos+1] << decimation_shifts::pre2, - &xreal[0], - &yimag[0], + buf[pos+2] << decimation_shifts::pre2, + buf[pos+3] << decimation_shifts::pre2, buf[pos+4] << decimation_shifts::pre2, buf[pos+5] << decimation_shifts::pre2, - &xreal[1], - &yimag[1]); + buf[pos+6] << decimation_shifts::pre2, + buf[pos+7] << decimation_shifts::pre2, + &buf2[0]); - (**it).setReal(xreal[0] >> decimation_shifts::post2); - (**it).setImag(yimag[0] >> decimation_shifts::post2); + (**it).setReal(buf2[0] >> decimation_shifts::post2); + (**it).setImag(buf2[1] >> decimation_shifts::post2); ++(*it); - (**it).setReal(xreal[1] >> decimation_shifts::post2); - (**it).setImag(yimag[1] >> decimation_shifts::post2); + (**it).setReal(buf2[2] >> decimation_shifts::post2); + (**it).setImag(buf2[3] >> decimation_shifts::post2); ++(*it); } } @@ -549,114 +541,99 @@ void Decimators::decimate2_sup(SampleVector: template void Decimators::decimate4_inf(SampleVector::iterator* it, const T* buf, qint32 len) { - StorageType xreal[4], yimag[4]; + StorageType buf2[8], buf4[4]; for (int pos = 0; pos < len - 15; pos += 16) { - xreal[0] = buf[pos+2] << decimation_shifts::pre4; - yimag[0] = buf[pos+3] << decimation_shifts::pre4; - xreal[1] = buf[pos+6] << decimation_shifts::pre4; - yimag[1] = buf[pos+7] << decimation_shifts::pre4; - m_decimator2.myDecimateInf( buf[pos+0] << decimation_shifts::pre4, buf[pos+1] << decimation_shifts::pre4, - &xreal[0], - &yimag[0], + buf[pos+2] << decimation_shifts::pre4, + buf[pos+3] << decimation_shifts::pre4, buf[pos+4] << decimation_shifts::pre4, buf[pos+5] << decimation_shifts::pre4, - &xreal[1], - &yimag[1]); - - xreal[2] = buf[pos+10] << decimation_shifts::pre4; - yimag[2] = buf[pos+11] << decimation_shifts::pre4; - xreal[3] = buf[pos+14] << decimation_shifts::pre4; - yimag[3] = buf[pos+15] << decimation_shifts::pre4; + buf[pos+6] << decimation_shifts::pre4, + buf[pos+7] << decimation_shifts::pre4, + &buf2[0]); m_decimator2.myDecimateInf( buf[pos+8] << decimation_shifts::pre4, buf[pos+9] << decimation_shifts::pre4, - &xreal[2], - &yimag[2], + buf[pos+10] << decimation_shifts::pre4, + buf[pos+11] << decimation_shifts::pre4, buf[pos+12] << decimation_shifts::pre4, buf[pos+13] << decimation_shifts::pre4, - &xreal[3], - &yimag[3]); + buf[pos+14] << decimation_shifts::pre4, + buf[pos+15] << decimation_shifts::pre4, + &buf2[4]); - m_decimator4.myDecimateCen( - xreal[0], - yimag[0], - &xreal[1], - &yimag[1], - xreal[2], - yimag[2], - &xreal[3], - &yimag[3]); + m_decimator4.myDecimateSup( + buf2[0], + buf2[1], + buf2[2], + buf2[3], + buf2[4], + buf2[5], + buf2[6], + buf2[7], + &buf4[0]); - (**it).setReal(xreal[1] >> decimation_shifts::post4); - (**it).setImag(yimag[1] >> decimation_shifts::post4); + (**it).setReal(buf4[0] >> decimation_shifts::post4); + (**it).setImag(buf4[1] >> decimation_shifts::post4); ++(*it); - (**it).setReal(xreal[3] >> decimation_shifts::post4); - (**it).setImag(yimag[3] >> decimation_shifts::post4); + (**it).setReal(buf4[2] >> decimation_shifts::post4); + (**it).setImag(buf4[3] >> decimation_shifts::post4); ++(*it); } } - template void Decimators::decimate4_sup(SampleVector::iterator* it, const T* buf, qint32 len) { - StorageType xreal[4], yimag[4]; + StorageType buf2[8], buf4[4]; for (int pos = 0; pos < len - 15; pos += 16) { - xreal[0] = buf[pos+2] << decimation_shifts::pre4; - yimag[0] = buf[pos+3] << decimation_shifts::pre4; - xreal[1] = buf[pos+6] << decimation_shifts::pre4; - yimag[1] = buf[pos+7] << decimation_shifts::pre4; - m_decimator2.myDecimateSup( buf[pos+0] << decimation_shifts::pre4, buf[pos+1] << decimation_shifts::pre4, - &xreal[0], - &yimag[0], + buf[pos+2] << decimation_shifts::pre4, + buf[pos+3] << decimation_shifts::pre4, buf[pos+4] << decimation_shifts::pre4, buf[pos+5] << decimation_shifts::pre4, - &xreal[1], - &yimag[1]); - - xreal[2] = buf[pos+10] << decimation_shifts::pre4; - yimag[2] = buf[pos+11] << decimation_shifts::pre4; - xreal[3] = buf[pos+14] << decimation_shifts::pre4; - yimag[3] = buf[pos+15] << decimation_shifts::pre4; + buf[pos+6] << decimation_shifts::pre4, + buf[pos+7] << decimation_shifts::pre4, + &buf2[0]); m_decimator2.myDecimateSup( buf[pos+8] << decimation_shifts::pre4, buf[pos+9] << decimation_shifts::pre4, - &xreal[2], - &yimag[2], + buf[pos+10] << decimation_shifts::pre4, + buf[pos+11] << decimation_shifts::pre4, buf[pos+12] << decimation_shifts::pre4, buf[pos+13] << decimation_shifts::pre4, - &xreal[3], - &yimag[3]); + buf[pos+14] << decimation_shifts::pre4, + buf[pos+15] << decimation_shifts::pre4, + &buf2[4]); - m_decimator4.myDecimateCen( - xreal[0], - yimag[0], - &xreal[1], - &yimag[1], - xreal[2], - yimag[2], - &xreal[3], - &yimag[3]); + m_decimator4.myDecimateInf( + buf2[0], + buf2[1], + buf2[2], + buf2[3], + buf2[4], + buf2[5], + buf2[6], + buf2[7], + &buf4[0]); - (**it).setReal(xreal[1] >> decimation_shifts::post4); - (**it).setImag(yimag[1] >> decimation_shifts::post4); + (**it).setReal(buf4[0] >> decimation_shifts::post4); + (**it).setImag(buf4[1] >> decimation_shifts::post4); ++(*it); - (**it).setReal(xreal[3] >> decimation_shifts::post4); - (**it).setImag(yimag[3] >> decimation_shifts::post4); + (**it).setReal(buf4[2] >> decimation_shifts::post4); + (**it).setImag(buf4[3] >> decimation_shifts::post4); ++(*it); } } @@ -752,11 +729,11 @@ void Decimators::decimate8_inf(SampleVector: buf[pos+31] << decimation_shifts::pre8, &buf2[12]); - m_decimator4.myDecimateCen( + m_decimator4.myDecimateSup( &buf2[0], &buf4[0]); - m_decimator4.myDecimateCen( + m_decimator4.myDecimateSup( &buf2[8], &buf4[4]); @@ -825,11 +802,11 @@ void Decimators::decimate8_sup(SampleVector: buf[pos+31] << decimation_shifts::pre8, &buf2[12]); - m_decimator4.myDecimateCen( + m_decimator4.myDecimateInf( &buf2[0], &buf4[0]); - m_decimator4.myDecimateCen( + m_decimator4.myDecimateInf( &buf2[8], &buf4[4]); @@ -942,27 +919,27 @@ void Decimators::decimate16_inf(SampleVector buf[pos+63] << decimation_shifts::pre16, &buf2[28]); - m_decimator4.myDecimateCen( + m_decimator4.myDecimateSup( &buf2[0], &buf4[0]); - m_decimator4.myDecimateCen( + m_decimator4.myDecimateSup( &buf2[8], &buf4[4]); - m_decimator4.myDecimateCen( + m_decimator4.myDecimateSup( &buf2[16], &buf4[8]); - m_decimator4.myDecimateCen( + m_decimator4.myDecimateSup( &buf2[24], &buf4[12]); - m_decimator8.myDecimateCen( + m_decimator8.myDecimateSup( &buf4[0], &buf8[0]); - m_decimator8.myDecimateCen( + m_decimator8.myDecimateSup( &buf4[8], &buf8[4]); @@ -1075,27 +1052,27 @@ void Decimators::decimate16_sup(SampleVector buf[pos+63] << decimation_shifts::pre16, &buf2[28]); - m_decimator4.myDecimateCen( + m_decimator4.myDecimateInf( &buf2[0], &buf4[0]); - m_decimator4.myDecimateCen( + m_decimator4.myDecimateInf( &buf2[8], &buf4[4]); - m_decimator4.myDecimateCen( + m_decimator4.myDecimateInf( &buf2[16], &buf4[8]); - m_decimator4.myDecimateCen( + m_decimator4.myDecimateInf( &buf2[24], &buf4[12]); - m_decimator8.myDecimateCen( + m_decimator8.myDecimateInf( &buf4[0], &buf8[0]); - m_decimator8.myDecimateCen( + m_decimator8.myDecimateInf( &buf4[8], &buf8[4]); @@ -1296,59 +1273,59 @@ void Decimators::decimate32_inf(SampleVector buf[pos+127] << decimation_shifts::pre32, &buf2[60]); - m_decimator4.myDecimateCen( + m_decimator4.myDecimateSup( &buf2[0], &buf4[0]); - m_decimator4.myDecimateCen( + m_decimator4.myDecimateSup( &buf2[8], &buf4[4]); - m_decimator4.myDecimateCen( + m_decimator4.myDecimateSup( &buf2[16], &buf4[8]); - m_decimator4.myDecimateCen( + m_decimator4.myDecimateSup( &buf2[24], &buf4[12]); - m_decimator4.myDecimateCen( + m_decimator4.myDecimateSup( &buf2[32], &buf4[16]); - m_decimator4.myDecimateCen( + m_decimator4.myDecimateSup( &buf2[40], &buf4[20]); - m_decimator4.myDecimateCen( + m_decimator4.myDecimateSup( &buf2[48], &buf4[24]); - m_decimator4.myDecimateCen( + m_decimator4.myDecimateSup( &buf2[56], &buf4[28]); - m_decimator8.myDecimateCen( + m_decimator8.myDecimateSup( &buf4[0], &buf8[0]); - m_decimator8.myDecimateCen( + m_decimator8.myDecimateSup( &buf4[8], &buf8[4]); - m_decimator8.myDecimateCen( + m_decimator8.myDecimateSup( &buf4[16], &buf8[8]); - m_decimator8.myDecimateCen( + m_decimator8.myDecimateSup( &buf4[24], &buf8[12]); - m_decimator16.myDecimateCen( + m_decimator16.myDecimateSup( &buf8[0], &buf16[0]); - m_decimator16.myDecimateCen( + m_decimator16.myDecimateSup( &buf8[8], &buf16[4]); @@ -1549,59 +1526,59 @@ void Decimators::decimate32_sup(SampleVector buf[pos+127] << decimation_shifts::pre32, &buf2[60]); - m_decimator4.myDecimateCen( + m_decimator4.myDecimateInf( &buf2[0], &buf4[0]); - m_decimator4.myDecimateCen( + m_decimator4.myDecimateInf( &buf2[8], &buf4[4]); - m_decimator4.myDecimateCen( + m_decimator4.myDecimateInf( &buf2[16], &buf4[8]); - m_decimator4.myDecimateCen( + m_decimator4.myDecimateInf( &buf2[24], &buf4[12]); - m_decimator4.myDecimateCen( + m_decimator4.myDecimateInf( &buf2[32], &buf4[16]); - m_decimator4.myDecimateCen( + m_decimator4.myDecimateInf( &buf2[40], &buf4[20]); - m_decimator4.myDecimateCen( + m_decimator4.myDecimateInf( &buf2[48], &buf4[24]); - m_decimator4.myDecimateCen( + m_decimator4.myDecimateInf( &buf2[56], &buf4[28]); - m_decimator8.myDecimateCen( + m_decimator8.myDecimateInf( &buf4[0], &buf8[0]); - m_decimator8.myDecimateCen( + m_decimator8.myDecimateInf( &buf4[8], &buf8[4]); - m_decimator8.myDecimateCen( + m_decimator8.myDecimateInf( &buf4[16], &buf8[8]); - m_decimator8.myDecimateCen( + m_decimator8.myDecimateInf( &buf4[24], &buf8[12]); - m_decimator16.myDecimateCen( + m_decimator16.myDecimateInf( &buf8[0], &buf16[0]); - m_decimator16.myDecimateCen( + m_decimator16.myDecimateInf( &buf8[8], &buf16[4]); @@ -1978,123 +1955,123 @@ void Decimators::decimate64_inf(SampleVector buf[pos+255] << decimation_shifts::pre64, &buf2[124]); - m_decimator4.myDecimateCen( + m_decimator4.myDecimateSup( &buf2[0], &buf4[0]); - m_decimator4.myDecimateCen( + m_decimator4.myDecimateSup( &buf2[8], &buf4[4]); - m_decimator4.myDecimateCen( + m_decimator4.myDecimateSup( &buf2[16], &buf4[8]); - m_decimator4.myDecimateCen( + m_decimator4.myDecimateSup( &buf2[24], &buf4[12]); - m_decimator4.myDecimateCen( + m_decimator4.myDecimateSup( &buf2[32], &buf4[16]); - m_decimator4.myDecimateCen( + m_decimator4.myDecimateSup( &buf2[40], &buf4[20]); - m_decimator4.myDecimateCen( + m_decimator4.myDecimateSup( &buf2[48], &buf4[24]); - m_decimator4.myDecimateCen( + m_decimator4.myDecimateSup( &buf2[56], &buf4[28]); - m_decimator4.myDecimateCen( + m_decimator4.myDecimateSup( &buf2[64], &buf4[32]); - m_decimator4.myDecimateCen( + m_decimator4.myDecimateSup( &buf2[72], &buf4[36]); - m_decimator4.myDecimateCen( + m_decimator4.myDecimateSup( &buf2[80], &buf4[40]); - m_decimator4.myDecimateCen( + m_decimator4.myDecimateSup( &buf2[88], &buf4[44]); - m_decimator4.myDecimateCen( + m_decimator4.myDecimateSup( &buf2[96], &buf4[48]); - m_decimator4.myDecimateCen( + m_decimator4.myDecimateSup( &buf2[104], &buf4[52]); - m_decimator4.myDecimateCen( + m_decimator4.myDecimateSup( &buf2[112], &buf4[56]); - m_decimator4.myDecimateCen( + m_decimator4.myDecimateSup( &buf2[120], &buf4[60]); - m_decimator8.myDecimateCen( + m_decimator8.myDecimateSup( &buf4[0], &buf8[0]); - m_decimator8.myDecimateCen( + m_decimator8.myDecimateSup( &buf4[8], &buf8[4]); - m_decimator8.myDecimateCen( + m_decimator8.myDecimateSup( &buf4[16], &buf8[8]); - m_decimator8.myDecimateCen( + m_decimator8.myDecimateSup( &buf4[24], &buf8[12]); - m_decimator8.myDecimateCen( + m_decimator8.myDecimateSup( &buf4[32], &buf8[16]); - m_decimator8.myDecimateCen( + m_decimator8.myDecimateSup( &buf4[40], &buf8[20]); - m_decimator8.myDecimateCen( + m_decimator8.myDecimateSup( &buf4[48], &buf8[24]); - m_decimator8.myDecimateCen( + m_decimator8.myDecimateSup( &buf4[56], &buf8[28]); - m_decimator16.myDecimateCen( + m_decimator16.myDecimateSup( &buf8[0], &buf16[0]); - m_decimator16.myDecimateCen( + m_decimator16.myDecimateSup( &buf8[8], &buf16[4]); - m_decimator16.myDecimateCen( + m_decimator16.myDecimateSup( &buf8[16], &buf16[8]); - m_decimator16.myDecimateCen( + m_decimator16.myDecimateSup( &buf8[24], &buf16[12]); - m_decimator32.myDecimateCen( + m_decimator32.myDecimateSup( &buf16[0], &buf32[0]); - m_decimator32.myDecimateCen( + m_decimator32.myDecimateSup( &buf16[8], &buf32[4]); @@ -2471,123 +2448,123 @@ void Decimators::decimate64_sup(SampleVector buf[pos+255] << decimation_shifts::pre64, &buf2[124]); - m_decimator4.myDecimateCen( + m_decimator4.myDecimateInf( &buf2[0], &buf4[0]); - m_decimator4.myDecimateCen( + m_decimator4.myDecimateInf( &buf2[8], &buf4[4]); - m_decimator4.myDecimateCen( + m_decimator4.myDecimateInf( &buf2[16], &buf4[8]); - m_decimator4.myDecimateCen( + m_decimator4.myDecimateInf( &buf2[24], &buf4[12]); - m_decimator4.myDecimateCen( + m_decimator4.myDecimateInf( &buf2[32], &buf4[16]); - m_decimator4.myDecimateCen( + m_decimator4.myDecimateInf( &buf2[40], &buf4[20]); - m_decimator4.myDecimateCen( + m_decimator4.myDecimateInf( &buf2[48], &buf4[24]); - m_decimator4.myDecimateCen( + m_decimator4.myDecimateInf( &buf2[56], &buf4[28]); - m_decimator4.myDecimateCen( + m_decimator4.myDecimateInf( &buf2[64], &buf4[32]); - m_decimator4.myDecimateCen( + m_decimator4.myDecimateInf( &buf2[72], &buf4[36]); - m_decimator4.myDecimateCen( + m_decimator4.myDecimateInf( &buf2[80], &buf4[40]); - m_decimator4.myDecimateCen( + m_decimator4.myDecimateInf( &buf2[88], &buf4[44]); - m_decimator4.myDecimateCen( + m_decimator4.myDecimateInf( &buf2[96], &buf4[48]); - m_decimator4.myDecimateCen( + m_decimator4.myDecimateInf( &buf2[104], &buf4[52]); - m_decimator4.myDecimateCen( + m_decimator4.myDecimateInf( &buf2[112], &buf4[56]); - m_decimator4.myDecimateCen( + m_decimator4.myDecimateInf( &buf2[120], &buf4[60]); - m_decimator8.myDecimateCen( + m_decimator8.myDecimateInf( &buf4[0], &buf8[0]); - m_decimator8.myDecimateCen( + m_decimator8.myDecimateInf( &buf4[8], &buf8[4]); - m_decimator8.myDecimateCen( + m_decimator8.myDecimateInf( &buf4[16], &buf8[8]); - m_decimator8.myDecimateCen( + m_decimator8.myDecimateInf( &buf4[24], &buf8[12]); - m_decimator8.myDecimateCen( + m_decimator8.myDecimateInf( &buf4[32], &buf8[16]); - m_decimator8.myDecimateCen( + m_decimator8.myDecimateInf( &buf4[40], &buf8[20]); - m_decimator8.myDecimateCen( + m_decimator8.myDecimateInf( &buf4[48], &buf8[24]); - m_decimator8.myDecimateCen( + m_decimator8.myDecimateInf( &buf4[56], &buf8[28]); - m_decimator16.myDecimateCen( + m_decimator16.myDecimateInf( &buf8[0], &buf16[0]); - m_decimator16.myDecimateCen( + m_decimator16.myDecimateInf( &buf8[8], &buf16[4]); - m_decimator16.myDecimateCen( + m_decimator16.myDecimateInf( &buf8[16], &buf16[8]); - m_decimator16.myDecimateCen( + m_decimator16.myDecimateInf( &buf8[24], &buf16[12]); - m_decimator32.myDecimateCen( + m_decimator32.myDecimateInf( &buf16[0], &buf32[0]); - m_decimator32.myDecimateCen( + m_decimator32.myDecimateInf( &buf16[8], &buf32[4]); diff --git a/sdrbase/dsp/devicesamplesource.cpp b/sdrbase/dsp/devicesamplesource.cpp index bc2e8a963..1a637bc0b 100644 --- a/sdrbase/dsp/devicesamplesource.cpp +++ b/sdrbase/dsp/devicesamplesource.cpp @@ -54,23 +54,8 @@ qint64 DeviceSampleSource::calculateDeviceCenterFrequency( deviceCenterFrequency = deviceCenterFrequency < 0 ? 0 : deviceCenterFrequency; qint64 f_img = deviceCenterFrequency; - if ((log2Decim == 0) || (fcPos == FC_POS_CENTER)) - { - f_img = deviceCenterFrequency; - } - else - { - if (fcPos == FC_POS_INFRA) - { - deviceCenterFrequency += (devSampleRate / 4); - f_img = deviceCenterFrequency + devSampleRate/2; - } - else if (fcPos == FC_POS_SUPRA) - { - deviceCenterFrequency -= (devSampleRate / 4); - f_img = deviceCenterFrequency - devSampleRate/2; - } - } + deviceCenterFrequency -= calculateFrequencyShift(log2Decim, fcPos, devSampleRate); + f_img -= 2*calculateFrequencyShift(log2Decim, fcPos, devSampleRate); qDebug() << "DeviceSampleSource::calculateDeviceCenterFrequency:" << " desired center freq: " << centerFrequency << " Hz" @@ -82,3 +67,44 @@ qint64 DeviceSampleSource::calculateDeviceCenterFrequency( return deviceCenterFrequency; } + +/** + * log2Decim = 0: no shift + * + * n = log2Decim <= 2: fc = +/- 1/2^(n-1) + * center + * | ^ | + * | inf | sup | + * ^ ^ + * + * n = log2Decim > 2: fc = +/- 1/2^n + * center + * | ^ | + * | |inf| | |sup| | + * ^ ^ + */ +qint32 DeviceSampleSource::calculateFrequencyShift( + int log2Decim, + fcPos_t fcPos, + quint32 devSampleRate) +{ + if (log2Decim == 0) { // no shift at all + return 0; + } else if (log2Decim < 3) { + if (fcPos == FC_POS_INFRA) { // shift in the square next to center frequency + return -(devSampleRate / (1<<(log2Decim+1))); + } else if (fcPos == FC_POS_SUPRA) { + return devSampleRate / (1<<(log2Decim+1)); + } else { + return 0; + } + } else { + if (fcPos == FC_POS_INFRA) { // shift centered in the square next to center frequency + return -(devSampleRate / (1<<(log2Decim))); + } else if (fcPos == FC_POS_SUPRA) { + return devSampleRate / (1<<(log2Decim)); + } else { + return 0; + } + } +} diff --git a/sdrbase/dsp/devicesamplesource.h b/sdrbase/dsp/devicesamplesource.h index 776ed7f00..40d1ecd9f 100644 --- a/sdrbase/dsp/devicesamplesource.h +++ b/sdrbase/dsp/devicesamplesource.h @@ -94,6 +94,11 @@ public: quint32 devSampleRate, bool transverterMode = false); + static qint32 calculateFrequencyShift( + int log2Decim, + fcPos_t fcPos, + quint32 devSampleRate); + protected slots: void handleInputMessages(); diff --git a/sdrbase/dsp/inthalfbandfiltereo.h b/sdrbase/dsp/inthalfbandfiltereo.h index b60871bfe..a5cff5344 100644 --- a/sdrbase/dsp/inthalfbandfiltereo.h +++ b/sdrbase/dsp/inthalfbandfiltereo.h @@ -623,23 +623,6 @@ public: advancePointer(); } - void myDecimateInf(int32_t x1, int32_t y1, int32_t *x2, int32_t *y2, int32_t x3, int32_t y3, int32_t *x4, int32_t *y4) - { - storeSample32(-y1, x1); - advancePointer(); - - storeSample32(-*x2, -*y2); - doFIR(x2, y2); - advancePointer(); - - storeSample32(y3, -x3); - advancePointer(); - - storeSample32(*x4, *y4); - doFIR(x4, y4); - advancePointer(); - } - void myDecimateInf(int32_t x1, int32_t y1, int32_t x2, int32_t y2, int32_t x3, int32_t y3, int32_t x4, int32_t y4, int32_t *out) { storeSample32(-y1, x1); @@ -657,20 +640,20 @@ public: advancePointer(); } - void myDecimateSup(int32_t x1, int32_t y1, int32_t *x2, int32_t *y2, int32_t x3, int32_t y3, int32_t *x4, int32_t *y4) + void myDecimateInf(int32_t *in, int32_t *out) { - storeSample32(y1, -x1); + storeSample32(-in[1], in[0]); advancePointer(); - storeSample32(-*x2, -*y2); - doFIR(x2, y2); + storeSample32(-in[2], -in[3]); + doFIR(&out[0], &out[1]); advancePointer(); - storeSample32(-y3, x3); + storeSample32(in[5], -in[4]); advancePointer(); - storeSample32(*x4, *y4); - doFIR(x4, y4); + storeSample32(in[6], in[7]); + doFIR(&out[2], &out[3]); advancePointer(); } @@ -691,6 +674,23 @@ public: advancePointer(); } + void myDecimateSup(int32_t *in, int32_t *out) + { + storeSample32(in[1], -in[0]); + advancePointer(); + + storeSample32(-in[2], -in[3]); + doFIR(&out[0], &out[1]); + advancePointer(); + + storeSample32(-in[5], in[4]); + advancePointer(); + + storeSample32(in[6], in[7]); + doFIR(&out[2], &out[3]); + advancePointer(); + } + /** Simple zero stuffing and filter */ void myInterpolateZeroStuffing(Sample* sample1, Sample* sample2) {