Commit e3e273f0 authored by Dipl.-Ing. Jonas Stienen's avatar Dipl.-Ing. Jonas Stienen
Browse files

Cleaning up IIR coefficients

parent c8c45c77
......@@ -29,7 +29,8 @@ namespace ITADSP
{
enum FilterDesignAlgorithm //used to select the algorithm used to design filter coefficients
{
BURG = 0, //Use the Burg algorithm for designing the filter coefficients
UNSPECIFIED = 0,
BURG = 1, //Use the Burg algorithm for designing the filter coefficients
};
struct CIIRCoefficients
......@@ -41,6 +42,7 @@ namespace ITADSP
std::vector< float > vfDenominator;
CIIRCoefficients( unsigned int uiOrder = 0, bool is_ARMA_init = true )
: design_algorithm( ITADSP::UNSPECIFIED )
{
Initialise(uiOrder, is_ARMA_init);
};
......@@ -71,13 +73,17 @@ namespace ITADSP
inline void SetZero()
{
for( size_t i = 1; i < vfNumerator.size(); i++ )
vfNumerator[ i ] = 0.0f;
};
inline void SetIdentity()
{
SetZero();
vfNumerator[ 0 ] = 1;
vfDenominator[ 0 ] = 1.0f;
for( size_t i = 1; i < vfDenominator.size(); i++ )
vfDenominator[ i ] = 0.0f;
};
};
......
......@@ -48,15 +48,13 @@ void CITAIIRFilterEngine::SetCoefficients( const ITADSP::CIIRCoefficients& oCoef
if( oCoefficients.uiOrder != m_oCoeffs.uiOrder )
ITA_EXCEPT_INVALID_PARAMETER( "Order missmatch in coefficients" );
//if( oCoefficients.vfNumerator.size() != m_oCoeffs.vfNumerator.size() )
// ITA_EXCEPT_INVALID_PARAMETER( "Number of numerator does not match filter order" );
if( oCoefficients.vfNumerator.size() != m_oCoeffs.vfNumerator.size() )
ITA_EXCEPT_INVALID_PARAMETER( "Numerator count mismatch" );
if( oCoefficients.vfDenominator.size() != m_oCoeffs.vfDenominator.size() )
ITA_EXCEPT_INVALID_PARAMETER( "Number of denominator does not match filter order" );
ITA_EXCEPT_INVALID_PARAMETER( "Denominator count mismatch" );
m_oCoeffs = oCoefficients;
//m_oCoeffs.vfNumerator = oCoefficients.vfNumerator;
//m_oCoeffs.vfDenominator = oCoefficients.vfDenominator;
}
void CITAIIRFilterEngine::ClearAccumulators()
......
......@@ -35,30 +35,46 @@ const double g_dSampleRate = 44100;
int main( int, char** )
{
ITASampleBuffer sbInput( 1024 );
sbInput[ 0 ] = 1.0f;
const float* pfIn = sbInput.GetData();
int iSamples = sbInput.GetLength();
ITASampleBuffer sbOutput( 1024 );
float* pfOut = sbOutput.GetData();
ITADSP::CIIRCoefficients oCoeffs;
oCoeffs.uiOrder = 2;
oCoeffs.vfNumerator = { 1, 2, 1 };
oCoeffs.vfDenominator = { 0.56f, 0.78f };
oCoeffs.vfDenominator = { 1, 0.56f, 0.78f };
oCoeffs.is_ARMA = true;
#ifdef WITH_JSON_SUPPORT
ITADSP::ExportIIRCoefficientsToJSON( "ITADSPIIRFilterTest_coeffs.json", oCoeffs );
#endif
CITAIIRFilterEngine oIIRFilterEngine( oCoeffs.uiOrder );
oIIRFilterEngine.SetCoefficients( oCoeffs );
oIIRFilterEngine.Process( pfIn, pfOut, iSamples );
writeAudiofile( "ITADSPIIRFilterTest_out.wav", &sbOutput, g_dSampleRate );
ITASampleBuffer sbInput( 1024 );
sbInput[ 0 ] = 1.0f;
const float* pfIn = sbInput.GetData();
int iSamples = sbInput.GetLength();
ITASampleBuffer sbOutput( 1024 );
float* pfOut = sbOutput.GetData();
oIIRFilterEngine.Process( pfIn, pfOut, iSamples );
CITAIIRFilterEngine oIIRFilterEngine_Uninitialized( oCoeffs.uiOrder );
oIIRFilterEngine_Uninitialized.Process( pfIn, pfOut, iSamples );
writeAudiofile( "ITADSPIIRFilterTest_out_uninitialized.wav", &sbOutput, g_dSampleRate );
CITAIIRFilterEngine oIIRFilterEngine_Identity( oCoeffs.uiOrder );
oIIRFilterEngine_Identity.SetCoefficientsToIdentity();
oIIRFilterEngine_Identity.Process( pfIn, pfOut, iSamples );
writeAudiofile( "ITADSPIIRFilterTest_out_identity.wav", &sbOutput, g_dSampleRate );
CITAIIRFilterEngine oIIRFilterEngine_Zero( oCoeffs.uiOrder );
oIIRFilterEngine_Zero.SetCoefficientsToZero();
oIIRFilterEngine_Zero.Process( pfIn, pfOut, iSamples );
writeAudiofile( "ITADSPIIRFilterTest_out_zero.wav", &sbOutput, g_dSampleRate );
std::string sFilePath = "ITADSPIIRFilterTest_out.wav";
writeAudiofile( sFilePath, &sbOutput, g_dSampleRate );
return 255;
......
......@@ -4,6 +4,16 @@
ITADSPIIRFilterTest_out = ita_read( 'ITADSPIIRFilterTest_out.wav' );
%ITADSPIIRFilterTest_out = ITADSPIIRFilterTest_out .* 0.004603998475022463843231435021152719855;
ITADSPIIRFilterTest_out.pt
%ITADSPIIRFilterTest_out.pt
ITADSPIIRFilterTest_coeffs = jsondecode( fileread( 'ITADSPIIRFilterTest_coeffs.json' ) )
ITADSPIIRFilterTest_out_uninitialized = ita_read( 'ITADSPIIRFilterTest_out_uninitialized.wav' );
ITADSPIIRFilterTest_out_identity = ita_read( 'ITADSPIIRFilterTest_out_identity.wav' );
ITADSPIIRFilterTest_out_zero = ita_read( 'ITADSPIIRFilterTest_out_zero.wav' );
ITADSPIIRFilterTest_out_all = ita_merge( ITADSPIIRFilterTest_out_uninitialized, ITADSPIIRFilterTest_out_identity, ITADSPIIRFilterTest_out_zero );
ITADSPIIRFilterTest_out_all.channelNames = { 'Uninitialized filter engine out', 'Identity filter engine out', 'Zero''d filter entine out' };
ITADSPIIRFilterTest_out_all.signalType = 'energy';
ita_plot_freq( ITADSPIIRFilterTest_out_all, 'axis', [ 100 20e3 -7e3 0 ] )
\ No newline at end of file
......@@ -6,9 +6,10 @@
"b2" : 1
},
"denominator" : {
"a1" : 0.56,
"a2" : 0.78
"a1" : 1,
"a2" : 0.56,
"a3" : 0.78
},
"design_algorithm" : "",
"design_algorithm" : -858993460,
"is_ARMA" : true
}
\ No newline at end of file
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment