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

Tests running smoothly and showing comparable results

parent fc8bd42e
......@@ -3,6 +3,8 @@
#include <ITAIIRFilterGenerator.h>
#include <ITAThirdOctaveFIRFilterGenerator.h>
#include <algorithm>
using namespace ITADSP::ThirdOctaveFilterbank;
CIIRBurg::CIIRBurg( const double dSampleRate, const int iBlockLength, const int iFilterOrder /* = 4 */ )
......
......@@ -20,6 +20,7 @@
#include <ITAStreamFunctionGenerator.h>
#include <ITAFileDataSource.h>
#include <ITAStreamInfo.h>
#include <ITABase/UtilsJSON.h>
#include <math.h>
#include <vector>
......@@ -37,14 +38,17 @@
#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 ] ) );;
// 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 };
......@@ -64,8 +68,8 @@ void Burg_Time_Test();
int main( int, char** )
{
DesignFromSpectrum();
VDLIIRTest();
Burg_Time_Test();
//VDLIIRTest();
//Burg_Time_Test();
return 255;
}
......@@ -77,64 +81,47 @@ void DesignFromSpectrum()
// Generate an impulse response from the given spectra
ITABase::CThirdOctaveGainMagnitudeSpectrum oMags;
ITABase::CFiniteImpulseResponse oIRTarget( 1024, g_fSampleRate );
ITABase::CFiniteImpulseResponse oIRTarget( g_iFIRGenLength, 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 );
for( int i = 0; i < oMags.GetNumBands(); i++ )
oMags.SetValue( i, sqrt( 1.0f - oMags.GetValues()[ i ] ) );
#ifdef WITH_JSON_SUPPORT
ITADSP::ExportIIRCoefficientsToJSON( "ITADSPIIRFilterTest_AbsorptionCoeffs_+3dB.json", oBurgCoeffs );
ITABase::Utils::JSON::Export( &oMags, "ReflectionTOSpectrum.json" );
#endif
// Absorption spectrum with higher order
oMags.SetMagnitudes( vfAbsorptionSpectrumTO );
oIRGenerator.GenerateFilter( oMags, oIRTarget.GetData(), true );
oBurgCoeffs.InitialiseOrder( 10 );
oIRTarget.Store( "ReflectionIR_min_phase.wav" );
ITADSP::IIRFilterGenerator::Burg( oIRTarget, oBurgCoeffs );
#ifdef WITH_JSON_SUPPORT
ITADSP::ExportIIRCoefficientsToJSON( "ITADSPIIRFilterTest_AbsorptionCoeffs_order10.json", oBurgCoeffs );
ITADSP::ExportIIRCoefficientsToJSON( "ReflectionIIRCoeffs.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 );
// Directivity spectrum
oMags.SetMagnitudes( vfTrumpetDirectivitySpectrumTO );
#ifdef WITH_JSON_SUPPORT
ITADSP::ExportIIRCoefficientsToJSON( "ITADSPIIRFilterTest_AbsorptionCoeffs_order100.json", oBurgCoeffs );
ITABase::Utils::JSON::Export( &oMags, "DirectivityTOSpectrum.json" );
#endif
// Trumpet directivity spectrum
oMags.SetMagnitudes( vfTrumpetDirectivitySpectrumTO );
oIRGenerator.GenerateFilter( oMags, oIRTarget.GetData(), true );
oIRTarget.Store( "ITADSPIIRFilterGeneratorTest_TrumpetDirectivityIR.wav" );
oIRTarget.Store( "DirectivityIR_min_phase.wav" );
oBurgCoeffs.InitialiseOrder( 4 );
ITADSP::IIRFilterGenerator::Burg( oIRTarget, oBurgCoeffs );
#ifdef WITH_JSON_SUPPORT
ITADSP::ExportIIRCoefficientsToJSON( "ITADSPIIRFilterTest_TrumpetDirectivityCoeffs.json", oBurgCoeffs );
ITADSP::ExportIIRCoefficientsToJSON( "DirectivityIIRCoeffs.json", oBurgCoeffs );
#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( "ITADSPIIRFilterGeneratorTest_DiffractionIR.wav" );
oIRTarget.Store( "DiffractionIR_min_phase.wav" );
oBurgCoeffs.InitialiseOrder( 4 );
ITADSP::IIRFilterGenerator::Burg( oIRTarget, oBurgCoeffs );
#ifdef WITH_JSON_SUPPORT
ITADSP::ExportIIRCoefficientsToJSON( "ITADSPIIRFilterTest_DiffractionCoeffs.json", oBurgCoeffs );
ITADSP::ExportIIRCoefficientsToJSON( "DiffractionIIRCoeffs.json", oBurgCoeffs );
#endif
}
......@@ -186,12 +173,6 @@ void Burg_Time_Test() {
}
}
void VDLIIRTest()
{
//input parameters
......
%% 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' };
%% 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_coeffs = jsondecode( fileread( 'ReflectionIIRCoeffs.json' ) );
reflection_iir = dsp.IIRFilter;
reflection_iir.Numerator = [ reflection_coeffs.numerator.b0 0 0 0 0 ];
reflection_iir.Denominator = [ reflection_coeffs.denominator.a1 ...
reflection_coeffs.denominator.a2 ...
reflection_coeffs.denominator.a3 ...
reflection_coeffs.denominator.a4 ...
reflection_coeffs.denominator.a5 ];
reflection_ir_filtering = reflection_ir;
reflection_ir_filtering.timeData = reflection_iir( 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)'
absorption_irs = ita_merge( absorption_ir, absorption_ir_filtering_order100 );
absorption_irs.pf
%% Directivity
%% Trumpet directivity
directivity_ir = ita_read( 'DirectivityIR_min_phase.wav' );
directivity_ir.channelNames = { 'Directivity IR from C++ generator' };
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 );
directivity_coeffs = jsondecode( fileread( 'DirectivityIIRCoeffs.json' ) );
directivity_iir = dsp.IIRFilter;
directivity_iir.Numerator = [ directivity_coeffs.numerator.b0 ];
directivity_iir.Denominator = zeros( 1, 5 );
for i = 1:5
trumpet_directivity_iir.Denominator( i ) = trumpet_directivity_coeffs.denominator.( [ 'a' num2str( i ) ] );
directivity_iir.Denominator( i ) = 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' };
directivity_ir_filtering = directivity_ir;
directivity_ir_filtering.timeData = directivity_iir( excitation_ir.timeData );
directivity_ir_filtering.channelNames = { 'Matlab IIR response (order 4)' };
trumpet_directivity_irs = ita_merge( trumpet_directivity_ir, trumpet_directivity_ir_filtering );
trumpet_directivity_irs.pf
directivity_irs = ita_merge( directivity_ir, directivity_ir_filtering );
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' };
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';
dir_rs = ita_merge( dir_target_r, dir_rs );
dir_rs.pf
title 'Directivity filtering (third octave energetic band 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_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 );
......@@ -118,14 +74,18 @@ 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_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.pf
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' };
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';
dir_rs = ita_merge( diffr_target_r, diffr_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,8 +14,7 @@ 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();
......@@ -82,10 +82,6 @@ void TestThirdOctaveFilterGeneratorFIRSingleBands()
void TestThirdOctaveFilterGeneratorFIRDirectivityExample()
{
ITASampleBuffer oFilter( g_iFilterLength, true );
CITAThirdOctaveFIRFilterGenerator oFilterGenerator( g_dSampleRate, g_iFilterLength );
std::vector< float > vfDirectivityMags = { 0.9110f, 0.9110f,
0.9110f,
0.9103f,
......@@ -119,9 +115,19 @@ void TestThirdOctaveFilterGeneratorFIRDirectivityExample()
CThirdOctaveGainMagnitudeSpectrum oMags;
oMags.SetMagnitudes( vfDirectivityMags );
oFilterGenerator.GenerateFilter( oMags, oFilter.GetData() );
ITABase::Utils::JSON::Export( &oMags, "DirectivityExampleTOSpectrum.json" );
string sFilePath = "ITADSPThirdOctaveFilterGeneratorFIRTest_DirectivityExample_FIR.wav";
writeAudiofile( sFilePath, &oFilter, g_dSampleRate );
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;
}
......@@ -3,54 +3,20 @@
% Loads the FIR filters resulting from the test ITADSPThirdOctaveFilterGeneratorFIRTest_Identity_FIR
% Requires ITA Toolbox, see http://ita-toolbox.org
ITADSPThirdOctaveFilterGeneratorFIRTest_Identity_FIR = ita_read( 'ITADSPThirdOctaveFilterGeneratorFIRTest_Identity_FIR.wav' );
ITADSPThirdOctaveFilterGeneratorFIRTest_Zero_FIR = ita_read( 'ITADSPThirdOctaveFilterGeneratorFIRTest_Zero_FIR.wav' );
ITADSPThirdOctaveFilterGeneratorFIRTest_SingleBands_FIR = ita_read( 'ITADSPThirdOctaveFilterGeneratorFIRTest_SingleBands_FIR.wav' );
ITADSPThirdOctaveFilterGeneratorFIRTest_Zero_FIR.channelNames = { 'Zero' };
%ITADSPThirdOctaveFilterGeneratorFIRTest_Zero_FIR.pf % OK
ITADSPThirdOctaveFilterGeneratorFIRTest_Identity_FIR.channelNames = { 'Identity' };
%ITADSPThirdOctaveFilterGeneratorFIRTest_Identity_FIR.pf % OK
ITADSPThirdOctaveFilterGeneratorFIRTest_SingleBands_FIR.pf
%%
directivit_example_ir = ita_read( 'ITADSPThirdOctaveFilterGeneratorFIRTest_DirectivityExample_FIR.wav' );
directivity_example_t = ita_spk2frequencybands( directivit_example_ir, 'bandsperoctave', 3 );
dir_mags = [ 0.9110, 0.9110, 0.9110, ...
0.9103, ...
0.9092, ...
0.9074, ...
0.9039, ...
0.8980, ...
0.8872, ...
0.8645, ...
0.8262, ...
0.7629, ...
0.6695, ...
0.5598, ...
0.4747, ...
0.4392, ...
0.5202, ...
0.8082, ...
0.6256, ...
0.2545, ...
0.3255, ...
0.1991, ...
0.2711, ...
0.2834, ...
0.2163, ...
0.1293, ...
0.0362, ...
0.0666, ...
0.0367, ...
0.0633, ...
0.0633 ];
directivity_r = itaResult();
directivity_r.freqVector = ita_ANSI_center_frequencies;
directivity_r.freqData = dir_mags';
\ No newline at end of file
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.freqData = dir_rs.freqData ./ rms( dir_rs.freqData ) .* dir_target_gain;
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
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