satdump/src-core/common/dsp/correct_iq.cpp
2022-02-14 21:16:24 +01:00

32 lines
No EOL
780 B
C++

#include "correct_iq.h"
namespace dsp
{
CorrectIQBlock::CorrectIQBlock(std::shared_ptr<dsp::stream<complex_t>> input)
: Block(input)
{
}
CorrectIQBlock::~CorrectIQBlock()
{
}
void CorrectIQBlock::work()
{
int nsamples = input_stream->read();
if (nsamples <= 0)
{
input_stream->flush();
return;
}
for (int i = 0; i < nsamples; i++)
{
acc = acc * beta + input_stream->readBuf[i] * alpha; // Compute a moving average, of both I & Q
output_stream->writeBuf[i] = input_stream->readBuf[i] - acc; // Substract it to the input buffer, moving back to 0
}
input_stream->flush();
output_stream->swap(nsamples);
}
}