mirror of
https://github.com/g4klx/MMDVMHost
synced 2025-12-21 06:55:52 +08:00
Rename the IIR filter class.
This commit is contained in:
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (C) 2020,2021 by Jonathan Naylor G4KLX
|
* Copyright (C) 2020,2021,2024 by Jonathan Naylor G4KLX
|
||||||
*
|
*
|
||||||
* This program is free software; you can redistribute it and/or modify
|
* This program is free software; you can redistribute it and/or modify
|
||||||
* it under the terms of the GNU General Public License as published by
|
* it under the terms of the GNU General Public License as published by
|
||||||
@@ -48,13 +48,13 @@ m_filterStage3(NULL)
|
|||||||
assert(txAudioGain > 0.0F);
|
assert(txAudioGain > 0.0F);
|
||||||
assert(rxAudioGain > 0.0F);
|
assert(rxAudioGain > 0.0F);
|
||||||
|
|
||||||
m_preEmphasis = new CIIRDirectForm1Filter(8.315375384336983F, -7.03334621603483F,0.0F,1.0F, 0.282029168302153F,0.0F, PREEMPHASIS_GAIN_DB);
|
m_preEmphasis = new CIIR(8.315375384336983F, -7.03334621603483F,0.0F, 1.0F, 0.282029168302153F, 0.0F, PREEMPHASIS_GAIN_DB);
|
||||||
m_deEmphasis = new CIIRDirectForm1Filter(0.07708787090460224F, 0.07708787090460224F,0.0F, 1.0F, -0.8458242581907955F,0.0F, DEEMPHASIS_GAIN_DB);
|
m_deEmphasis = new CIIR(0.07708787090460224F, 0.07708787090460224F,0.0F, 1.0F, -0.8458242581907955F, 0.0F, DEEMPHASIS_GAIN_DB);
|
||||||
|
|
||||||
// Chebyshev type 1 0.2dB cheby type 1 3rd order 300-2700Hz fs=8000
|
// Chebyshev type 1 0.2dB cheby type 1 3rd order 300-2700Hz fs=8000
|
||||||
m_filterStage1 = new CIIRDirectForm1Filter(0.29495028f, 0.0f, -0.29495028f, 1.0f, -0.61384624f, -0.057158668f, FILTER_GAIN_DB);
|
m_filterStage1 = new CIIR(0.29495028f, 0.0f, -0.29495028f, 1.0f, -0.61384624f, -0.057158668f, FILTER_GAIN_DB);
|
||||||
m_filterStage2 = new CIIRDirectForm1Filter(1.0f, 2.0f, 1.0f, 1.0f, 0.9946123f, 0.6050482f, FILTER_GAIN_DB);
|
m_filterStage2 = new CIIR(1.0f, 2.0f, 1.0f, 1.0f, 0.9946123f, 0.6050482f, FILTER_GAIN_DB);
|
||||||
m_filterStage3 = new CIIRDirectForm1Filter(1.0f, -2.0f, 1.0f, 1.0f, -1.8414584f, 0.8804949f, FILTER_GAIN_DB);
|
m_filterStage3 = new CIIR(1.0f, -2.0f, 1.0f, 1.0f, -1.8414584f, 0.8804949f, FILTER_GAIN_DB);
|
||||||
}
|
}
|
||||||
|
|
||||||
CFMControl::~CFMControl()
|
CFMControl::~CFMControl()
|
||||||
|
|||||||
14
FMControl.h
14
FMControl.h
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (C) 2020,2021 by Jonathan Naylor G4KLX
|
* Copyright (C) 2020,2021,2024 by Jonathan Naylor G4KLX
|
||||||
*
|
*
|
||||||
* This program is free software; you can redistribute it and/or modify
|
* This program is free software; you can redistribute it and/or modify
|
||||||
* it under the terms of the GNU General Public License as published by
|
* it under the terms of the GNU General Public License as published by
|
||||||
@@ -21,7 +21,7 @@
|
|||||||
|
|
||||||
#include "FMNetwork.h"
|
#include "FMNetwork.h"
|
||||||
#include "Defines.h"
|
#include "Defines.h"
|
||||||
#include "IIRDirectForm1Filter.h"
|
#include "IIR.h"
|
||||||
|
|
||||||
// Uncomment this to dump audio to a raw audio file
|
// Uncomment this to dump audio to a raw audio file
|
||||||
// The file will be written in same folder as executable
|
// The file will be written in same folder as executable
|
||||||
@@ -49,11 +49,11 @@ private:
|
|||||||
bool m_deEmphasisOn;
|
bool m_deEmphasisOn;
|
||||||
bool m_enabled;
|
bool m_enabled;
|
||||||
CRingBuffer<unsigned char> m_incomingRFAudio;
|
CRingBuffer<unsigned char> m_incomingRFAudio;
|
||||||
CIIRDirectForm1Filter* m_preEmphasis;
|
CIIR* m_preEmphasis;
|
||||||
CIIRDirectForm1Filter* m_deEmphasis;
|
CIIR* m_deEmphasis;
|
||||||
CIIRDirectForm1Filter* m_filterStage1;
|
CIIR* m_filterStage1;
|
||||||
CIIRDirectForm1Filter* m_filterStage2;
|
CIIR* m_filterStage2;
|
||||||
CIIRDirectForm1Filter* m_filterStage3;
|
CIIR* m_filterStage3;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (C) 2015-2020 by Jonathan Naylor G4KLX
|
* Copyright (C) 2015-2020,2024 by Jonathan Naylor G4KLX
|
||||||
* Copyright (C) 2020 by Geoffrey Merck - F4FXL KC3FRA
|
* Copyright (C) 2020 by Geoffrey Merck - F4FXL KC3FRA
|
||||||
*
|
*
|
||||||
* This program is free software; you can redistribute it and/or modify
|
* This program is free software; you can redistribute it and/or modify
|
||||||
@@ -17,10 +17,11 @@
|
|||||||
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "IIRDirectForm1Filter.h"
|
#include "IIR.h"
|
||||||
#include "math.h"
|
|
||||||
|
|
||||||
CIIRDirectForm1Filter::CIIRDirectForm1Filter(float b0, float b1, float b2, float , float a1, float a2, float addtionalGaindB) :
|
#include <cmath>
|
||||||
|
|
||||||
|
CIIR::CIIR(float b0, float b1, float b2, float , float a1, float a2, float addtionalGaindB) :
|
||||||
m_x2(0.0F),
|
m_x2(0.0F),
|
||||||
m_y2(0.0F),
|
m_y2(0.0F),
|
||||||
m_x1(0.0F),
|
m_x1(0.0F),
|
||||||
@@ -32,29 +33,29 @@ m_a1(a1),
|
|||||||
m_a2(a2),
|
m_a2(a2),
|
||||||
m_additionalGainLin(0.0F)
|
m_additionalGainLin(0.0F)
|
||||||
{
|
{
|
||||||
m_additionalGainLin = ::powf(10.0F, addtionalGaindB / 20.0F);
|
m_additionalGainLin = ::powf(10.0F, addtionalGaindB / 20.0F);
|
||||||
}
|
}
|
||||||
|
|
||||||
float CIIRDirectForm1Filter::filter(float sample)
|
CIIR::~CIIR()
|
||||||
{
|
{
|
||||||
float output = m_b0 * sample
|
|
||||||
+ m_b1 * m_x1
|
|
||||||
+ m_b2 * m_x2
|
|
||||||
- m_a1 * m_y1
|
|
||||||
- m_a2 * m_y2;
|
|
||||||
|
|
||||||
m_x2 = m_x1;
|
|
||||||
m_y2 = m_y1;
|
|
||||||
m_x1 = sample;
|
|
||||||
m_y1 = output;
|
|
||||||
|
|
||||||
return output * m_additionalGainLin;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void CIIRDirectForm1Filter::reset()
|
float CIIR::filter(float sample)
|
||||||
{
|
{
|
||||||
m_x1 = 0.0f;
|
float output = m_b0 * sample + m_b1 * m_x1 + m_b2 * m_x2 - m_a1 * m_y1 - m_a2 * m_y2;
|
||||||
m_x2 = 0.0f;
|
|
||||||
m_y1 = 0.0f;
|
m_x2 = m_x1;
|
||||||
m_y2 = 0.0f;
|
m_y2 = m_y1;
|
||||||
|
m_x1 = sample;
|
||||||
|
m_y1 = output;
|
||||||
|
|
||||||
|
return output * m_additionalGainLin;
|
||||||
|
}
|
||||||
|
|
||||||
|
void CIIR::reset()
|
||||||
|
{
|
||||||
|
m_x1 = 0.0F;
|
||||||
|
m_x2 = 0.0F;
|
||||||
|
m_y1 = 0.0F;
|
||||||
|
m_y2 = 0.0F;
|
||||||
}
|
}
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (C) 2015-2020 by Jonathan Naylor G4KLX
|
* Copyright (C) 2015-2020,2024 by Jonathan Naylor G4KLX
|
||||||
* Copyright (C) 2020 by Geoffrey Merck - F4FXL KC3FRA
|
* Copyright (C) 2020 by Geoffrey Merck - F4FXL KC3FRA
|
||||||
*
|
*
|
||||||
* This program is free software; you can redistribute it and/or modify
|
* This program is free software; you can redistribute it and/or modify
|
||||||
@@ -17,34 +17,33 @@
|
|||||||
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#if !defined(IIRDIRECTFORM1FILTER_H)
|
#if !defined(IIR_H)
|
||||||
#define IIRDIRECTFORM1FILTER_H
|
#define IIR_H
|
||||||
|
|
||||||
class CIIRDirectForm1Filter
|
class CIIR
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
CIIRDirectForm1Filter(float b0, float b1, float b2, float, float a1, float a2, float additionalGaindB);
|
CIIR(float b0, float b1, float b2, float, float a1, float a2, float additionalGaindB);
|
||||||
float filter(float sample);
|
~CIIR();
|
||||||
void reset();
|
|
||||||
|
float filter(float sample);
|
||||||
|
|
||||||
|
void reset();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
// delay line
|
// Delay line
|
||||||
float m_x2; // x[n-2]
|
float m_x2; // x[n-2]
|
||||||
float m_y2; // y[n-2]
|
float m_y2; // y[n-2]
|
||||||
float m_x1; // x[n-1]
|
float m_x1; // x[n-1]
|
||||||
float m_y1; // y[n-1]
|
float m_y1; // y[n-1]
|
||||||
|
|
||||||
// coefficients
|
|
||||||
// FIR
|
|
||||||
float m_b0;
|
|
||||||
float m_b1;
|
|
||||||
float m_b2;
|
|
||||||
// IIR
|
|
||||||
float m_a1;
|
|
||||||
float m_a2;
|
|
||||||
|
|
||||||
float m_additionalGainLin;
|
// Coefficients
|
||||||
|
float m_b0;
|
||||||
|
float m_b1;
|
||||||
|
float m_b2;
|
||||||
|
float m_a1;
|
||||||
|
float m_a2;
|
||||||
|
float m_additionalGainLin;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
#endif
|
||||||
#endif
|
|
||||||
@@ -204,7 +204,7 @@
|
|||||||
<ClInclude Include="Golay24128.h" />
|
<ClInclude Include="Golay24128.h" />
|
||||||
<ClInclude Include="Hamming.h" />
|
<ClInclude Include="Hamming.h" />
|
||||||
<ClInclude Include="DMRLookup.h" />
|
<ClInclude Include="DMRLookup.h" />
|
||||||
<ClInclude Include="IIRDirectForm1Filter.h" />
|
<ClInclude Include="IIR.h" />
|
||||||
<ClInclude Include="LCDproc.h" />
|
<ClInclude Include="LCDproc.h" />
|
||||||
<ClInclude Include="Log.h" />
|
<ClInclude Include="Log.h" />
|
||||||
<ClInclude Include="M17Control.h" />
|
<ClInclude Include="M17Control.h" />
|
||||||
@@ -315,7 +315,7 @@
|
|||||||
<ClCompile Include="Golay2087.cpp" />
|
<ClCompile Include="Golay2087.cpp" />
|
||||||
<ClCompile Include="Golay24128.cpp" />
|
<ClCompile Include="Golay24128.cpp" />
|
||||||
<ClCompile Include="Hamming.cpp" />
|
<ClCompile Include="Hamming.cpp" />
|
||||||
<ClCompile Include="IIRDirectForm1Filter.cpp" />
|
<ClCompile Include="IIR.cpp" />
|
||||||
<ClCompile Include="LCDproc.cpp" />
|
<ClCompile Include="LCDproc.cpp" />
|
||||||
<ClCompile Include="Log.cpp" />
|
<ClCompile Include="Log.cpp" />
|
||||||
<ClCompile Include="M17Control.cpp" />
|
<ClCompile Include="M17Control.cpp" />
|
||||||
|
|||||||
@@ -317,7 +317,7 @@
|
|||||||
<ClInclude Include="FMControl.h">
|
<ClInclude Include="FMControl.h">
|
||||||
<Filter>Header Files</Filter>
|
<Filter>Header Files</Filter>
|
||||||
</ClInclude>
|
</ClInclude>
|
||||||
<ClInclude Include="IIRDirectForm1Filter.h">
|
<ClInclude Include="IIR.h">
|
||||||
<Filter>Header Files</Filter>
|
<Filter>Header Files</Filter>
|
||||||
</ClInclude>
|
</ClInclude>
|
||||||
<ClInclude Include="PseudoTTYController.h">
|
<ClInclude Include="PseudoTTYController.h">
|
||||||
@@ -625,7 +625,7 @@
|
|||||||
<ClCompile Include="FMControl.cpp">
|
<ClCompile Include="FMControl.cpp">
|
||||||
<Filter>Source Files</Filter>
|
<Filter>Source Files</Filter>
|
||||||
</ClCompile>
|
</ClCompile>
|
||||||
<ClCompile Include="IIRDirectForm1Filter.cpp">
|
<ClCompile Include="IIR.cpp">
|
||||||
<Filter>Source Files</Filter>
|
<Filter>Source Files</Filter>
|
||||||
</ClCompile>
|
</ClCompile>
|
||||||
<ClCompile Include="PseudoTTYController.cpp">
|
<ClCompile Include="PseudoTTYController.cpp">
|
||||||
|
|||||||
Reference in New Issue
Block a user