Skip to content

Commit

Permalink
fix noise level fluctuation during tx
Browse files Browse the repository at this point in the history
  • Loading branch information
sannysanoff committed Jun 3, 2024
1 parent 4f9a210 commit ce5b9e5
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 14 deletions.
34 changes: 23 additions & 11 deletions core/src/dsp/compression/experimental_fft_compressor.h
Original file line number Diff line number Diff line change
Expand Up @@ -147,9 +147,12 @@ namespace dsp::compression {
cma = centeredSma(cma, largeTick); // cleared noise floor.

auto mask = npzeros(fftSize);
for (int i = 0; i < fftSize; i++) {
if (clearMags->at(i) > cma->at(i) + allowance) { // allowance = normal noise variance
mask->at(i) = 1;
if (!txMode) {
// for rx mode, add good signals to mask, for tx assume no signals at all. Mask will be used to filter signal.
for (int i = 0; i < fftSize; i++) {
if (clearMags->at(i) > cma->at(i) + allowance) { // allowance = normal noise variance
mask->at(i) = 1;
}
}
}
for(int i=0; i<maskedFrequencies.size(); i+=2) {
Expand Down Expand Up @@ -187,6 +190,11 @@ namespace dsp::compression {
return rv;
}

bool txMode = false;
void setTxMode(int txMode) {
this->txMode = txMode;
}

inline int process() {

if (inputBuffer.size() < fftSize) {
Expand All @@ -202,17 +210,19 @@ namespace dsp::compression {

auto spectrumOut = npzeros(fftSize);
volk_32fc_s32f_power_spectrum_32f(spectrumOut->data(), (const lv_32fc_t *) out->data(), fftSize, fftSize);
cleanMagnitudes.emplace_back(spectrumOut);
if (!txMode) {
cleanMagnitudes.emplace_back(spectrumOut);
}

// applying window to get windowed windowedSpectrum
volk_32fc_32f_multiply_32fc((lv_32fc_t*)inArray->data(), (lv_32fc_t*)inArray->data(), fftWindow.data(), fftSize);
out = fftPlan->npfftfft(inArray);
swapfft(out);
auto windowedSpectrumOut = npzeros(fftSize);
volk_32fc_s32f_power_spectrum_32f(windowedSpectrumOut->data(), (const lv_32fc_t *) out->data(), fftSize, fftSize);
windowedMagnitudes.emplace_back(windowedSpectrumOut);


if (!txMode) {
windowedMagnitudes.emplace_back(windowedSpectrumOut);
}

if (cleanFreqDomain.size() < minRecents) {
return 0;
Expand All @@ -236,10 +246,12 @@ namespace dsp::compression {

if (lossRate > 0) {
auto nf = filterSignal(windowedSpectrum, clearSpectrum, this->out.writeBuf); // result is filtered writebuf
auto newNoiseFigure = estimateNoise(nf); // i/q variance estimate, output is in noise figure.
sharedDataLock.lock();
noiseFigure = newNoiseFigure;
sharedDataLock.unlock();
if (!txMode) {
auto newNoiseFigure = estimateNoise(nf); // i/q variance estimate, output is in noise figure.
sharedDataLock.lock();
noiseFigure = newNoiseFigure;
sharedDataLock.unlock();
}
}
auto unfiltered = this->out.writeBuf;
for(int i=0; i<fftSize; i++) {
Expand Down
7 changes: 4 additions & 3 deletions core/src/server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -316,8 +316,9 @@ namespace server {


int lastSentTXStatus = 0;
void setTxStatus(bool status) {
sigpath::transmitter->setTransmitStatus(status);
void setTxStatus(bool transmitFlag) {
fftCompressor.setTxMode(transmitFlag);
sigpath::transmitter->setTransmitStatus(transmitFlag);
int currentTXStatus = sigpath::transmitter->getTXStatus();
if (currentTXStatus != lastSentTXStatus) {
sendTransmitAction();
Expand Down Expand Up @@ -437,7 +438,7 @@ namespace server {
if (client) {
if (client->isOpen()) {
client->write(bb_pkt_hdr->size, bbuf);
if (fftCompressor.isEnabled() && frameCount % 20 == 1) {
if (fftCompressor.isEnabled() && frameCount % 20 == 1 && (sigpath::transmitter == nullptr || sigpath::transmitter->getTXStatus() == 0)) {
fftCompressor.sharedDataLock.lock();
auto nbytes = fftCompressor.noiseFigure.size() * sizeof(fftCompressor.noiseFigure[0]);
memcpy(s_cmd_data, fftCompressor.noiseFigure.data(), nbytes);
Expand Down

0 comments on commit ce5b9e5

Please sign in to comment.