mirror of
https://github.com/aicodix/dsp.git
synced 2026-04-27 14:30:36 +00:00
added normalizer for sinusoidal signal
This commit is contained in:
parent
65383970a7
commit
c7f3cdd565
2 changed files with 57 additions and 0 deletions
53
normalize.hh
Normal file
53
normalize.hh
Normal file
|
|
@ -0,0 +1,53 @@
|
|||
/*
|
||||
Normalizers for periodic signals
|
||||
|
||||
Copyright 2019 Ahmet Inan <inan@aicodix.de>
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "blockdc.hh"
|
||||
#include "ema.hh"
|
||||
|
||||
namespace DSP {
|
||||
|
||||
template <typename TYPE>
|
||||
class NormalizeSine
|
||||
{
|
||||
DSP::BlockDC<TYPE, TYPE> hpf;
|
||||
DSP::EMA<TYPE, TYPE> lpf;
|
||||
public:
|
||||
constexpr NormalizeSine() : lpf(1)
|
||||
{
|
||||
}
|
||||
void samples(int s)
|
||||
{
|
||||
hpf.samples(s);
|
||||
lpf.samples(s);
|
||||
}
|
||||
TYPE operator()(TYPE input)
|
||||
{
|
||||
TYPE tmp = hpf(input);
|
||||
TYPE amp = sqrt(TYPE(2) * lpf(tmp * tmp));
|
||||
return tmp / amp;
|
||||
}
|
||||
};
|
||||
|
||||
template <typename COMPLEX>
|
||||
class NormalizeIQ
|
||||
{
|
||||
NormalizeSine<typename COMPLEX::value_type> ni, nq;
|
||||
public:
|
||||
void samples(int s)
|
||||
{
|
||||
ni.samples(s);
|
||||
nq.samples(s);
|
||||
}
|
||||
COMPLEX operator()(COMPLEX iq)
|
||||
{
|
||||
return COMPLEX(ni(iq.real()), nq(iq.imag()));
|
||||
}
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
Loading…
Add table
Add a link
Reference in a new issue