SDRAngel  4.11.5
Developer docs for <a href="https://github.com/f4exb/sdrangel">SDRangel<\a>, an Open Source Qt5 / OpenGL 3.0+ SDR and signal analyzer frontend to various hardware.
chanalyzer.h
Go to the documentation of this file.
1 // Copyright (C) 2017 Edouard Griffiths, F4EXB //
3 // //
4 // This program is free software; you can redistribute it and/or modify //
5 // it under the terms of the GNU General Public License as published by //
6 // the Free Software Foundation as version 3 of the License, or //
7 // (at your option) any later version. //
8 // //
9 // This program is distributed in the hope that it will be useful, //
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of //
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the //
12 // GNU General Public License V3 for more details. //
13 // //
14 // You should have received a copy of the GNU General Public License //
15 // along with this program. If not, see <http://www.gnu.org/licenses/>. //
17 
18 #ifndef INCLUDE_CHANALYZERNG_H
19 #define INCLUDE_CHANALYZERNG_H
20 
21 #include <QMutex>
22 #include <vector>
23 
24 #include "dsp/basebandsamplesink.h"
25 #include "channel/channelapi.h"
26 #include "dsp/interpolator.h"
27 #include "dsp/ncof.h"
28 #include "dsp/fftcorr.h"
29 #include "dsp/fftfilt.h"
30 #include "dsp/phaselockcomplex.h"
31 #include "dsp/freqlockcomplex.h"
32 #include "audio/audiofifo.h"
33 #include "util/message.h"
34 #include "util/movingaverage.h"
35 
36 #include "chanalyzersettings.h"
37 
38 #define ssbFftLen 1024
39 
40 class DeviceAPI;
42 class DownChannelizer;
43 
45 public:
48 
49  public:
50  const ChannelAnalyzerSettings& getSettings() const { return m_settings; }
51  bool getForce() const { return m_force; }
52 
53  static MsgConfigureChannelAnalyzer* create(const ChannelAnalyzerSettings& settings, bool force)
54  {
55  return new MsgConfigureChannelAnalyzer(settings, force);
56  }
57 
58  private:
60  bool m_force;
61 
63  Message(),
64  m_settings(settings),
65  m_force(force)
66  { }
67  };
68 
71 
72  public:
73  int getSampleRate() const { return m_sampleRate; }
74  int getCenterFrequency() const { return m_centerFrequency; }
75 
76  static MsgConfigureChannelizer* create(int sampleRate, int centerFrequency)
77  {
78  return new MsgConfigureChannelizer(sampleRate, centerFrequency);
79  }
80 
81  private:
84 
85  MsgConfigureChannelizer(int sampleRate, int centerFrequency) :
86  Message(),
87  m_sampleRate(sampleRate),
88  m_centerFrequency(centerFrequency)
89  { }
90  };
91 
94 
95  public:
96 
98  {
100  }
101 
102  private:
103 
105  Message()
106  { }
107  };
108 
109  ChannelAnalyzer(DeviceAPI *deviceAPI);
110  virtual ~ChannelAnalyzer();
111  virtual void destroy() { delete this; }
112  void setSampleSink(BasebandSampleSink* sampleSink) { m_sampleSink = sampleSink; }
113 
114 // void configure(MessageQueue* messageQueue,
115 // int channelSampleRate,
116 // Real Bandwidth,
117 // Real LowCutoff,
118 // int spanLog2,
119 // bool ssb,
120 // bool pll,
121 // bool fll,
122 // unsigned int pllPskOrder);
123 
125  int getInputSampleRate() const { return m_inputSampleRate; }
127  int getDecimation() const { return 1<<m_settings.m_spanLog2; }
128  double getMagSq() const { return m_magsq; }
129  double getMagSqAvg() const { return (double) m_channelPowerAvg; }
130  bool isPllLocked() const { return m_settings.m_pll && m_pll.locked(); }
131  Real getPllFrequency() const;
132  Real getPllDeltaPhase() const { return m_pll.getDeltaPhi(); }
133  Real getPllPhase() const { return m_pll.getPhiHat(); }
134 
135  virtual void feed(const SampleVector::const_iterator& begin, const SampleVector::const_iterator& end, bool positiveOnly);
136  virtual void start();
137  virtual void stop();
138  virtual bool handleMessage(const Message& cmd);
139 
140  virtual void getIdentifier(QString& id) { id = objectName(); }
141  virtual void getTitle(QString& title) { title = objectName(); }
142  virtual qint64 getCenterFrequency() const { return m_settings.m_frequency; }
143 
144  virtual QByteArray serialize() const { return QByteArray(); }
145  virtual bool deserialize(const QByteArray& data) { (void) data; return false; }
146 
147  virtual int getNbSinkStreams() const { return 1; }
148  virtual int getNbSourceStreams() const { return 0; }
149 
150  virtual qint64 getStreamCenterFrequency(int streamIndex, bool sinkElseSource) const
151  {
152  (void) streamIndex;
153  (void) sinkElseSource;
154  return m_settings.m_frequency;
155  }
156 
157  static const QString m_channelIdURI;
158  static const QString m_channelId;
159 
160 private:
165 
170  bool m_usb;
171  double m_magsq;
173 
180 
185 
190 
191 // void apply(bool force = false);
192  void applyChannelSettings(int inputSampleRate, int inputFrequencyOffset, bool force = false);
193  void applySettings(const ChannelAnalyzerSettings& settings, bool force = false);
194  void setFilters(int sampleRate, float bandwidth, float lowCutoff);
195  void processOneSample(Complex& c, fftfilt::cmplx *sideband);
196 
197  inline void feedOneSample(const fftfilt::cmplx& s, const fftfilt::cmplx& pll)
198  {
199  switch (m_settings.m_inputType)
200  {
202  {
203  if (m_settings.m_ssb & !m_usb) { // invert spectrum for LSB
204  m_sampleBuffer.push_back(Sample(pll.imag()*SDR_RX_SCALEF, pll.real()*SDR_RX_SCALEF));
205  } else {
206  m_sampleBuffer.push_back(Sample(pll.real()*SDR_RX_SCALEF, pll.imag()*SDR_RX_SCALEF));
207  }
208  }
209  break;
211  {
212  std::complex<float> a = m_corr->run(s/(SDR_RX_SCALEF/768.0f), 0);
213 
214  if (m_settings.m_ssb & !m_usb) { // invert spectrum for LSB
215  m_sampleBuffer.push_back(Sample(a.imag(), a.real()));
216  } else {
217  m_sampleBuffer.push_back(Sample(a.real(), a.imag()));
218  }
219  }
220  break;
222  default:
223  {
224  if (m_settings.m_ssb & !m_usb) { // invert spectrum for LSB
225  m_sampleBuffer.push_back(Sample(s.imag(), s.real()));
226  } else {
227  m_sampleBuffer.push_back(Sample(s.real(), s.imag()));
228  }
229  }
230  break;
231  }
232  }
233 };
234 
235 #endif // INCLUDE_CHANALYZERNG_H
virtual void feed(const SampleVector::const_iterator &begin, const SampleVector::const_iterator &end, bool positiveOnly)
Definition: chanalyzer.cpp:78
double getMagSqAvg() const
Definition: chanalyzer.h:129
std::vector< Sample > SampleVector
Definition: dsptypes.h:96
virtual int getNbSinkStreams() const
Definition: chanalyzer.h:147
static MsgConfigureChannelizer * create(int sampleRate, int centerFrequency)
Definition: chanalyzer.h:76
DownChannelizer * m_channelizer
Definition: chanalyzer.h:163
float getDeltaPhi() const
MovingAverageUtil< double, double, 480 > m_channelPowerAvg
Definition: chanalyzer.h:188
Real m_interpolatorDistanceRemain
Definition: chanalyzer.h:179
virtual bool handleMessage(const Message &cmd)
Processing of a message. Returns true if message has actually been processed.
Definition: chanalyzer.cpp:180
Definition: ncof.h:24
fftfilt::cmplx m_sum
Definition: chanalyzer.h:169
float getPhiHat() const
void applyChannelSettings(int inputSampleRate, int inputFrequencyOffset, bool force=false)
Definition: chanalyzer.cpp:236
static MsgReportChannelSampleRateChanged * create()
Definition: chanalyzer.h:97
virtual void destroy()
Definition: chanalyzer.h:111
MsgConfigureChannelAnalyzer(const ChannelAnalyzerSettings &settings, bool force)
Definition: chanalyzer.h:62
std::complex< float > cmplx
Definition: fftfilt.h:21
SampleVector m_sampleBuffer
Definition: chanalyzer.h:187
virtual ~ChannelAnalyzer()
Definition: chanalyzer.cpp:67
#define SDR_RX_SCALEF
Definition: dsptypes.h:33
Real getPllPhase() const
Definition: chanalyzer.h:133
static const QString m_channelId
Definition: chanalyzer.h:158
Real getPllFrequency() const
Definition: chanalyzer.cpp:383
virtual void stop()
Definition: chanalyzer.cpp:176
fftcorr * m_corr
Definition: chanalyzer.h:184
PhaseLockComplex m_pll
Definition: chanalyzer.h:175
const ChannelAnalyzerSettings & getSettings() const
Definition: chanalyzer.h:50
#define MESSAGE_CLASS_DECLARATION
Definition: message.h:43
void applySettings(const ChannelAnalyzerSettings &settings, bool force=false)
Definition: chanalyzer.cpp:297
void setSampleSink(BasebandSampleSink *sampleSink)
Definition: chanalyzer.h:112
virtual qint64 getStreamCenterFrequency(int streamIndex, bool sinkElseSource) const
Definition: chanalyzer.h:150
bool m_useInterpolator
Definition: chanalyzer.h:172
virtual qint64 getCenterFrequency() const
Applies to a default stream.
Definition: chanalyzer.h:142
DownChannelizer * getChannelizer()
Definition: chanalyzer.h:124
virtual bool deserialize(const QByteArray &data)
Definition: chanalyzer.h:145
virtual void getTitle(QString &title)
Definition: chanalyzer.h:141
int m_inputFrequencyOffset
Definition: chanalyzer.h:167
void feedOneSample(const fftfilt::cmplx &s, const fftfilt::cmplx &pll)
Definition: chanalyzer.h:197
virtual void getIdentifier(QString &id)
Definition: chanalyzer.h:140
MsgConfigureChannelizer(int sampleRate, int centerFrequency)
Definition: chanalyzer.h:85
Interpolator m_interpolator
Definition: chanalyzer.h:177
void processOneSample(Complex &c, fftfilt::cmplx *sideband)
Definition: chanalyzer.cpp:115
virtual void start()
Definition: chanalyzer.cpp:171
bool isPllLocked() const
Definition: chanalyzer.h:130
virtual int getNbSourceStreams() const
Definition: chanalyzer.h:148
BasebandSampleSink * m_sampleSink
Definition: chanalyzer.h:186
int getInputSampleRate() const
Definition: chanalyzer.h:125
DeviceAPI * m_deviceAPI
Definition: chanalyzer.h:161
ThreadedBasebandSampleSink * m_threadedChannelizer
Definition: chanalyzer.h:162
QMutex m_settingsMutex
Definition: chanalyzer.h:189
static MsgConfigureChannelAnalyzer * create(const ChannelAnalyzerSettings &settings, bool force)
Definition: chanalyzer.h:53
Real getPllDeltaPhase() const
Definition: chanalyzer.h:132
FreqLockComplex m_fll
Definition: chanalyzer.h:176
Real m_interpolatorDistance
Definition: chanalyzer.h:178
fftfilt * RRCFilter
Definition: chanalyzer.h:183
ChannelAnalyzerSettings m_settings
Definition: chanalyzer.h:164
virtual QByteArray serialize() const
Definition: chanalyzer.h:144
bool locked() const
int m_undersampleCount
Definition: chanalyzer.h:168
std::complex< Real > Complex
Definition: dsptypes.h:43
int getChannelSampleRate() const
Definition: chanalyzer.h:126
static const QString m_channelIdURI
Definition: chanalyzer.h:157
float Real
Definition: dsptypes.h:42
int run(const cmplx &inA, const cmplx *inB, cmplx **out)
if inB = 0 then run auto-correlation
Definition: fftcorr.cpp:62
fftfilt * SSBFilter
Definition: chanalyzer.h:181
double getMagSq() const
Definition: chanalyzer.h:128
void setFilters(int sampleRate, float bandwidth, float lowCutoff)
Definition: chanalyzer.cpp:270
ChannelAnalyzer(DeviceAPI *deviceAPI)
Definition: chanalyzer.cpp:35
fftfilt * DSBFilter
Definition: chanalyzer.h:182
int getDecimation() const
Definition: chanalyzer.h:127