......@@ -3,7 +3,7 @@
*
* ITA core libs
* (c) Copyright Institute of Technical Acoustics (ITA)
* RWTH Aachen University, Germany, 2015-2019
* RWTH Aachen University, Germany, 2015-2020
*
* ----------------------------------------------------------------
* ____ __________ _______
......
......@@ -3,7 +3,7 @@
*
* ITA core libs
* (c) Copyright Institute of Technical Acoustics (ITA)
* RWTH Aachen University, Germany, 2015-2019
* RWTH Aachen University, Germany, 2015-2020
*
* ----------------------------------------------------------------
* ____ __________ _______
......@@ -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 );
......
%% ITADSPIIRFilterTest
% Matlab vs. C++
impls = itaAudio();
impls.timeData = [ 1; zeros( 127, 1 ) ];
ir = itaAudio();
ir.timeData = zeros( 128, 1 );
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_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" : 4,
"numerator" : {
"b0" : 0.005268
},
"denominator" : {
"a1" : 1,
"a2" : 0.413353,
"a3" : 0.132606,
"a4" : 0.061426,
"a5" : 0.217934
},
"design_algorithm" : 1,
"is_ARMA" : false
}
\ No newline at end of file
{
"order" : 4,
"numerator" : {
"b0" : 0.021073
},
"denominator" : {
"a1" : 1,
"a2" : 0.413353,
"a3" : 0.132606,
"a4" : 0.061426,
"a5" : 0.217934
},
"design_algorithm" : 1,
"is_ARMA" : false
}
\ No newline at end of file
{
"order" : 10,
"numerator" : {
"b0" : 0.005036
},
"denominator" : {
"a1" : 1,
"a2" : 0.361548,
"a3" : 0.206807,
"a4" : 0.052984,
"a5" : 0.262672,
"a6" : -0.000109,
"a7" : 0.267345,
"a8" : 0.026036,
"a9" : 0.130557,
"a10" : 0.01508,
"a11" : 0.118088
},
"design_algorithm" : 1,
"is_ARMA" : false
}
\ No newline at end of file
{
"order" : 100,
"numerator" : {
"b0" : 0.004899
},
"denominator" : {
"a1" : 1,
"a2" : 0.303199,
"a3" : 0.247608,
"a4" : -0.001017,
"a5" : 0.317378,
"a6" : -0.076738,
"a7" : 0.354835,
"a8" : -0.077673,
"a9" : 0.241247,
"a10" : -0.096285,
"a11" : 0.218598,
"a12" : -0.139888,
"a13" : 0.190158,
"a14" : -0.143337,
"a15" : 0.158238,
"a16" : -0.131935,
"a17" : 0.146925,
"a18" : -0.122817,
"a19" : 0.132795,
"a20" : -0.114794,
"a21" : 0.115507,
"a22" : -0.105374,
"a23" : 0.102542,
"a24" : -0.093108,
"a25" : 0.093513,
"a26" : -0.080674,
"a27" : 0.08538,
"a28" : -0.069873,
"a29" : 0.076388,
"a30" : -0.061813,
"a31" : 0.06682,
"a32" : -0.055458,
"a33" : 0.057608,
"a34" : -0.050189,
"a35" : 0.049353,
"a36" : -0.04556,
"a37" : 0.04196,
"a38" : -0.041107,
"a39" : 0.035705,
"a40" : -0.036843,
"a41" : 0.030576,
"a42" : -0.032727,
"a43" : 0.026368,
"a44" : -0.028834,
"a45" : 0.022816,
"a46" : -0.025337,
"a47" : 0.019571,
"a48" : -0.022467,
"a49" : 0.016606,
"a50" : -0.02011,
"a51" : 0.013879,
"a52" : -0.018136,
"a53" : 0.011373,
"a54" : -0.01654,
"a55" : 0.009068,
"a56" : -0.015251,
"a57" : 0.006999,
"a58" : -0.014153,
"a59" : 0.005218,
"a60" : -0.013117,
"a61" : 0.003709,
"a62" : -0.01217,
"a63" : 0.002423,
"a64" : -0.01135,
"a65" : 0.001293,
"a66" : -0.010617,
"a67" : 0.00033,
"a68" : -0.009941,
"a69" : -0.000482,
"a70" : -0.00932,
"a71" : -0.001161,
"a72" : -0.008772,
"a73" : -0.001755,
"a74" : -0.0083,
"a75" : -0.002303,
"a76" : -0.007904,
"a77" : -0.002784,
"a78" : -0.00755,
"a79" : -0.00319,
"a80" : -0.007211,
"a81" : -0.003518,
"a82" : -0.006875,
"a83" : -0.003776,
"a84" : -0.006531,
"a85" : -0.003956,
"a86" : -0.006185,
"a87" : -0.004068,
"a88" : -0.00583,
"a89" : -0.004132,
"a90" : -0.005438,
"a91" : -0.004095,
"a92" : -0.004998,
"a93" : -0.003893,
"a94" : -0.004456,
"a95" : -0.003586,
"a96" : -0.003688,
"a97" : -0.003098,
"a98" : -0.003022,
"a99" : -0.002526,
"a100" : -0.002412,
"a101" : -0.001508
},
"design_algorithm" : 1,
"is_ARMA" : false
}
\ No newline at end of file
{
"order" : 4,
"numerator" : {
"b0" : 0.000087
},
"denominator" : {
"a1" : 1,
"a2" : -1.189105,
"a3" : -0.043069,
"a4" : 0.326351,
"a5" : -0.079158
},
"design_algorithm" : 1,
"is_ARMA" : false
}
\ No newline at end of file
{
"order" : 4,
"numerator" : {
"b0" : 0.009467
},
"denominator" : {
"a1" : 1,
"a2" : -1.222275,
"a3" : 0.082224,
"a4" : 0.06884,
"a5" : 0.079527
},
"design_algorithm" : 1,
"is_ARMA" : false
}
\ No newline at end of file
cmake_minimum_required( VERSION 2.8 )
project( ITADSPGeneratorsTest )
list( APPEND CMAKE_MODULE_PATH "$ENV{VISTA_CMAKE_COMMON}" )
include( VistaCommon )
vista_use_package( ITABase REQUIRED FIND_DEPENDENCIES )
vista_use_package( ITADSP REQUIRED FIND_DEPENDENCIES )
vista_use_package( ITADataSources REQUIRED FIND_DEPENDENCIES )
if( ITA_CORE_LIBS_BUILD_STATIC )
add_definitions( -DITA_BASE_STATIC -DITA_DSP_STATIC -DITA_DATA_SOURCES_STATIC -DITA_CONVOLUTION_STATIC )
endif( )
if( ITA_VISTA_BUILD_STATIC )
add_definitions( -DVISTATOOLS_STATIC -DVISTABASE_STATIC -DVISTAMATH_STATIC -DVISTAASPECTS_STATIC -DVISTAINTERPROCCOMM_STATIC )
endif( )
add_executable( ITADSPIIRFilterGeneratorTest ITADSPIIRFilterGeneratorTest.cpp )
target_link_libraries( ITADSPIIRFilterGeneratorTest ${VISTA_USE_PACKAGE_LIBRARIES} )
vista_configure_app( ITADSPIIRFilterGeneratorTest )
vista_install( ITADSPIIRFilterGeneratorTest )
vista_create_default_info_file( ITADSPIIRFilterGeneratorTest )
set_property( TARGET ITADSPIIRFilterGeneratorTest PROPERTY FOLDER "ITACoreLibs/Tests/ITADSP/generators" )
add_executable( ITADSPThirdOctaveFilterGeneratorFIRTest ITADSPThirdOctaveFilterGeneratorFIRTest.cpp )
target_link_libraries( ITADSPThirdOctaveFilterGeneratorFIRTest ${VISTA_USE_PACKAGE_LIBRARIES} )
vista_configure_app( ITADSPThirdOctaveFilterGeneratorFIRTest )
vista_install( ITADSPThirdOctaveFilterGeneratorFIRTest )
vista_create_default_info_file( ITADSPThirdOctaveFilterGeneratorFIRTest )
set_property( TARGET ITADSPThirdOctaveFilterGeneratorFIRTest PROPERTY FOLDER "ITACoreLibs/Tests/ITADSP/generators" )
......@@ -3,7 +3,7 @@
*
* ITA core libs
* (c) Copyright Institute of Technical Acoustics (ITA)
* RWTH Aachen University, Germany, 2015-2019
* RWTH Aachen University, Germany, 2015-2020
*
* ----------------------------------------------------------------
* ____ __________ _______
......@@ -20,6 +20,7 @@
#include <ITAStreamFunctionGenerator.h>
#include <ITAFileDataSource.h>
#include <ITAStreamInfo.h>
#include <ITABase/UtilsJSON.h>
#include <math.h>
#include <vector>
......@@ -37,115 +38,102 @@
#include <ITASampleFrame.h>
#include <ITAThirdOctaveFIRFilterGenerator.h>
#include <ITAThirdOctaveMagnitudeSpectrum.h>
#include <iostream>
#include <ccomplex>
#include <memory>
using namespace std;
using namespace ITABase;
const float g_fSampleRate = 44100;
const int g_iFIRGenLength = int( 4 * ceil( g_fSampleRate / CThirdOctaveMagnitudeSpectrum::GetCenterFrequencies()[ 0 ] ) );
void VDLIIRTest();
void Burg_Time_Test();
// 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 };
//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 };
// Trumpet directivity
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 };
//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 };
//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 };
// Diffracion filter
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** )
{
DesignFromSpectrum();
//VDLIIRTest();
Burg_Time_Test();
//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 oBurgCoeffsOrder4( 4, false );
ITADSP::CFilterCoefficients oBurgCoeffsOrder10( 10, 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( g_iFIRGenLength, g_fSampleRate );
CITAThirdOctaveFIRFilterGenerator oIRGenerator( oIRTarget.GetSampleRate(), oIRTarget.GetLength() );
// Absorption spectrum
oMags.SetMagnitudes( vfAbsorptionSpectrumTO );
for( int i = 0; i < oMags.GetNumBands(); i++ )
oMags.SetValue( i, sqrt( 1.0f - oMags.GetValues()[ i ] ) );
#ifdef WITH_JSON_SUPPORT
ITABase::Utils::JSON::Export( &oMags, "ReflectionTOSpectrum.json" );
#endif
oIRGenerator.GenerateFilter( oMags, oIRTarget.GetData(), true );
oIRTarget.Store( "ReflectionIR_min_phase.wav" );
ITADSP::IIRFilterGenerator::Burg( oIRTarget, oBurgCoeffsOrder4 );
ITADSP::IIRFilterGenerator::Burg( oIRTarget, oBurgCoeffsOrder10 );
#ifdef WITH_JSON_SUPPORT
ITADSP::ExportIIRCoefficientsToJSON( "ReflectionIIRCoeffsOrder4.json", oBurgCoeffsOrder4 );
ITADSP::ExportIIRCoefficientsToJSON( "ReflectionIIRCoeffsOrder4.json", oBurgCoeffsOrder10 );
#endif
// Directivity spectrum
oMags.SetMagnitudes( vfTrumpetDirectivitySpectrumTO );
#ifdef WITH_JSON_SUPPORT
ITABase::Utils::JSON::Export( &oMags, "DirectivityTOSpectrum.json" );
#endif
oIRGenerator.GenerateFilter( oMags, oIRTarget.GetData(), true );
oIRTarget.Store( "DirectivityIR_min_phase.wav" );
oBurgCoeffsOrder4.InitialiseOrder( 4 );
oBurgCoeffsOrder10.InitialiseOrder( 10 );
ITADSP::IIRFilterGenerator::Burg( oIRTarget, oBurgCoeffsOrder4 );
ITADSP::IIRFilterGenerator::Burg( oIRTarget, oBurgCoeffsOrder10 );
#ifdef WITH_JSON_SUPPORT
ITADSP::ExportIIRCoefficientsToJSON( "DirectivityIIRCoeffsOrder4.json", oBurgCoeffsOrder4 );
ITADSP::ExportIIRCoefficientsToJSON( "DirectivityIIRCoeffsOrder10.json", oBurgCoeffsOrder10 );
#endif
// Diffraction spectrum
oMags.SetMagnitudes( vfDiffractionSpectrumTO );
#ifdef WITH_JSON_SUPPORT
ITABase::Utils::JSON::Export( &oMags, "DiffractionTOSpectrum.json" );
#endif
oIRGenerator.GenerateFilter( oMags, oIRTarget.GetData(), true );
oIRTarget.Store( "DiffractionIR_min_phase.wav" );
oBurgCoeffsOrder4.InitialiseOrder( 4 );
oBurgCoeffsOrder10.InitialiseOrder( 10 );
ITADSP::IIRFilterGenerator::Burg( oIRTarget, oBurgCoeffsOrder4 );
ITADSP::IIRFilterGenerator::Burg( oIRTarget, oBurgCoeffsOrder10 );
#ifdef WITH_JSON_SUPPORT
ITADSP::ExportIIRCoefficientsToJSON( "DiffractionIIRCoeffsOrder4.json", oBurgCoeffsOrder4 );
ITADSP::ExportIIRCoefficientsToJSON( "DiffractionIIRCoeffsOrder10.json", oBurgCoeffsOrder10 );
#endif
}
void Burg_Time_Test() {
int filter_order = 4;
......@@ -155,7 +143,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 );
......@@ -194,12 +182,6 @@ void Burg_Time_Test() {
}
}
void VDLIIRTest()
{
//input parameters
......@@ -258,13 +240,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();
......
%% Reflection (from absorption data)
reflection_ir = ita_read( 'ReflectionIR_min_phase.wav' );
reflection_ir.channelNames = { 'C++ IR from spectrum generator' };
excitation_ir = ita_generate_impulse( 'fftDegree', reflection_ir.fftDegree );
reflection_coeffs4 = jsondecode( fileread( 'ReflectionIIRCoeffsOrder4.json' ) );
reflection_iir_o4 = dsp.IIRFilter;
reflection_iir_o4.Numerator = [ reflection_coeffs4.numerator.b0 0 0 0 0 ];
reflection_iir_o4.Denominator = [ reflection_coeffs4.denominator.a1 ...
reflection_coeffs4.denominator.a2 ...
reflection_coeffs4.denominator.a3 ...
reflection_coeffs4.denominator.a4 ...
reflection_coeffs4.denominator.a5 ];
reflection_ir_filtering = reflection_ir;
reflection_ir_filtering.timeData = reflection_iir_o4( excitation_ir.timeData );
reflection_ir_filtering.channelNames = { 'Matlab IIR response order 4' };
refl_irs = ita_merge( reflection_ir, reflection_ir_filtering );
refl_irs.signalType = 'energy';
refl_rs = ita_spk2frequencybands( refl_irs );
R_r = ita_result_from_json( 'ReflectionTOSpectrum.json' );
R_r.freqVector = refl_rs.freqVector;
R_r.channelNames = { 'Original third-octave band spectrum' };
refl_rs = ita_merge( R_r, refl_rs );
refl_rs.pf
title 'Reflection filtering (third octave energetic band spectrum)'
%% Diffraction
diffraction_ir = ita_read( 'DiffractionIR_min_phase.wav' );
diffraction_ir.channelNames = { 'Diffraction IR from C++ generator' };
diffraction_coeffs = jsondecode( fileread( 'DiffractionIIRCoeffs.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( excitation_ir.timeData );
diffraction_ir_filtering.channelNames = { 'Matlab IIR response (order 4)' };
diffraction_irs = ita_merge( diffraction_ir, diffraction_ir_filtering );
diffraction_irs.signalType = 'energy';
diffr_rs = ita_spk2frequencybands( diffraction_irs );
diffr_target_r = ita_result_from_json( 'DiffractionTOSpectrum.json' );
diffr_target_r.freqVector = diffr_rs.freqVector;
diffr_target_r.freqData = diffr_target_r.freqData;
diffr_target_r.channelNames = { 'Original third-octave band spectrum' };
dir_rs = ita_merge( diffr_target_r, diffr_rs );
dir_rs.pf
title 'Diffraction filtering (third octave energetic band spectrum)'
%% Directivity
dir_ir = ita_read( 'DirectivityIR_min_phase.wav' );
dir_ir.channelNames = { 'Directivity IR from C++ generator' };
directivity_coeffs4 = jsondecode( fileread( 'DirectivityIIRCoeffsOrder4.json' ) );
directivity_iir4 = dsp.IIRFilter;
directivity_iir4.Numerator = [ directivity_coeffs4.numerator.b0 ];
directivity_iir4.Denominator = zeros( 1, 5 );
for i = 1:5
directivity_iir4.Denominator( i ) = directivity_coeffs4.denominator.( [ 'a' num2str( i ) ] );
end
directivity_ir_filtering_4 = dir_ir;
directivity_ir_filtering_4.timeData = directivity_iir4( excitation_ir.timeData );
directivity_ir_filtering_4.channelNames = { 'Matlab IIR response (order 4)' };
directivity_coeffs10 = jsondecode( fileread( 'DirectivityIIRCoeffsOrder10.json' ) );
directivity_iir10 = dsp.IIRFilter;
directivity_iir10.Numerator = [ directivity_coeffs10.numerator.b0 ];
directivity_iir10.Denominator = zeros( 1, 11 );
for i = 1:11
directivity_iir10.Denominator( i ) = directivity_coeffs10.denominator.( [ 'a' num2str( i ) ] );
end
directivity_ir_filtering_10 = dir_ir;
directivity_ir_filtering_10.timeData = directivity_iir10( excitation_ir.timeData );
directivity_ir_filtering_10.channelNames = { 'Matlab IIR response (order 10)' };
directivity_irs = ita_merge( dir_ir, directivity_ir_filtering_4, directivity_ir_filtering_10 );
directivity_irs.signalType = 'energy';
dir_rs = ita_spk2frequencybands( directivity_irs );
dir_target_r = ita_result_from_json( 'DirectivityTOSpectrum.json' );
dir_target_r.freqVector = dir_rs.freqVector;
dir_target_r.freqData = dir_target_r.freqData;
dir_target_r.channelNames = { 'Original third-octave band spectrum' };
dir_rs = ita_merge( dir_target_r, dir_rs );
dir_rs.pf
title 'Directivity filtering (third octave energetic band spectrum)'
......@@ -6,6 +6,7 @@
#include <ITAStopWatch.h>
#include <ITASampleBuffer.h>
#include <ITASampleFrame.h>
#include <ITABase/UtilsJSON.h>
#include <iostream>
......@@ -13,18 +14,20 @@ using namespace ITABase;
using namespace std;
const double g_dSampleRate = 44100;
//const int g_iFilterLength = int( ceil( g_dSampleRate / CThirdOctaveMagnitudeSpectrum::GetCenterFrequencies()[ 0 ] ) );
const int g_iFilterLength = int( 10 * ceil( g_dSampleRate / CThirdOctaveMagnitudeSpectrum::GetCenterFrequencies()[ 0 ] ) );
const int g_iFilterLength = int( 4 * ceil( g_dSampleRate / CThirdOctaveMagnitudeSpectrum::GetCenterFrequencies()[ 0 ] ) );
void TestThirdOctaveFilterGeneratorFIRIdentity();
void TestThirdOctaveFilterGeneratorFIRZero();
void TestThirdOctaveFilterGeneratorFIRSingleBands();
void TestThirdOctaveFilterGeneratorFIRDirectivityExample();
int main( int, char** )
{
TestThirdOctaveFilterGeneratorFIRIdentity();
TestThirdOctaveFilterGeneratorFIRZero();
TestThirdOctaveFilterGeneratorFIRSingleBands();
TestThirdOctaveFilterGeneratorFIRDirectivityExample();
return 255;
}
......@@ -38,7 +41,7 @@ void TestThirdOctaveFilterGeneratorFIRIdentity()
CITAThirdOctaveFIRFilterGenerator oFilterGenerator( g_dSampleRate, g_iFilterLength );
oFilterGenerator.GenerateFilter( oMags, oFilter.GetData() );
string sFilePath = "ITADSPThirdOctaveFilterGeneratorTest_Identity_FIR.wav";
string sFilePath = "ITADSPThirdOctaveFilterGeneratorFIRTest_Identity_FIR.wav";
writeAudiofile( sFilePath, &oFilter, g_dSampleRate );
cout << "Exported result to " << sFilePath << endl;
}
......@@ -53,7 +56,7 @@ void TestThirdOctaveFilterGeneratorFIRZero()
CITAThirdOctaveFIRFilterGenerator oFilterGenerator( g_dSampleRate, g_iFilterLength );
oFilterGenerator.GenerateFilter( oMags, oFilter.GetData() );
string sFilePath = "ITADSPThirdOctaveFilterGeneratorTest_Zero_FIR.wav";
string sFilePath = "ITADSPThirdOctaveFilterGeneratorFIRTest_Zero_FIR.wav";
writeAudiofile( sFilePath, &oFilter, g_dSampleRate );
cout << "Exported result to " << sFilePath << endl;
}
......@@ -72,7 +75,59 @@ void TestThirdOctaveFilterGeneratorFIRSingleBands()
oFilterGenerator.GenerateFilter( oMags, oFilter[ i ].GetData() );
}
string sFilePath = "ITADSPThirdOctaveFilterGeneratorTest_SingleBands_FIR.wav";
string sFilePath = "ITADSPThirdOctaveFilterGeneratorFIRTest_SingleBands_FIR.wav";
writeAudiofile( sFilePath, &oFilter, g_dSampleRate );
cout << "Exported result to " << sFilePath << endl;
}
void TestThirdOctaveFilterGeneratorFIRDirectivityExample()
{
std::vector< float > vfDirectivityMags = { 0.9110f, 0.9110f,
0.9110f,
0.9103f,
0.9092f,
0.9074f,
0.9039f,
0.8980f,
0.8872f,
0.8645f,
0.8262f,
0.7629f,
0.6695f,
0.5598f,
0.4747f,
0.4392f,
0.5202f,
0.8082f,
0.6256f,
0.2545f,
0.3255f,
0.1991f,
0.2711f,
0.2834f,
0.2163f,
0.1293f,
0.0362f,
0.0666f,
0.0367f,
0.0633f,
0.0633f, };
CThirdOctaveGainMagnitudeSpectrum oMags;
oMags.SetMagnitudes( vfDirectivityMags );
ITABase::Utils::JSON::Export( &oMags, "DirectivityExampleTOSpectrum.json" );
ITASampleBuffer oFilter1( g_iFilterLength, true );
CITAThirdOctaveFIRFilterGenerator oFilterGenerator1( g_dSampleRate, oFilter1.GetLength() );
oFilterGenerator1.GenerateFilter( oMags, oFilter1, false );
string sFilePath = "DirectivityExample_FIR_linear_phase.wav";
writeAudiofile( sFilePath, &oFilter1, g_dSampleRate );
cout << "Exported result to " << sFilePath << endl;
ITASampleBuffer oFilter2( g_iFilterLength, true );
CITAThirdOctaveFIRFilterGenerator oFilterGenerator2( g_dSampleRate, oFilter2.GetLength() );
oFilterGenerator2.GenerateFilter( oMags, oFilter2, true );
sFilePath = "DirectivityExample_FIR_minimum_phase.wav";
writeAudiofile( sFilePath, &oFilter2, g_dSampleRate );
cout << "Exported result to " << sFilePath << endl;
}
%% ITADSPThirdOctaveFilterGeneratorFIRTest evaluation Matlab script
% Loads the FIR filters resulting from the test ITADSPThirdOctaveFilterGeneratorFIRTest_Identity_FIR
% Requires ITA Toolbox, see http://ita-toolbox.org
dir_lin_phase_ir1 = ita_read( 'DirectivityExample_FIR_linear_phase.wav' );
dir_min_phase_ir2 = ita_read( 'DirectivityExample_FIR_minimum_phase.wav' );
dir_generated_irs = ita_merge( dir_lin_phase_ir1, dir_min_phase_ir2 );
dir_generated_irs.channelNames = { 'FIR linear phase', 'FIR minimum phase' };
dir_generated_irs.signalType = 'energy';
dirs_generated_t = ita_spk2frequencybands( dir_generated_irs );
dir_original_t = ita_result_from_json( 'DirectivityExampleTOSpectrum.json' );
dir_original_t.freqVector = dirs_generated_t.freqVector;
dir_original_t.channelNames = { 'Original third-octave band spectrum' };
dir_target_gain = rms( dir_original_t.freqData );
dir_rs = ita_merge( dir_original_t, dirs_generated_t );
dir_rs.pf
title 'FIR filtering from a directivity (third octave energetic band spectrum)'
function r = ita_result_from_json( file_path )
%ITA_RESULT_FROM_JSON Loads a spectrum from json format file
json_t = jsondecode( fileread( file_path ) );
r = itaResult();
r.domain = 'freq';
fn = fields( json_t.spectrum );
r.freqVector = zeros( numel( fn ), 1 );
r.freqData = zeros( numel( fn ), 1 );
for n = 1:numel( fn )
r.freqVector( n ) = json_t.spectrum.( fn{ n } ).center_frequency;
r.freqData( n ) = json_t.spectrum.( fn{ n } ).value;
end
end
cmake_minimum_required( VERSION 2.8 )
project( ITADSPTest )
list( APPEND CMAKE_MODULE_PATH "$ENV{VISTA_CMAKE_COMMON}" )
include( VistaCommon )
vista_use_package( VistaTools REQUIRED FIND_DEPENDENCIES )
vista_use_package( DspFilters REQUIRED FIND_DEPENDENCIES )
vista_use_package( ITABase REQUIRED FIND_DEPENDENCIES )
vista_use_package( ITADSP REQUIRED FIND_DEPENDENCIES )
vista_use_package( ITADataSources REQUIRED FIND_DEPENDENCIES )
if( ITA_CORE_LIBS_BUILD_STATIC )
add_definitions( -DITA_BASE_STATIC -DITA_DSP_STATIC -DITA_DATA_SOURCES_STATIC -DITA_CONVOLUTION_STATIC )
endif( )
if( ITA_VISTA_BUILD_STATIC )
add_definitions( -DVISTATOOLS_STATIC -DVISTABASE_STATIC -DVISTAMATH_STATIC -DVISTAASPECTS_STATIC -DVISTAINTERPROCCOMM_STATIC )
endif( )
add_executable( ITADSP_pd_jet_engine ITADSP_pd_jet_engine.cpp )
target_link_libraries( ITADSP_pd_jet_engine ${VISTA_USE_PACKAGE_LIBRARIES} )
vista_configure_app( ITADSP_pd_jet_engine )
vista_install( ITADSP_pd_jet_engine )
vista_create_default_info_file( ITADSP_pd_jet_engine )
set_property( TARGET ITADSP_pd_jet_engine PROPERTY FOLDER "ITACoreLibs/Tests/ITADSP/pd" )
#include <ITAAudiofileWriter.h>
#include <ITAConstants.h>
#include <ITASampleBuffer.h>
#include <ITAStopWatch.h>
#include <ITAStringUtils.h>
#include <ITAFiniteImpulseResponse.h>
#include <ITAMultichannelFiniteImpulseResponse.h>
#include <ITADSP/PD/JetEngine.h>
#include <iostream>
using namespace std;
const double g_dSampleRate = 44100;
const int g_iOutputLengthSamples = 20 * int( g_dSampleRate );
int iTotalSamples = 0;
int main( int, char** )
{
ITAStopWatch sw;
ITASampleBuffer oOutputBuffer( g_iOutputLengthSamples );
vector<float > vfRPMs = { 1000.f, 4000.0f, 2000.0f };
bool bColdStart = true;
ITADSP::PD::CJetEngine oPatch( g_dSampleRate, vfRPMs[ 0 ], bColdStart );
int iTimeSeriesLeg = g_iOutputLengthSamples / ( int ) vfRPMs.size();
for( auto m = 0; m < vfRPMs.size(); m++ )
{
oPatch.SetRPM( vfRPMs[ m ] );
int iProcessSamples = std::min( iTimeSeriesLeg, g_iOutputLengthSamples - m * iTimeSeriesLeg );
sw.start();
oPatch.Process( oOutputBuffer.GetData() + iTotalSamples, iProcessSamples );
sw.stop();
iTotalSamples += iProcessSamples;
}
assert( iTotalSamples == oOutputBuffer.GetLength() );
string sFilePath = "ITADSP_pd_jet_engine_out.wav";
writeAudiofile( sFilePath, &oOutputBuffer, g_dSampleRate, ITAQuantization::ITA_FLOAT );
cout << "Exported result to " << sFilePath << endl;
cout << "Real-time ratio: " << iTimeSeriesLeg / g_dSampleRate / sw.mean() << endl;
return 255;
}
%%
jet_engine = ita_read( 'ITADSP_pd_jet_engine_out.wav' );
jet_engine.plot_spectrogram
%%
jet_engine.play
cmake_minimum_required( VERSION 2.8 )
project( ITADSPVDLTest )
list( APPEND CMAKE_MODULE_PATH "$ENV{VISTA_CMAKE_COMMON}" )
include( VistaCommon )
vista_use_package( ITABase REQUIRED FIND_DEPENDENCIES )
vista_use_package( ITADSP REQUIRED FIND_DEPENDENCIES )
vista_use_package( ITADataSources REQUIRED FIND_DEPENDENCIES )
if( ITA_CORE_LIBS_BUILD_STATIC )
add_definitions( -DITA_BASE_STATIC -DITA_DSP_STATIC -DITA_DATA_SOURCES_STATIC -DITA_CONVOLUTION_STATIC )
endif( )
if( ITA_VISTA_BUILD_STATIC )
add_definitions( -DVISTATOOLS_STATIC -DVISTABASE_STATIC -DVISTAMATH_STATIC -DVISTAASPECTS_STATIC -DVISTAINTERPROCCOMM_STATIC )
endif( )
add_executable( ITADSPVariableDelayLineTest ITADSPVariableDelayLineTest.cpp )
target_link_libraries( ITADSPVariableDelayLineTest ${VISTA_USE_PACKAGE_LIBRARIES} )
vista_configure_app( ITADSPVariableDelayLineTest )
vista_install( ITADSPVariableDelayLineTest )
vista_create_default_info_file( ITADSPVariableDelayLineTest )
set_property( TARGET ITADSPVariableDelayLineTest PROPERTY FOLDER "ITACoreLibs/Tests/ITADSP/vdl" )
add_executable( ITADSPSIMOVDLTest ITADSPSIMOVDLTest.cpp )
target_link_libraries( ITADSPSIMOVDLTest ${VISTA_USE_PACKAGE_LIBRARIES} )
vista_configure_app( ITADSPSIMOVDLTest )
vista_install( ITADSPSIMOVDLTest )
vista_create_default_info_file( ITADSPSIMOVDLTest )
set_property( TARGET ITADSPSIMOVDLTest PROPERTY FOLDER "ITACoreLibs/Tests/ITADSP/vdl" )
add_executable( ITADSPSIMOVDLSourceInShoebox ITADSPSIMOVDLSourceInShoebox.cpp )
target_link_libraries( ITADSPSIMOVDLSourceInShoebox ${VISTA_USE_PACKAGE_LIBRARIES} )
vista_configure_app( ITADSPSIMOVDLSourceInShoebox )
vista_install( ITADSPSIMOVDLSourceInShoebox )
vista_create_default_info_file( ITADSPSIMOVDLSourceInShoebox )
set_property( TARGET ITADSPSIMOVDLSourceInShoebox PROPERTY FOLDER "ITACoreLibs/Tests/ITADSP/vdl" )
add_executable( ITASIMOVariableDelayLineBaseTest ITASIMOVariableDelayLineBaseTest.cpp )
target_link_libraries( ITASIMOVariableDelayLineBaseTest ${VISTA_USE_PACKAGE_LIBRARIES} )
vista_configure_app( ITASIMOVariableDelayLineBaseTest )
vista_install( ITASIMOVariableDelayLineBaseTest )
vista_create_default_info_file( ITASIMOVariableDelayLineBaseTest )
set_property( TARGET ITASIMOVariableDelayLineBaseTest PROPERTY FOLDER "ITACoreLibs/Tests/ITADSP/vdl" )
......@@ -3,7 +3,7 @@
*
* ITA core libs
* (c) Copyright Institute of Technical Acoustics (ITA)
* RWTH Aachen University, Germany, 2015-2019
* RWTH Aachen University, Germany, 2015-2020
*
* ----------------------------------------------------------------
* ____ __________ _______
......