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

Extending native DspFilters test, now also includes an octave band filter bank design

parent b6624526
......@@ -20,6 +20,7 @@
#include <DspFilters/Butterworth.h>
#include <ITAConstants.h>
#include <ITAFiniteImpulseResponse.h>
#include <cassert>
......@@ -30,6 +31,7 @@
using namespace std;
using namespace Dsp;
using namespace ITABase;
using namespace ITAConstants;
float fSampleRate = 44100.0f;
const int iOrder = 10;
......@@ -40,6 +42,8 @@ void manual_low_pass_1kHz();
void manual_high_pass_1kHz();
void manual_band_pass_1kHz();
void tri_band();
void downcast_test();
void octave_bands();
int main( int, char** )
{
......@@ -49,6 +53,10 @@ int main( int, char** )
tri_band();
downcast_test();
octave_bands();
return 255;
}
......@@ -56,6 +64,7 @@ void manual_low_pass_1kHz()
{
SimpleFilter< Butterworth::LowPass< iOrder >, iChannels > oBandPassFilter;
float fCuttoffFrequency = 1000.0f;
oBandPassFilter.setup( iOrder, fSampleRate, fCuttoffFrequency );
......@@ -134,4 +143,51 @@ void tri_band()
pf = oIR.GetData();
oHPF.process( iFilterLength, &pf );
oIR.Store( "NativeDspFiltersTest_IR_Triband_High.wav" );
}
\ No newline at end of file
}
void downcast_test()
{
SimpleFilter< Butterworth::BandPass< iOrder >, iChannels > oBandPassFilter;
SimpleFilter< Butterworth::BandPass< iOrder >, iChannels >* pBPF = &oBandPassFilter;
float fV = 1.0f;
float* pf = &fV;
pBPF->process( 1, &pf );
}
void octave_bands()
{
CFiniteImpulseResponse oIR( iFilterLength, fSampleRate );
float fLowPassFrequencyCuttoff = OCTAVE_CENTER_FREQUENCIES_ISO_F[0] * sqrt( 2.0f );
SimpleFilter< Butterworth::LowPass< iOrder >, iChannels > oLPF;
oLPF.setup( iOrder, fSampleRate, fLowPassFrequencyCuttoff );
oIR.SetDirac();
float* pf = oIR.GetData();
oLPF.process( iFilterLength, &pf );
oIR.Store( "NativeDspFiltersTest_IR_OctaveBands_LP.wav" );
for( size_t i = 1; i < OCTAVE_CENTER_FREQUENCIES_ISO_F.size() - 1; i++ )
{
float fMidCenterFrequency = OCTAVE_CENTER_FREQUENCIES_ISO_F[i];
float fMidBandWidth = ( OCTAVE_CENTER_FREQUENCIES_ISO_F[ i + 1 ] - OCTAVE_CENTER_FREQUENCIES_ISO_F[ i - 1 ] ) / 2.15f;
SimpleFilter< Butterworth::BandPass< iOrder >, iChannels > oBPF;
assert( fMidBandWidth > 0 );
oBPF.setup( iOrder, fSampleRate, fMidCenterFrequency, fMidBandWidth );
oIR.SetDirac();
pf = oIR.GetData();
oBPF.process( iFilterLength, &pf );
oIR.Store( "NativeDspFiltersTest_IR_OctaveBands_BP" + std::to_string( ( long ) ( i ) ) + ".wav" );
}
float fHighPassFrequencyCuttoff = OCTAVE_CENTER_FREQUENCIES_ISO_F[ OCTAVE_CENTER_FREQUENCIES_ISO_F.size() - 1 ] / sqrt( 2.0f );
SimpleFilter< Butterworth::HighPass< iOrder >, iChannels > oHPF;
oHPF.setup( iOrder, fSampleRate, fHighPassFrequencyCuttoff );
oIR.SetDirac();
pf = oIR.GetData();
oHPF.process( iFilterLength, &pf );
oIR.Store( "NativeDspFiltersTest_IR_OctaveBands_HP.wav" );
}
......@@ -23,4 +23,22 @@ IR_Triband.channelNames = { 'Low pass 250kHz cutoff', ...
'High pass 4kHz cutoff', ...
'Triband identity (sum)' };
IR_Triband.pf
%IR_Triband.pf
%% Octaves
IR_Octaves_LP = ita_read( 'NativeDspFiltersTest_IR_OctaveBands_LP.wav' );
IR_Octaves_BP1 = ita_read( 'NativeDspFiltersTest_IR_OctaveBands_BP1.wav' );
IR_Octaves_BP2 = ita_read( 'NativeDspFiltersTest_IR_OctaveBands_BP2.wav' );
IR_Octaves_BP3 = ita_read( 'NativeDspFiltersTest_IR_OctaveBands_BP3.wav' );
IR_Octaves_BP4 = ita_read( 'NativeDspFiltersTest_IR_OctaveBands_BP4.wav' );
IR_Octaves_BP5 = ita_read( 'NativeDspFiltersTest_IR_OctaveBands_BP5.wav' );
IR_Octaves_BP6 = ita_read( 'NativeDspFiltersTest_IR_OctaveBands_BP6.wav' );
IR_Octaves_BP7 = ita_read( 'NativeDspFiltersTest_IR_OctaveBands_BP7.wav' );
IR_Octaves_BP8 = ita_read( 'NativeDspFiltersTest_IR_OctaveBands_BP8.wav' );
IR_Octaves_HP = ita_read( 'NativeDspFiltersTest_IR_OctaveBands_HP.wav' );
IR_Octaves = ita_merge( IR_Octaves_LP, IR_Octaves_BP1, IR_Octaves_BP2,IR_Octaves_BP3, IR_Octaves_BP4, IR_Octaves_BP5, IR_Octaves_BP6, IR_Octaves_BP7, IR_Octaves_BP8, IR_Octaves_HP );
IR_Octaves = ita_merge( IR_Octaves, IR_Octaves.sum );
IR_Octaves.pf
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