From c7f3cdd565c544c2f28a39baa1bffe38e4cddada Mon Sep 17 00:00:00 2001 From: Ahmet Inan Date: Mon, 25 Feb 2019 13:00:58 +0100 Subject: [PATCH] added normalizer for sinusoidal signal --- README.md | 4 ++++ normalize.hh | 53 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 57 insertions(+) create mode 100644 normalize.hh diff --git a/README.md b/README.md index 5c4ed86..2673637 100644 --- a/README.md +++ b/README.md @@ -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). diff --git a/normalize.hh b/normalize.hh new file mode 100644 index 0000000..6f939bd --- /dev/null +++ b/normalize.hh @@ -0,0 +1,53 @@ +/* +Normalizers for periodic signals + +Copyright 2019 Ahmet Inan +*/ + +#pragma once + +#include "blockdc.hh" +#include "ema.hh" + +namespace DSP { + +template +class NormalizeSine +{ + DSP::BlockDC hpf; + DSP::EMA 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 +class NormalizeIQ +{ + NormalizeSine 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())); + } +}; + +} +