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

Improving tests, now with export of spectra to JSON

parent 619fa229
......@@ -38,12 +38,22 @@ int main( int, char** )
sbDirac[ 0 ] = 1.0f;
oZero.SetZero();
#ifdef WITH_JSON_SUPPORT
ITABase::Utils::JSON::Export( &oZero, "ZeroSpectrum.json" );
#endif
oIdentity.SetIdentity();
oIdentity.Multiply( 1.000001f );
#ifdef WITH_JSON_SUPPORT
ITABase::Utils::JSON::Export( &oIdentity, "IdentitySpectrum.json" );
#endif
oHighPass.SetIdentity();
for( int i = 15; i >= 0; i-- )
oHighPass[ i ] = powf( 0.5f, 15.0f - float( i ) );
#ifdef WITH_JSON_SUPPORT
ITABase::Utils::JSON::Export( &oHighPass, "HighPassSpectrum.json" );
#endif
oSomeBands.SetZero();
oSomeBands[ 3 ] = ( float ) db10_to_ratio( 3.0f );
......@@ -52,13 +62,22 @@ int main( int, char** )
oSomeBands[ 12 ] = ( float ) db10_to_ratio( -9.0f );
oSomeBands[ 13 ] = ( float ) db10_to_ratio( -9.0f );
oSomeBands[ 14 ] = ( float ) db10_to_ratio( -7.0f );
#ifdef WITH_JSON_SUPPORT
ITABase::Utils::JSON::Export( &oSomeBands, "SomeBandsSpectrum.json" );
#endif
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 };
for( int i = 0; i < oAbsorption.GetNumBands(); i++ )
oAbsorption.SetMagnitude( i, 1 - vfAbsorptionSpectrumTO[ i ] * vfAbsorptionSpectrumTO[ i ] );
#ifdef WITH_JSON_SUPPORT
ITABase::Utils::JSON::Export( &oAbsorption, "ReflectedSpectrum.json" );
#endif
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 };
oDirectivity.SetMagnitudes( vfTrumpetDirectivitySpectrumTO );
#ifdef WITH_JSON_SUPPORT
ITABase::Utils::JSON::Export( &oDirectivity, "DirectivitySpectrum.json" );
#endif
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 };
oDiffraction.SetMagnitudes( vfDiffractionSpectrumTO );
......
......@@ -4,7 +4,7 @@
% Requires ITA Toolbox, see http://ita-toolbox.org
%% FIR spline interpolation linear phase
fir_zero = ita_read( 'ITADSPThirdOctaveFilterbankTest_FIRSplineLinearPhase_Zeros.wav' );
fir_zeros = ita_read( 'ITADSPThirdOctaveFilterbankTest_FIRSplineLinearPhase_Zeros.wav' );
fir_unity = ita_read( 'ITADSPThirdOctaveFilterbankTest_FIRSplineLinearPhase_Identity.wav' );
fir_sb = ita_read( 'ITADSPThirdOctaveFilterbankTest_FIRSplineLinearPhase_SomeBands.wav' );
fir_hp = ita_read( 'ITADSPThirdOctaveFilterbankTest_FIRSplineLinearPhase_HighPass.wav' );
......@@ -30,33 +30,98 @@ iir_bq_abs = ita_read( 'ITADSPThirdOctaveFilterbankTest_IIRBiquadOrder10_Absorb.
iir_bq_dir = ita_read( 'ITADSPThirdOctaveFilterbankTest_IIRBiquadOrder10_Dir.wav' );
iir_bq_dif = ita_read( 'ITADSPThirdOctaveFilterbankTest_IIRBiquadOrder10_Diffr.wav' );
%% JSON import
json_zeros = load_result_from_json_file( 'ZeroSpectrum.json' );
json_ident = load_result_from_json_file( 'IdentitySpectrum.json' );
json_hp = load_result_from_json_file( 'HighPassSpectrum.json' );
json_sb = load_result_from_json_file( 'SomeBandsSpectrum.json' );
json_refl = load_result_from_json_file( 'ReflectedSpectrum.json' );
json_dir = load_result_from_json_file( 'DirectivitySpectrum.json' );
json_diffr = load_result_from_json_file( 'DiffractionSpectrum.json' );
%% Plots
cn = { 'Original input spectrum', 'FIR Spline-Interpolation Linear-Phase', 'IIR Burg Design Algorithm', 'IIR BiQuad filterbank structure' };
if false
if 0
cp_zeros = ita_merge( fir_zeros, iir_burg_zeros, iir_bq_zeros );
cp_zeros.channelNames = { 'FIR Spline-Interpolation Linear-Phase', 'IIR Burg Design Algorithm', 'IIR BiQuad filterbank structure' };
% cp_zeros.pf % all correct
%title( 'Zero magnitude spectrum' )
cp_zeros.signalType = 'energy';
cp_zeros_r = ita_spk2frequencybands( cp_zeros );
json_zero_r = cp_zeros_r.ch(1);
json_zero_r.freqData = json_zeros.freqData;
cp_zeros_r = ita_merge( json_zero_r, cp_zeros_r );
cp_zeros_r.channelNames = cn;
cp_zeros_r.pf
title( 'Zero spectrum' )
end
if 0
cp_ident = ita_merge( fir_unity, iir_burg_unity, iir_bq_unity );
cp_ident.channelNames = { 'FIR Spline-Interpolation Linear-Phase', 'IIR Burg Design Algorithm', 'IIR BiQuad filterbank structure' };
% cp_ident.pf % low freq problems in iir burg and fir approach
%title( 'Identity magnitude spectrum' )
cp_ident.signalType = 'energy';
cp_ident_r = ita_spk2frequencybands( cp_ident );
json_zero_r = cp_ident_r.ch(1);
json_zero_r.freqData = json_ident.freqData;
cp_ident_r = ita_merge( json_zero_r, cp_ident_r );
cp_ident_r.channelNames = cn;
cp_ident_r.pf
title( 'Identity / unity spectrum' )
end
cp_some_bands = ita_merge( fir_sb, iir_burg_sb, iir_bq_sb );
cp_some_bands.channelNames = { 'FIR Spline-Interpolation Linear-Phase', 'IIR Burg Design Algorithm', 'IIR BiQuad filterbank structure' };
%cp_some_bands.pf
%title( 'Some band spectrum' )
if 0
cp_sb = ita_merge( fir_sb, iir_burg_sb, iir_bq_sb );
cp_sb.signalType = 'energy';
cp_sb_r = ita_spk2frequencybands( cp_sb );
json_sb_r = cp_sb_r.ch(1);
json_sb_r.freqData = json_sb.freqData;
cp_sb_r = ita_merge( json_sb_r, cp_sb_r );
cp_sb_r.channelNames = cn;
cp_sb_r.pf
title( 'Some bands spectrum' )
end
if 0
cp_hp = ita_merge( fir_hp, iir_burg_hp, iir_bq_hp );
cp_hp.channelNames = { 'FIR Spline-Interpolation Linear-Phase', 'IIR Burg Design Algorithm', 'IIR BiQuad filterbank structure' };
%cp_hp.pf
%title( 'High-pass spectrum' )
cp_hp.signalType = 'energy';
cp_hp_r = ita_spk2frequencybands( cp_hp );
json_hp_r = cp_hp_r.ch(1);
json_hp_r.freqData = json_hp.freqData;
cp_hp_r = ita_merge( json_hp_r, cp_hp_r );
cp_hp_r.channelNames = cn;
cp_hp_r.pf
title( 'High-pass spectrum' )
end
if true
if 0
cp_dir = ita_merge( fir_dir, iir_burg_dir, iir_bq_dir );
cp_dir.channelNames = { 'FIR Spline-Interpolation Linear-Phase', 'IIR Burg Design Algorithm', 'IIR BiQuad filterbank structure' };
cp_dir.pf
cp_dir.signalType = 'energy';
cp_dir_r = ita_spk2frequencybands( cp_dir );
json_dir_r = cp_dir_r.ch(1);
json_dir_r.freqData = json_dir.freqData;
cp_dir_r = ita_merge( json_dir_r, cp_dir_r );
cp_dir_r.channelNames = cn
cp_dir_r.pf
title( 'Directivity spectrum' )
end
%% Helper functions
function ita_result_t = load_result_from_json_file( file_path )
json_t = jsondecode( fileread( file_path ) );
ita_result_t = itaResult();
ita_result_t.domain = 'freq';
fn = fields( json_t.spectrum );
ita_result_t.freqVector = zeros( numel( fn ), 1 );
ita_result_t.freqData = zeros( numel( fn ), 1 );
for n = 1:numel( fn )
ita_result_t.freqVector( n ) = json_t.spectrum.( fn{ n } ).center_frequency;
ita_result_t.freqData( n ) = json_t.spectrum.( fn{ n } ).value;
end
end
......@@ -49,10 +49,10 @@ const float g_fSampleRate = 44100;
// 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
// 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 };
//diffracion filter
// 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 };
......
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