mirror of
https://github.com/aicodix/dsp.git
synced 2026-04-27 14:30:36 +00:00
added AM demodulator with AGC
This commit is contained in:
parent
70dc3392fe
commit
d2b1bf32b4
2 changed files with 47 additions and 0 deletions
|
|
@ -48,6 +48,10 @@ The following [infinite impulse response](https://en.wikipedia.org/wiki/Infinite
|
|||
|
||||
[Frequency modulation](https://en.wikipedia.org/wiki/Frequency_modulation) [demodulation](https://en.wikipedia.org/wiki/Demodulation) with and without [atan2](https://en.wikipedia.org/wiki/Atan2).
|
||||
|
||||
### [amd.hh](amd.hh)
|
||||
|
||||
[Amplitude modulation](https://en.wikipedia.org/wiki/Amplitude_modulation) [demodulation](https://en.wikipedia.org/wiki/Demodulation) with [automatic gain control](https://en.wikipedia.org/wiki/Automatic_gain_control).
|
||||
|
||||
### [atan2.hh](atan2.hh)
|
||||
|
||||
[atan](https://en.wikipedia.org/wiki/Inverse_trigonometric_functions) and [atan2](https://en.wikipedia.org/wiki/Atan2).
|
||||
|
|
|
|||
43
amd.hh
Normal file
43
amd.hh
Normal file
|
|
@ -0,0 +1,43 @@
|
|||
/*
|
||||
AM Demodulation
|
||||
|
||||
Copyright 2019 Ahmet Inan <inan@aicodix.de>
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
namespace DSP {
|
||||
|
||||
template <typename TYPE>
|
||||
class AMD1
|
||||
{
|
||||
typedef TYPE complex_type;
|
||||
typedef typename complex_type::value_type value_type;
|
||||
value_type avg, att, dec, lo, hi, idx;
|
||||
public:
|
||||
AMD1() : avg(0), att(0), dec(0), lo(0.001), hi(1), idx(1)
|
||||
{
|
||||
}
|
||||
void index(value_type modidx)
|
||||
{
|
||||
idx = modidx;
|
||||
}
|
||||
void agc(value_type attack, value_type decay, value_type low = value_type(0.001), value_type high = value_type(1))
|
||||
{
|
||||
att = attack;
|
||||
dec = decay;
|
||||
lo = low;
|
||||
hi = high;
|
||||
}
|
||||
value_type operator()(complex_type input)
|
||||
{
|
||||
value_type amp = abs(input);
|
||||
avg = lerp(amp < avg ? dec : att, avg, amp);
|
||||
avg = min(max(avg, lo), hi);
|
||||
amp /= avg;
|
||||
return (amp * (value_type(1)+idx) - value_type(1)) / idx;
|
||||
}
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
Loading…
Add table
Add a link
Reference in a new issue