diff --git a/include/dsp/phasediscri.hpp b/include/dsp/phasediscri.h similarity index 99% rename from include/dsp/phasediscri.hpp rename to include/dsp/phasediscri.h index 479dac558..b7e99be01 100644 --- a/include/dsp/phasediscri.hpp +++ b/include/dsp/phasediscri.h @@ -18,6 +18,8 @@ #ifndef INCLUDE_DSP_PHASEDISCRI_H_ #define INCLUDE_DSP_PHASEDISCRI_H_ +#include "dsp/dsptypes.h" + class PhaseDiscriminators { public: diff --git a/plugins/channel/nfm/nfmdemod.cpp b/plugins/channel/nfm/nfmdemod.cpp index 5674cff6b..3621b1bf9 100644 --- a/plugins/channel/nfm/nfmdemod.cpp +++ b/plugins/channel/nfm/nfmdemod.cpp @@ -331,6 +331,7 @@ void NFMDemod::apply() m_interpolator.create(16, m_config.m_inputSampleRate, m_config.m_rfBandwidth / 2.2); m_interpolatorDistanceRemain = 0; m_interpolatorDistance = (Real) m_config.m_inputSampleRate / (Real) m_config.m_audioSampleRate; + m_fmExcursion = m_config.m_rfBandwidth / 2.0f; m_phaseDiscri.setFMScaling(m_config.m_inputSampleRate / m_fmExcursion); m_settingsMutex.unlock(); } @@ -341,8 +342,6 @@ void NFMDemod::apply() m_settingsMutex.lock(); m_lowpass.create(301, m_config.m_audioSampleRate, 250.0); m_bandpass.create(301, m_config.m_audioSampleRate, 300.0, m_config.m_afBandwidth); - m_fmExcursion = m_config.m_afBandwidth / 2.0f; - m_phaseDiscri.setFMScaling(m_config.m_inputSampleRate / m_fmExcursion); m_settingsMutex.unlock(); } diff --git a/plugins/channel/nfm/nfmdemod.h b/plugins/channel/nfm/nfmdemod.h index 1375e3940..55cc4b593 100644 --- a/plugins/channel/nfm/nfmdemod.h +++ b/plugins/channel/nfm/nfmdemod.h @@ -18,6 +18,7 @@ #ifndef INCLUDE_NFMDEMOD_H #define INCLUDE_NFMDEMOD_H +#include #include #include #include "dsp/samplesink.h" @@ -29,7 +30,6 @@ #include "dsp/agc.h" #include "dsp/ctcssdetector.h" #include "dsp/afsquelch.h" -#include "dsp/phasediscri.hpp" #include "audio/audiofifo.h" #include "util/message.h" diff --git a/plugins/channel/nfm/nfmdemodgui.ui b/plugins/channel/nfm/nfmdemodgui.ui index d685e59ef..8bd445743 100644 --- a/plugins/channel/nfm/nfmdemodgui.ui +++ b/plugins/channel/nfm/nfmdemodgui.ui @@ -244,7 +244,7 @@ - 40 + 100 1 diff --git a/plugins/channel/wfm/wfmdemod.cpp b/plugins/channel/wfm/wfmdemod.cpp index 9c224d4ee..b46caf3b7 100644 --- a/plugins/channel/wfm/wfmdemod.cpp +++ b/plugins/channel/wfm/wfmdemod.cpp @@ -42,6 +42,7 @@ WFMDemod::WFMDemod(SampleSink* sampleSink) : m_config.m_volume = 2.0; m_config.m_audioSampleRate = DSPEngine::instance()->getAudioSampleRate(); m_rfFilter = new fftfilt(-50000.0 / 384000.0, 50000.0 / 384000.0, rfFilterFftLength); + m_phaseDiscri.setFMScaling(384000/75000); apply(); @@ -101,20 +102,19 @@ void WFMDemod::feed(const SampleVector::const_iterator& begin, const SampleVecto // Alternative without atan // http://www.embedded.com/design/configurable-systems/4212086/DSP-Tricks--Frequency-demodulation-algorithms- // in addition it needs scaling by instantaneous magnitude squared and volume (0..10) adjustment factor + /* Real ip = rf[i].real() - m_m2Sample.real(); Real qp = rf[i].imag() - m_m2Sample.imag(); Real h1 = m_m1Sample.real() * qp; Real h2 = m_m1Sample.imag() * ip; - demod = (h1 - h2) / (msq * 10.0); + demod = (h1 - h2) / (msq * 10.0);*/ + demod = m_phaseDiscri.phaseDiscriminator2(rf[i]); } else { demod = 0; } - m_m2Sample = m_m1Sample; - m_m1Sample = rf[i]; - Complex e(demod, 0); if(m_interpolator.interpolate(&m_interpolatorDistanceRemain, e, &ci)) @@ -168,7 +168,7 @@ void WFMDemod::start() { m_squelchState = 0; m_audioFifo.clear(); - m_m1Sample = 0; + m_phaseDiscri.reset(); } void WFMDemod::stop() @@ -254,6 +254,8 @@ void WFMDemod::apply() Real lowCut = -(m_config.m_rfBandwidth / 2.0) / m_config.m_inputSampleRate; Real hiCut = (m_config.m_rfBandwidth / 2.0) / m_config.m_inputSampleRate; m_rfFilter->create_filter(lowCut, hiCut); + m_fmExcursion = m_config.m_rfBandwidth / 2.0; + m_phaseDiscri.setFMScaling(m_config.m_inputSampleRate / m_fmExcursion); m_settingsMutex.unlock(); } diff --git a/plugins/channel/wfm/wfmdemod.h b/plugins/channel/wfm/wfmdemod.h index d0ef3f0a2..15881a67e 100644 --- a/plugins/channel/wfm/wfmdemod.h +++ b/plugins/channel/wfm/wfmdemod.h @@ -26,6 +26,7 @@ #include "dsp/lowpass.h" #include "dsp/movingaverage.h" #include "dsp/fftfilt.h" +#include "dsp/phasediscri.h" #include "audio/audiofifo.h" #include "util/message.h" @@ -120,9 +121,8 @@ private: int m_squelchState; Real m_lastArgument; - Complex m_m1Sample; //!< x^-1 sample - Complex m_m2Sample; //!< x^-1 sample MovingAverage m_movingAverage; + Real m_fmExcursion; AudioVector m_audioBuffer; uint m_audioBufferFill; @@ -132,6 +132,8 @@ private: SampleVector m_sampleBuffer; QMutex m_settingsMutex; + PhaseDiscriminators m_phaseDiscri; + void apply(); };