File: correct_iq.cpp

package info (click to toggle)
satdump 1.2.2%2Bgb79af48-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 81,648 kB
  • sloc: cpp: 276,768; ansic: 164,598; lisp: 1,219; sh: 283; xml: 106; makefile: 7
file content (39 lines) | stat: -rw-r--r-- 1,100 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
#include "correct_iq.h"

namespace dsp
{
    template <typename T>
    CorrectIQBlock<T>::CorrectIQBlock(std::shared_ptr<dsp::stream<T>> input, float alpha)
        : Block<T, T>(input)
    {
        beta = 1.0f - alpha;
    }

    template <typename T>
    CorrectIQBlock<T>::~CorrectIQBlock()
    {
    }

    template <typename T>
    void CorrectIQBlock<T>::work()
    {
        int nsamples = Block<T, T>::input_stream->read();
        if (nsamples <= 0)
        {
            Block<T, T>::input_stream->flush();
            return;
        }

        for (int i = 0; i < nsamples; i++)
        {
            acc = acc * beta + Block<T, T>::input_stream->readBuf[i] * alpha;                      // Compute a moving average, of both I & Q
            Block<T, T>::output_stream->writeBuf[i] = Block<T, T>::input_stream->readBuf[i] - acc; // Substract it to the input buffer, moving back to 0
        }

        Block<T, T>::input_stream->flush();
        Block<T, T>::output_stream->swap(nsamples);
    }

    template class CorrectIQBlock<complex_t>;
    template class CorrectIQBlock<float>;
}