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

Extending tests for IIR filtering and IIR coefficient design using Burg

parent 2c691dde
......@@ -46,106 +46,98 @@ using namespace std;
const float g_fSampleRate = 44100;
void VDLIIRTest();
void Burg_Time_Test();
//absorption filter
vector<float> abs_Magnitudes = { 0.02f, 0.02f, 0.02f, 0.0233333f, 0.0266667f, 0.03f, 0.03f, 0.03f, 0.03f, 0.03f, 0.03f, 0.03f, 0.03f, 0.03f, 0.03f, 0.0333333f, 0.0366667f, 0.04f, 0.0433333f, 0.0466667f, 0.05f, 0.0566667f, 0.0633333f, 0.07f, 0.07f, 0.07f, 0.07f, 0.0733333f, 0.0766667f, 0.08f, 0.08f };
// Absorption filter
vector< float > vfAbsorptionSpectrumTO = { 0.02f, 0.02f, 0.02f, 0.0233333f, 0.0266667f, 0.03f, 0.03f, 0.03f, 0.03f, 0.03f, 0.03f, 0.03f, 0.03f, 0.03f, 0.03f, 0.0333333f, 0.0366667f, 0.04f, 0.0433333f, 0.0466667f, 0.05f, 0.0566667f, 0.0633333f, 0.07f, 0.07f, 0.07f, 0.07f, 0.0733333f, 0.0766667f, 0.08f, 0.08f };
//trumpet directivity
vector<float> trump_Magnitudes = { 0.860280990600586f, 0.860280632972717f, 0.860280632972717f, 0.860280632972717f, 0.860280632972717f, 0.860280632972717f, 0.860280632972717f, 0.860280692577362f, 0.860280692577362f, 0.863133668899536f, 0.752475023269653f, 0.674751520156860f, 0.499466955661774f, 0.738280415534973f, 0.653443872928619f, 0.507191777229309f, 0.533296763896942f, 0.503476321697235f, 0.376767426729202f, 0.353374809026718f, 0.269741356372833f, 0.207140043377876f, 0.153062343597412f, 0.112099960446358f, 0.127615734934807f, 0.0946486070752144f, 0.0785422623157501f, 0.0600289255380631f, 0.0488252453505993f, 0.0387985333800316f, 0.0315645076334477f };
vector< float > vfTrumpetDirectivitySpectrumTO = { 0.860280990600586f, 0.860280632972717f, 0.860280632972717f, 0.860280632972717f, 0.860280632972717f, 0.860280632972717f, 0.860280632972717f, 0.860280692577362f, 0.860280692577362f, 0.863133668899536f, 0.752475023269653f, 0.674751520156860f, 0.499466955661774f, 0.738280415534973f, 0.653443872928619f, 0.507191777229309f, 0.533296763896942f, 0.503476321697235f, 0.376767426729202f, 0.353374809026718f, 0.269741356372833f, 0.207140043377876f, 0.153062343597412f, 0.112099960446358f, 0.127615734934807f, 0.0946486070752144f, 0.0785422623157501f, 0.0600289255380631f, 0.0488252453505993f, 0.0387985333800316f, 0.0315645076334477f };
//diffracion filter
vector<float> diff_Magnitudes = { 0.111934553579764f, 0.106460935614618f, 0.100699704548526f, 0.0947001721104573f, 0.0890866491204974f, 0.0835569704783756f, 0.0775507540050590f, 0.0722382340567499f, 0.0670519961369095f, 0.0621838133597414f, 0.0565935658858452f, 0.0519303873398500f, 0.0473436952392266f, 0.0428843783633814f, 0.0389753239378729f, 0.0351914143864374f, 0.0315689677042525f, 0.0284535398945892f, 0.0255957249048243f, 0.0227266136854582f, 0.0203857703689526f, 0.0182702796747406f, 0.0162996829305633f, 0.0144787461518097f, 0.0129580533457382f, 0.0115033291355433f, 0.0102513560003608f, 0.00917063160436257f, 0.00820336236165088f, 0.00725137721071123f, 0.00648611579946720f };
vector< float > vfDiffractionSpectrumTO = { 0.111934553579764f, 0.106460935614618f, 0.100699704548526f, 0.0947001721104573f, 0.0890866491204974f, 0.0835569704783756f, 0.0775507540050590f, 0.0722382340567499f, 0.0670519961369095f, 0.0621838133597414f, 0.0565935658858452f, 0.0519303873398500f, 0.0473436952392266f, 0.0428843783633814f, 0.0389753239378729f, 0.0351914143864374f, 0.0315689677042525f, 0.0284535398945892f, 0.0255957249048243f, 0.0227266136854582f, 0.0203857703689526f, 0.0182702796747406f, 0.0162996829305633f, 0.0144787461518097f, 0.0129580533457382f, 0.0115033291355433f, 0.0102513560003608f, 0.00917063160436257f, 0.00820336236165088f, 0.00725137721071123f, 0.00648611579946720f };
void DesignFromSpectrum();
void VDLIIRTest();
void Burg_Time_Test();
int main( int, char** )
{
//VDLIIRTest();
DesignFromSpectrum();
VDLIIRTest();
Burg_Time_Test();
return 255;
//Load an target impulse response from file (oIR)
ITABase::CFiniteImpulseResponse oIR;
float fSampleRate;
//oIR.Load( "ITADSPIIRFilterGeneratorTest_IR_in.wav", fSampleRate );
oIR.Load( "ITADSPIIRFilterTest_out.wav", fSampleRate );
}
int filter_order = 4;
void DesignFromSpectrum()
{
//Generate an impulse response (oIR2) from frequency third octave magnitude data
ITABase::CFiniteImpulseResponse oIR2( 1024, g_fSampleRate );
CITAThirdOctaveFIRFilterGenerator oIRGenerator( oIR2.GetSampleRate(), oIR2.GetLength() );
ITADSP::CFilterCoefficients oBurgCoeffs( 4, false );
// Generate an impulse response from the given spectra
ITABase::CThirdOctaveGainMagnitudeSpectrum oMags;
oMags.SetMagnitudes( abs_Magnitudes );
//oMags.SetIdentity();
oIRGenerator.GenerateFilter( oMags, oIR2.GetData(), true );
/*
//Generate filter from magnitude response using yule-walker method
ITADSP::CIIRCoefficients oYulewalkCoeffs( 4 );
ITADSP::IIRFilterGenerator::Yulewalk( oIR, oYulewalkCoeffs );
*/
CITAIIRFilterEngine oIIRFilterEngine( filter_order ); //create an IIR filter
//ITASampleBuffer pfIn;
//pfIn.Load("WelcomeToVA.wav", fSampleRate);
ITASampleBuffer pfIn( 1024, true );
pfIn.GetData()[ 0 ] = 1.0f; //impulse
ITASampleBuffer pfOut( pfIn.GetLength() );
/*
//Generate filter using the Burg method
ITADSP::CIIRCoefficients oBurgCoeffs( filter_order, false );
ITAStopWatch sw;
sw.start(); //start timing
ITADSP::IIRFilterGenerator::Burg( oIR2, oBurgCoeffs );
//cout << timeToString( sw.stop() ) << endl << endl;
oIIRFilterEngine.SetCoefficients(oBurgCoeffs); //set filter coefficients to those calculated with Burg
oIIRFilterEngine.Process(pfIn.GetData(), pfOut.GetData(), pfIn.GetLength()); //apply the filter to an input signal
cout << timeToString(sw.stop()) << endl << endl; //stop timing
*/
ITADSP::CFilterCoefficients oYuleCoeffs;
ITADSP::IIRFilterGenerator::Yulewalk( oIR2, oYuleCoeffs );
//writeAudiofile("WelcomeToVA_filtered_burg_trumpet.wav", &pfOut, fSampleRate);
//--------------------------------------------------------Output data------------------------------------------------------------------
/*
//Display output data in console
cout << "Gain: " << oBurgCoeffs.vfNumerator[0] << endl << endl << "Denominators:" << endl;
//writeAudiofile("Generated_IR_out_absorption_minphase.wav", &oIR2, fSampleRate);
for( int i=0; i<= oBurgCoeffs.uiOrder; i++ )
cout << oBurgCoeffs.vfDenominator[i] << endl;
#ifdef WITH_JSON_SUPPORT //export generated coefficients as json file
ITADSP::ExportIIRCoefficientsToJSON( "ITADSPIIRFilterGeneratorTest_burg_coeffs.json", oBurgCoeffs );
#endif
*/
return 255;
ITABase::CFiniteImpulseResponse oIRTarget( 1024, g_fSampleRate );
CITAThirdOctaveFIRFilterGenerator oIRGenerator( oIRTarget.GetSampleRate(), oIRTarget.GetLength() );
// Absorption spectrum
oMags.SetMagnitudes( vfAbsorptionSpectrumTO );
oIRGenerator.GenerateFilter( oMags, oIRTarget.GetData(), true );
oIRTarget.Store( "ITADSPIIRFilterGeneratorTest_AbsorptionIR.wav" );
ITADSP::IIRFilterGenerator::Burg( oIRTarget, oBurgCoeffs );
#ifdef WITH_JSON_SUPPORT
ITADSP::ExportIIRCoefficientsToJSON( "ITADSPIIRFilterTest_AbsorptionCoeffs.json", oBurgCoeffs );
#endif
// Absorption spectrum + 3 dB
oMags.SetMagnitudes( vfAbsorptionSpectrumTO );
oMags.Multiply( 2 );
oIRGenerator.GenerateFilter( oMags, oIRTarget.GetData(), true );
oIRTarget.Store( "ITADSPIIRFilterGeneratorTest_AbsorptionIR_+3dB.wav" );
ITADSP::IIRFilterGenerator::Burg( oIRTarget, oBurgCoeffs );
#ifdef WITH_JSON_SUPPORT
ITADSP::ExportIIRCoefficientsToJSON( "ITADSPIIRFilterTest_AbsorptionCoeffs_+3dB.json", oBurgCoeffs );
#endif
// Absorption spectrum with higher order
oMags.SetMagnitudes( vfAbsorptionSpectrumTO );
oIRGenerator.GenerateFilter( oMags, oIRTarget.GetData(), true );
oBurgCoeffs.InitialiseOrder( 10 );
ITADSP::IIRFilterGenerator::Burg( oIRTarget, oBurgCoeffs );
#ifdef WITH_JSON_SUPPORT
ITADSP::ExportIIRCoefficientsToJSON( "ITADSPIIRFilterTest_AbsorptionCoeffs_order10.json", oBurgCoeffs );
#endif
// Absorption spectrum with huge order
oMags.SetMagnitudes( vfAbsorptionSpectrumTO );
oIRGenerator.GenerateFilter( oMags, oIRTarget.GetData(), true );
oBurgCoeffs.InitialiseOrder( 100 );
ITADSP::IIRFilterGenerator::Burg( oIRTarget, oBurgCoeffs );
#ifdef WITH_JSON_SUPPORT
ITADSP::ExportIIRCoefficientsToJSON( "ITADSPIIRFilterTest_AbsorptionCoeffs_order100.json", oBurgCoeffs );
#endif
// Trumpet directivity spectrum
oMags.SetMagnitudes( vfTrumpetDirectivitySpectrumTO );
oIRGenerator.GenerateFilter( oMags, oIRTarget.GetData(), true );
oIRTarget.Store( "ITADSPIIRFilterGeneratorTest_TrumpetDirectivityIR.wav" );
oBurgCoeffs.InitialiseOrder( 4 );
ITADSP::IIRFilterGenerator::Burg( oIRTarget, oBurgCoeffs );
#ifdef WITH_JSON_SUPPORT
ITADSP::ExportIIRCoefficientsToJSON( "ITADSPIIRFilterTest_TrumpetDirectivityCoeffs.json", oBurgCoeffs );
#endif
// Diffraction spectrum
oMags.SetMagnitudes( vfDiffractionSpectrumTO );
oIRGenerator.GenerateFilter( oMags, oIRTarget.GetData(), true );
oIRTarget.Store( "ITADSPIIRFilterGeneratorTest_DiffractionIR.wav" );
oBurgCoeffs.InitialiseOrder( 4 );
ITADSP::IIRFilterGenerator::Burg( oIRTarget, oBurgCoeffs );
#ifdef WITH_JSON_SUPPORT
ITADSP::ExportIIRCoefficientsToJSON( "ITADSPIIRFilterTest_DiffractionCoeffs.json", oBurgCoeffs );
#endif
}
void Burg_Time_Test() {
int filter_order = 4;
......@@ -155,7 +147,7 @@ void Burg_Time_Test() {
CITAThirdOctaveFIRFilterGenerator oIRGenerator( oIR.GetSampleRate(), oIR.GetLength() );
ITABase::CThirdOctaveGainMagnitudeSpectrum oMags;
oMags.SetMagnitudes( abs_Magnitudes );
oMags.SetMagnitudes( vfAbsorptionSpectrumTO );
oIRGenerator.GenerateFilter( oMags, oIR.GetData(), true );
......@@ -258,13 +250,13 @@ void VDLIIRTest()
int filter_length = 1024;
ITABase::CThirdOctaveGainMagnitudeSpectrum oMags1; //set magnitude responses
oMags1.SetMagnitudes( abs_Magnitudes );
oMags1.SetMagnitudes( vfAbsorptionSpectrumTO );
ITABase::CThirdOctaveGainMagnitudeSpectrum oMags2;
oMags2.SetMagnitudes( trump_Magnitudes );
oMags2.SetMagnitudes( vfTrumpetDirectivitySpectrumTO );
ITABase::CThirdOctaveGainMagnitudeSpectrum oMags3;
oMags3.SetMagnitudes( diff_Magnitudes );
oMags3.SetMagnitudes( vfDiffractionSpectrumTO );
ITABase::CThirdOctaveGainMagnitudeSpectrum oMags4;
oMags4.SetIdentity();
......
%% Absorption
absorption_ir = ita_read( 'ITADSPIIRFilterGeneratorTest_AbsorptionIR.wav' );
absorption_ir.channelNames = { 'C++ IR from spectrum generator' };
absorption_coeffs = jsondecode( fileread( 'ITADSPIIRFilterTest_AbsorptionCoeffs.json' ) );
%absorption_mags = [ 0.02, 0.02, 0.02, 0.0233333, 0.0266667, 0.03, 0.03, 0.03, 0.03, 0.03, 0.03, 0.03, 0.03, 0.03, 0.03, 0.0333333, 0.0366667, 0.04, 0.0433333, 0.0466667, 0.05, 0.0566667, 0.0633333, 0.07, 0.07, 0.07, 0.07, 0.0733333, 0.0766667, 0.08, 0.08 ];
absorption_iir = dsp.IIRFilter;
absorption_iir.Numerator = [ absorption_coeffs.numerator.b0 0 0 0 0 ];
absorption_iir.Denominator = [ absorption_coeffs.denominator.a1 ...
absorption_coeffs.denominator.a2 ...
absorption_coeffs.denominator.a3 ...
absorption_coeffs.denominator.a4 ...
absorption_coeffs.denominator.a5 ];
absorption_ir_filtering = absorption_ir;
absorption_ir_filtering.timeData = absorption_iir( [ 1; zeros( absorption_ir_filtering.nSamples - 1, 1 ) ] );
absorption_ir_filtering.channelNames = { 'Matlab IIR response order 4' };
absorption_irs = ita_merge( absorption_ir, absorption_ir_filtering );
absorption_irs.pf
% Absorption + 3 dB
absorption_ir_3db = ita_read( 'ITADSPIIRFilterGeneratorTest_AbsorptionIR_+3dB.wav' );
absorption_ir_3db.channelNames = { 'C++ IR from spectrum generator +3dB' };
absorption_coeffs_3db = jsondecode( fileread( 'ITADSPIIRFilterTest_AbsorptionCoeffs_+3dB.json' ) );
%absorption_mags_3dB = 2 .* [ 0.02, 0.02, 0.02, 0.0233333, 0.0266667, 0.03, 0.03, 0.03, 0.03, 0.03, 0.03, 0.03, 0.03, 0.03, 0.03, 0.0333333, 0.0366667, 0.04, 0.0433333, 0.0466667, 0.05, 0.0566667, 0.0633333, 0.07, 0.07, 0.07, 0.07, 0.0733333, 0.0766667, 0.08, 0.08 ];
absorption_iir = dsp.IIRFilter;
absorption_iir.Numerator = [ absorption_coeffs_3db.numerator.b0 0 0 0 0 ];
absorption_iir.Denominator = [ absorption_coeffs_3db.denominator.a1 ...
absorption_coeffs_3db.denominator.a2 ...
absorption_coeffs_3db.denominator.a3 ...
absorption_coeffs_3db.denominator.a4 ...
absorption_coeffs_3db.denominator.a5 ];
absorption_ir_filtering_3db = absorption_ir_3db;
absorption_ir_filtering_3db.timeData = absorption_iir( [ 1; zeros( absorption_ir_filtering_3db.nSamples - 1, 1 ) ] );
absorption_ir_filtering_3db.channelNames = { 'Matlab IIR response order 4 +3dB' };
absorption_irs_3db = ita_merge( absorption_irs, absorption_ir_3db, absorption_ir_filtering_3db );
absorption_irs_3db.pf
%% Absorption Order 10
absorption_coeffs_o10 = jsondecode( fileread( 'ITADSPIIRFilterTest_AbsorptionCoeffs_order10.json' ) );
%absorption_mags = [ 0.02, 0.02, 0.02, 0.0233333, 0.0266667, 0.03, 0.03, 0.03, 0.03, 0.03, 0.03, 0.03, 0.03, 0.03, 0.03, 0.0333333, 0.0366667, 0.04, 0.0433333, 0.0466667, 0.05, 0.0566667, 0.0633333, 0.07, 0.07, 0.07, 0.07, 0.0733333, 0.0766667, 0.08, 0.08 ];
absorption_iir = dsp.IIRFilter;
absorption_iir.Numerator = [ absorption_coeffs_o10.numerator.b0 0 0 0 0 0 0 0 0 0 ];
absorption_iir.Denominator = [ absorption_coeffs_o10.denominator.a1 ...
absorption_coeffs_o10.denominator.a2 ...
absorption_coeffs_o10.denominator.a3 ...
absorption_coeffs_o10.denominator.a4 ...
absorption_coeffs_o10.denominator.a5 ...
absorption_coeffs_o10.denominator.a6 ...
absorption_coeffs_o10.denominator.a7 ...
absorption_coeffs_o10.denominator.a8 ...
absorption_coeffs_o10.denominator.a9 ...
absorption_coeffs_o10.denominator.a10 ...
absorption_coeffs_o10.denominator.a11 ];
absorption_ir_filtering_order10 = absorption_ir;
absorption_ir_filtering_order10.timeData = absorption_iir( [ 1; zeros( absorption_ir_filtering_order10.nSamples - 1, 1 ) ] );
absorption_ir_filtering_order10.channelNames = { 'Matlab IIR response order 10' };
absorption_irs = ita_merge( absorption_ir, absorption_ir_filtering_order10 );
absorption_irs.pf
%% Absorption Order 100
absorption_coeffs_o100 = jsondecode( fileread( 'ITADSPIIRFilterTest_AbsorptionCoeffs_order100.json' ) );
%absorption_mags = [ 0.02, 0.02, 0.02, 0.0233333, 0.0266667, 0.03, 0.03, 0.03, 0.03, 0.03, 0.03, 0.03, 0.03, 0.03, 0.03, 0.0333333, 0.0366667, 0.04, 0.0433333, 0.0466667, 0.05, 0.0566667, 0.0633333, 0.07, 0.07, 0.07, 0.07, 0.0733333, 0.0766667, 0.08, 0.08 ];
absorption_iir = dsp.IIRFilter;
absorption_iir.Numerator = [ absorption_coeffs_o100.numerator.b0 0 0 0 0 0 0 0 0 0 ];
absorption_iir.Denominator = zeros( 1, 100 );
for i = 1:101
absorption_iir.Denominator( i ) = absorption_coeffs_o100.denominator.( [ 'a' num2str( i ) ] );
end
absorption_ir_filtering_order100 = absorption_ir;
absorption_ir_filtering_order100.timeData = absorption_iir( [ 1; zeros( absorption_ir_filtering_order100.nSamples - 1, 1 ) ] );
absorption_ir_filtering_order100.channelNames = { 'Matlab IIR response order 100' };
absorption_irs = ita_merge( absorption_ir, absorption_ir_filtering_order100 );
absorption_irs.pf
%% Trumpet directivity
trumpet_directivity_ir = ita_read( 'ITADSPIIRFilterGeneratorTest_TrumpetDirectivityIR.wav' );
trumpet_directivity_ir.channelNames = { 'C++ trumpet directivity IR from spectrum generator' };
trumpet_directivity_coeffs = jsondecode( fileread( 'ITADSPIIRFilterTest_TrumpetDirectivityCoeffs.json' ) );
trumpet_directivity_iir = dsp.IIRFilter;
trumpet_directivity_iir.Numerator = [ trumpet_directivity_coeffs.numerator.b0 ];
trumpet_directivity_iir.Denominator = zeros( 1, 5 );
for i = 1:5
trumpet_directivity_iir.Denominator( i ) = trumpet_directivity_coeffs.denominator.( [ 'a' num2str( i ) ] );
end
trumpet_directivity_ir_filtering = trumpet_directivity_ir;
trumpet_directivity_ir_filtering.timeData = trumpet_directivity_iir( [ 1; zeros( trumpet_directivity_ir_filtering.nSamples - 1, 1 ) ] );
trumpet_directivity_ir_filtering.channelNames = { 'Matlab IIR response trumpet_directivity spectrum' };
trumpet_directivity_irs = ita_merge( trumpet_directivity_ir, trumpet_directivity_ir_filtering );
trumpet_directivity_irs.pf
trumpet_spectrum = [ 0.860280990600586 0.860280632972717 0.860280632972717 0.860280632972717 0.860280632972717 0.860280632972717 0.860280632972717 0.860280692577362 0.860280692577362 0.863133668899536 0.752475023269653 0.674751520156860 0.499466955661774 0.738280415534973 0.653443872928619 0.507191777229309 0.533296763896942 0.503476321697235 0.376767426729202 0.353374809026718 0.269741356372833 0.207140043377876 0.153062343597412 0.112099960446358 0.127615734934807 0.0946486070752144 0.0785422623157501 0.0600289255380631 0.0488252453505993 0.0387985333800316 0.0315645076334477 ];
trumpet_dir_r = itaResult();
trumpet_dir_r.freqVector = ita_ANSI_center_frequencies;
trumpet_dir_r.freqData = trumpet_spectrum';
%% Diffraction
diffraction_ir = ita_read( 'ITADSPIIRFilterGeneratorTest_DiffractionIR.wav' );
diffraction_ir.channelNames = { 'C++ diffraction IR from spectrum generator' };
diffraction_coeffs = jsondecode( fileread( 'ITADSPIIRFilterTest_DiffractionCoeffs.json' ) );
diffraction_iir = dsp.IIRFilter;
diffraction_iir.Numerator = [ diffraction_coeffs.numerator.b0 ];
diffraction_iir.Denominator = zeros( 1, 5 );
for i = 1:5
diffraction_iir.Denominator( i ) = diffraction_coeffs.denominator.( [ 'a' num2str( i ) ] );
end
diffraction_ir_filtering = diffraction_ir;
diffraction_ir_filtering.timeData = diffraction_iir( [ 1; zeros( diffraction_ir_filtering.nSamples - 1, 1 ) ] );
diffraction_ir_filtering.channelNames = { 'Matlab IIR response diffraction spectrum' };
diffraction_irs = ita_merge( diffraction_ir, diffraction_ir_filtering );
diffraction_irs.pf
diffraction_spectrum = [ 0.111934553579764 0.106460935614618 0.100699704548526 0.0947001721104573 0.0890866491204974 0.0835569704783756 0.0775507540050590 0.0722382340567499 0.0670519961369095 0.0621838133597414 0.0565935658858452 0.0519303873398500 0.0473436952392266 0.0428843783633814 0.0389753239378729 0.0351914143864374 0.0315689677042525 0.0284535398945892 0.0255957249048243 0.0227266136854582 0.0203857703689526 0.0182702796747406 0.0162996829305633 0.0144787461518097 0.0129580533457382 0.0115033291355433 0.0102513560003608 0.00917063160436257 0.00820336236165088 0.00725137721071123 0.00648611579946720 ];
diffraction_r = itaResult();
diffraction_r.freqVector = ita_ANSI_center_frequencies;
diffraction_r.freqData = diffraction_spectrum';
......@@ -44,33 +44,34 @@ int main( int, char** )
float* pfOut = sbOutput.GetData();
ITADSP::CFilterCoefficients oCoeffs;
oCoeffs.uiOrder = 2;
oCoeffs.vfNumerator = { 1, 2, 1 };
oCoeffs.vfDenominator = { 1, 0.56f, 0.78f };
oCoeffs.bIsARMA = true;
ITADSP::CFilterCoefficients oCoeffs1;
oCoeffs1.uiOrder = 2;
oCoeffs1.vfNumerator = { 1, 2, 1 };
oCoeffs1.vfDenominator = { 1, 0.56f, 0.78f };
oCoeffs1.bIsARMA = true;
#ifdef WITH_JSON_SUPPORT
ITADSP::ExportIIRCoefficientsToJSON( "ITADSPIIRFilterTest_coeffs.json", oCoeffs );
ITADSP::ExportIIRCoefficientsToJSON( "ITADSPIIRFilterTest_coeffs1.json", oCoeffs1 );
#endif
CITAIIRFilterEngine oIIRFilterEngine( oCoeffs.uiOrder );
oIIRFilterEngine.SetCoefficients( oCoeffs );
CITAIIRFilterEngine oIIRFilterEngine( oCoeffs1.uiOrder );
oIIRFilterEngine.SetCoefficients( oCoeffs1 );
oIIRFilterEngine.Process( pfIn, pfOut, iSamples );
writeAudiofile( "ITADSPIIRFilterTest_out.wav", &sbOutput, g_dSampleRate );
writeAudiofile( "ITADSPIIRFilterTest_coeffs1_out.wav", &sbOutput, g_dSampleRate );
CITAIIRFilterEngine oIIRFilterEngine_Uninitialized( oCoeffs.uiOrder );
CITAIIRFilterEngine oIIRFilterEngine_Uninitialized( oCoeffs1.uiOrder );
oIIRFilterEngine_Uninitialized.Process( pfIn, pfOut, iSamples );
writeAudiofile( "ITADSPIIRFilterTest_out_uninitialized.wav", &sbOutput, g_dSampleRate );
CITAIIRFilterEngine oIIRFilterEngine_Identity( oCoeffs.uiOrder );
CITAIIRFilterEngine oIIRFilterEngine_Identity( oCoeffs1.uiOrder );
oIIRFilterEngine_Identity.SetCoefficientsToIdentity();
oIIRFilterEngine_Identity.Process( pfIn, pfOut, iSamples );
writeAudiofile( "ITADSPIIRFilterTest_out_identity.wav", &sbOutput, g_dSampleRate );
CITAIIRFilterEngine oIIRFilterEngine_Zero( oCoeffs.uiOrder );
CITAIIRFilterEngine oIIRFilterEngine_Zero( oCoeffs1.uiOrder );
oIIRFilterEngine_Zero.SetCoefficientsToZero();
oIIRFilterEngine_Zero.Process( pfIn, pfOut, iSamples );
writeAudiofile( "ITADSPIIRFilterTest_out_zero.wav", &sbOutput, g_dSampleRate );
......
%Import the output of the c++ file "ITADSPFilterTest", where an impulse
%response of a filter with coefficients b = [1 2 1], a = [1 0.56 0.78] is generated.
%Plot the generated impulse response
%% ITADSPIIRFilterTest
ITADSPIIRFilterTest_out = ita_read( 'ITADSPIIRFilterTest_out.wav' );
%ITADSPIIRFilterTest_out = ITADSPIIRFilterTest_out .* 0.004603998475022463843231435021152719855;
%ITADSPIIRFilterTest_out.pt
% Matlab vs. C++
ITADSPIIRFilterTest_coeffs = jsondecode( fileread( 'ITADSPIIRFilterTest_coeffs.json' ) )
impls = itaAudio();
impls.timeData = [ 1; zeros( 127, 1 ) ];
ir = itaAudio();
ir.timeData = zeros( 128, 1 );
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' );
iir1 = dsp.IIRFilter;
iir1.Numerator = [ 1 2 1 ];
iir1.Denominator = [ 1 0.56 0.78 ];
ir1 = ir;
ir1.timeData = iir1( impls.timeData );
ir1.channelNames = { 'Matlab dsp.IIRFilter hard-coded' };
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
ITADSPIIRFilterTest_coeffs1 = jsondecode( fileread( 'ITADSPIIRFilterTest_coeffs1.json' ) );
iir2 = dsp.IIRFilter;
iir2.Numerator = [ ITADSPIIRFilterTest_coeffs1.numerator.b0 ...
ITADSPIIRFilterTest_coeffs1.numerator.b1 ...
ITADSPIIRFilterTest_coeffs1.numerator.b2 ];
iir2.Denominator = [ ITADSPIIRFilterTest_coeffs1.denominator.a1 ...
ITADSPIIRFilterTest_coeffs1.denominator.a2 ...
ITADSPIIRFilterTest_coeffs1.denominator.a3 ];
ir2 = ir;
ir2.timeData = iir2( impls.timeData );
ir2.channelNames = { 'Matlab dsp.IIRFilter JSON imported coeffs' };
ir3 = ita_read( 'ITADSPIIRFilterTest_out.wav' );
ir3 = ita_time_crop( ir3, [ 1 ir1.nSamples ], 'samples' );
ir3.channelNames = { 'C++ implementation' };
irs = ita_merge( ir1, ir2, ir3 );
irs.pt
%% ITADSPIIRFilterTest
% Different init values
ir_uninitialized = ita_read( 'ITADSPIIRFilterTest_out_uninitialized.wav' );
ir_identity = ita_read( 'ITADSPIIRFilterTest_out_identity.wav' );
ir_zero = ita_read( 'ITADSPIIRFilterTest_out_zero.wav' );
irs = ita_merge( ir_uninitialized, ir_identity, ir_zero );
irs.channelNames = { 'Uninitialized filter engine out', 'Identity filter engine out', 'Zero''d filter entine out' };
irs.signalType = 'energy';
ita_plot_freq( irs, 'axis', [ 100 20e3 -7e3 0 ] )
{
"order" : 2,
"numerator" : {
"b0" : 1,
"b1" : 2,
"b2" : 1
},
"denominator" : {
"a1" : 1,
"a2" : 0.56,
"a3" : 0.78
},
"design_algorithm" : 0,
"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