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
|
|
@ -45,6 +45,10 @@ The following [infinite impulse response](https://en.wikipedia.org/wiki/Infinite
|
|||
|
||||
A [notch filter at DC](https://en.wikipedia.org/wiki/Band-stop_filter) helps removing [DC bias](https://en.wikipedia.org/wiki/DC_bias).
|
||||
|
||||
### [normalize.hh](normalize.hh)
|
||||
|
||||
Normalizers for [periodic](https://en.wikipedia.org/wiki/Periodic_function) signals.
|
||||
|
||||
### [phasor.hh](phasor.hh)
|
||||
|
||||
[Numerically controlled oscillator](https://en.wikipedia.org/wiki/Numerically_controlled_oscillator) implemented using a [phasor](https://en.wikipedia.org/wiki/Phasor) and [complex multiplication](https://en.wikipedia.org/wiki/Complex_number#Multiplication) instead of a [lookup table](https://en.wikipedia.org/wiki/Lookup_table).
|
||||
|
|
|
|||
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