From 347360db905ec2e35bf67928e320c3fca1f535cf Mon Sep 17 00:00:00 2001 From: f4exb Date: Wed, 15 Jul 2015 01:19:39 +0200 Subject: [PATCH] Channel analyzer: in the scope+spectrum combo show the spectrum of the scope captured data possibly triggered and not just the free running spectrum of the channel --- include-gpl/dsp/scopevis.h | 2 ++ include-gpl/dsp/spectrumvis.h | 2 ++ sdrbase/dsp/scopevis.cpp | 17 +++++++++++++++++ sdrbase/dsp/spectrumscopecombovis.cpp | 3 ++- sdrbase/dsp/spectrumvis.cpp | 22 ++++++++++++++++++++++ 5 files changed, 45 insertions(+), 1 deletion(-) diff --git a/include-gpl/dsp/scopevis.h b/include-gpl/dsp/scopevis.h index 4346d6295..f3cc18554 100644 --- a/include-gpl/dsp/scopevis.h +++ b/include-gpl/dsp/scopevis.h @@ -32,6 +32,7 @@ public: void setSampleRate(int sampleRate); int getSampleRate() const { return m_sampleRate; } + SampleVector::const_iterator getTriggerPoint() const { return m_triggerPoint; } private: class MsgConfigureScopeVis : public Message { @@ -76,6 +77,7 @@ private: bool m_triggerOneShot; bool m_armed; int m_sampleRate; + SampleVector::const_iterator m_triggerPoint; bool triggerCondition(SampleVector::const_iterator& it); }; diff --git a/include-gpl/dsp/spectrumvis.h b/include-gpl/dsp/spectrumvis.h index f6d17452e..272fee568 100644 --- a/include-gpl/dsp/spectrumvis.h +++ b/include-gpl/dsp/spectrumvis.h @@ -17,6 +17,7 @@ public: void configure(MessageQueue* msgQueue, int fftSize, int overlapPercent, FFTWindow::Function window); void feed(SampleVector::const_iterator begin, SampleVector::const_iterator end, bool positiveOnly); + void feedTriggered(SampleVector::const_iterator triggerPoint, SampleVector::const_iterator begin, SampleVector::const_iterator end, bool positiveOnly); void start(); void stop(); bool handleMessageKeep(Message* message); @@ -34,6 +35,7 @@ private: size_t m_overlapSize; size_t m_refillSize; size_t m_fftBufferFill; + bool m_needMoreSamples; GLSpectrum* m_glSpectrum; diff --git a/sdrbase/dsp/scopevis.cpp b/sdrbase/dsp/scopevis.cpp index 8969a8a5f..d0aad27fe 100644 --- a/sdrbase/dsp/scopevis.cpp +++ b/sdrbase/dsp/scopevis.cpp @@ -30,6 +30,22 @@ void ScopeVis::configure(MessageQueue* msgQueue, TriggerChannel triggerChannel, void ScopeVis::feed(SampleVector::const_iterator begin, SampleVector::const_iterator end, bool positiveOnly) { + if (m_triggerChannel == TriggerFreeRun) { + m_triggerPoint = begin; + } + else if (m_triggerState == Triggered) { + m_triggerPoint = begin; + } + else if (m_triggerState == Untriggered) { + m_triggerPoint = end; + } + else if (m_triggerState == WaitForReset) { + m_triggerPoint = end; + } + else { + m_triggerPoint = begin; + } + while(begin < end) { if (m_triggerChannel == TriggerFreeRun) @@ -62,6 +78,7 @@ void ScopeVis::feed(SampleVector::const_iterator begin, SampleVector::const_iter if (m_armed) { m_triggerState = Triggered; m_armed = false; + m_triggerPoint = begin; break; } } diff --git a/sdrbase/dsp/spectrumscopecombovis.cpp b/sdrbase/dsp/spectrumscopecombovis.cpp index 269454c40..215cb4e21 100644 --- a/sdrbase/dsp/spectrumscopecombovis.cpp +++ b/sdrbase/dsp/spectrumscopecombovis.cpp @@ -10,8 +10,9 @@ SpectrumScopeComboVis::SpectrumScopeComboVis(SpectrumVis* spectrumVis, ScopeVis* void SpectrumScopeComboVis::feed(SampleVector::const_iterator begin, SampleVector::const_iterator end, bool positiveOnly) { - m_spectrumVis->feed(begin, end, positiveOnly); m_scopeVis->feed(begin, end, false); + SampleVector::const_iterator triggerPoint = m_scopeVis->getTriggerPoint(); + m_spectrumVis->feedTriggered(triggerPoint, begin, end, positiveOnly); } void SpectrumScopeComboVis::start() diff --git a/sdrbase/dsp/spectrumvis.cpp b/sdrbase/dsp/spectrumvis.cpp index 13261c566..ba2013110 100644 --- a/sdrbase/dsp/spectrumvis.cpp +++ b/sdrbase/dsp/spectrumvis.cpp @@ -18,6 +18,7 @@ SpectrumVis::SpectrumVis(GLSpectrum* glSpectrum) : m_fftBuffer(MAX_FFT_SIZE), m_logPowerSpectrum(MAX_FFT_SIZE), m_fftBufferFill(0), + m_needMoreSamples(false), m_glSpectrum(glSpectrum) { handleConfigure(1024, 0, FFTWindow::BlackmanHarris); @@ -34,6 +35,25 @@ void SpectrumVis::configure(MessageQueue* msgQueue, int fftSize, int overlapPerc cmd->submit(msgQueue, this); } +void SpectrumVis::feedTriggered(SampleVector::const_iterator triggerPoint, SampleVector::const_iterator begin, SampleVector::const_iterator end, bool positiveOnly) +{ + if (triggerPoint == end) + { + // the following piece of code allows to terminate the FFT that ends past the end of scope captured data + // that is the spectrum will include the captured data + // just do nothing if you want the spectrum to be included inside the scope captured data + // that is to drop the FFT that dangles past the end of captured data + if (m_needMoreSamples) { + feed(begin, end, positiveOnly); + m_needMoreSamples = false; // force finish + } + } + else + { + feed(triggerPoint, end, positiveOnly); // normal feed from trigger point + } +} + void SpectrumVis::feed(SampleVector::const_iterator begin, SampleVector::const_iterator end, bool positiveOnly) { // if no visualisation is set, send the samples to /dev/null @@ -94,11 +114,13 @@ void SpectrumVis::feed(SampleVector::const_iterator begin, SampleVector::const_i // start over m_fftBufferFill = m_overlapSize; + m_needMoreSamples = false; } else { // not enough samples for FFT - just fill in new data and return for(std::vector::iterator it = m_fftBuffer.begin() + m_fftBufferFill; begin < end; ++begin) *it++ = Complex(begin->real() / 32768.0, begin->imag() / 32768.0); m_fftBufferFill += todo; + m_needMoreSamples = true; } } }