From 6944ed8ea930e382bfecb31e67fccafbe3daf461 Mon Sep 17 00:00:00 2001 From: John Greb Date: Wed, 17 Dec 2014 21:06:02 +0000 Subject: [PATCH] TCP SSB FFT. --- plugins/channel/tcpsrc/tcpsrc.cpp | 25 ++++++++++++++++++------- plugins/channel/tcpsrc/tcpsrc.h | 6 +++++- 2 files changed, 23 insertions(+), 8 deletions(-) diff --git a/plugins/channel/tcpsrc/tcpsrc.cpp b/plugins/channel/tcpsrc/tcpsrc.cpp index 57d08ee5b..69c6b247d 100644 --- a/plugins/channel/tcpsrc/tcpsrc.cpp +++ b/plugins/channel/tcpsrc/tcpsrc.cpp @@ -25,6 +25,9 @@ TCPSrc::TCPSrc(MessageQueue* uiMessageQueue, TCPSrcGUI* tcpSrcGUI, SampleSink* s m_spectrumEnabled = false; m_nextSSBId = 0; m_nextS16leId = 0; + + TCPFilter = new fftfilt(0.01, 16.0 / 48.0, ssbFftLen); + // if (!TCPFilter) segfault; } TCPSrc::~TCPSrc() @@ -46,6 +49,11 @@ void TCPSrc::setSpectrum(MessageQueue* messageQueue, bool enabled) void TCPSrc::feed(SampleVector::const_iterator begin, SampleVector::const_iterator end, bool positiveOnly) { Complex ci; + Complex* sideband; + + m_sampleBuffer.clear(); + m_sampleBufferSSB.clear(); + for(SampleVector::const_iterator it = begin; it < end; ++it) { Complex c(it->real() / 32768.0, it->imag() / 32768.0); c *= m_nco.nextIQ(); @@ -64,15 +72,17 @@ void TCPSrc::feed(SampleVector::const_iterator begin, SampleVector::const_iterat if(m_ssbSockets.count() > 0) { for(SampleVector::const_iterator it = m_sampleBuffer.begin(); it != m_sampleBuffer.end(); ++it) { - // TODO: fft filter - m_sampleBufferSSB.push_back(it->real() + it->imag()); + Complex cj(it->real() / 20000.0, it->imag() / 20000.0); + int n_out = TCPFilter->run(cj, &sideband, true); + for (int i = 0; i < n_out; i+=2) { + Real one = (sideband[i].real() + sideband[i].imag()) * 0.7 * 20000.0; + Real two = (sideband[i+1].real() + sideband[i+1].imag()) * 0.7 * 20000.0; + m_sampleBufferSSB.push_back(Sample(one, two)); + } + for(int i = 0; (n_out > 0) && (i < m_ssbSockets.count()); i++) + m_ssbSockets[i].socket->write((const char*)&m_sampleBufferSSB[0], n_out * 2); } - for(int i = 0; i < m_ssbSockets.count(); i++) - m_ssbSockets[i].socket->write((const char*)&m_sampleBufferSSB[0], m_sampleBufferSSB.size()); } - - m_sampleBuffer.clear(); - m_sampleBufferSSB.clear(); } void TCPSrc::start() @@ -116,6 +126,7 @@ bool TCPSrc::handleMessage(Message* cmd) } m_interpolator.create(16, m_inputSampleRate, m_rfBandwidth / 2.1); m_sampleDistanceRemain = m_inputSampleRate / m_outputSampleRate; + TCPFilter->create_filter(0.3f / 48.0f, m_rfBandwidth / 2.0 / m_outputSampleRate); cmd->completed(); return true; } else if(MsgTCPSrcSpectrum::match(cmd)) { diff --git a/plugins/channel/tcpsrc/tcpsrc.h b/plugins/channel/tcpsrc/tcpsrc.h index 8e56eff07..b39e63cb1 100644 --- a/plugins/channel/tcpsrc/tcpsrc.h +++ b/plugins/channel/tcpsrc/tcpsrc.h @@ -4,9 +4,12 @@ #include #include "dsp/samplesink.h" #include "dsp/nco.h" +#include "dsp/fftfilt.h" #include "dsp/interpolator.h" #include "util/message.h" +#define ssbFftLen 1024 + class QTcpServer; class QTcpSocket; class TCPSrcGUI; @@ -122,9 +125,10 @@ protected: NCO m_nco; Interpolator m_interpolator; Real m_sampleDistanceRemain; + fftfilt* TCPFilter; SampleVector m_sampleBuffer; - std::vector m_sampleBufferSSB; + SampleVector m_sampleBufferSSB; SampleSink* m_spectrum; bool m_spectrumEnabled;