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

Ading DspFilters native test

parent 594ccf84
......@@ -77,3 +77,7 @@ vista_install( ITADSPThirdOctaveFilterbankTest )
vista_create_default_info_file( ITADSPThirdOctaveFilterbankTest )
set_property( TARGET ITADSPThirdOctaveFilterbankTest PROPERTY FOLDER "ITACoreLibs/Tests/ITADSP" )
if( DSPFILTERS_FOUND OR TRUE )
add_subdirectory( "dspfilters" )
endif( )
\ No newline at end of file
cmake_minimum_required( VERSION 2.8 )
project( ITADSPTest )
list( APPEND CMAKE_MODULE_PATH "$ENV{VISTA_CMAKE_COMMON}" )
include( VistaCommon )
vista_use_package( ITADSP REQUIRED FIND_DEPENDENCIES )
vista_use_package( DspFilters 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( NativeDspFiltersTest NativeDspFiltersTest.cpp )
target_link_libraries( NativeDspFiltersTest ${VISTA_USE_PACKAGE_LIBRARIES} )
vista_configure_app( NativeDspFiltersTest )
vista_install( NativeDspFiltersTest )
vista_create_default_info_file( NativeDspFiltersTest )
set_property( TARGET NativeDspFiltersTest PROPERTY FOLDER "ITACoreLibs/Tests/ITADSP/dspfilters" )
/*
* ----------------------------------------------------------------
*
* ITA core libs
* (c) Copyright Institute of Technical Acoustics (ITA)
* RWTH Aachen University, Germany, 2015-2017
*
* ----------------------------------------------------------------
* ____ __________ _______
* // / //__ ___/ // _ |
* // / // / // /_| |
* // / // / // ___ |
* //__/ //__/ //__/ |__|
*
* ----------------------------------------------------------------
*
* Testing DspFilters library.
*
*/
#include <DspFilters/Butterworth.h>
#include <ITAFiniteImpulseResponse.h>
#include <cassert>
#include <iostream>
#include <cmath>
#include <vector>
using namespace std;
using namespace Dsp;
using namespace ITABase;
float fSampleRate = 44100.0f;
const int iOrder = 10;
const int iChannels = 1;
int iFilterLength = ( int ) pow( 2, 12 );
void manual_low_pass_1kHz();
void manual_high_pass_1kHz();
void manual_band_pass_1kHz();
void tri_band();
int main( int, char** )
{
manual_low_pass_1kHz();
manual_high_pass_1kHz();
manual_band_pass_1kHz();
tri_band();
return 255;
}
void manual_low_pass_1kHz()
{
SimpleFilter< Butterworth::LowPass< iOrder >, iChannels > oBandPassFilter;
float fCuttoffFrequency = 1000.0f;
oBandPassFilter.setup( iOrder, fSampleRate, fCuttoffFrequency );
CFiniteImpulseResponse oDirac( iFilterLength, fSampleRate );
oDirac.SetDirac();
float* pf = oDirac.GetData();
oBandPassFilter.process( iFilterLength, &pf );
oDirac.Store( "NativeDspFiltersTest_IR_LP_1kHz.wav" );
}
void manual_high_pass_1kHz()
{
SimpleFilter< Butterworth::HighPass< iOrder >, iChannels > oBandPassFilter;
float fCuttoffFrequency = 1000.0f;
oBandPassFilter.setup( iOrder, fSampleRate, fCuttoffFrequency );
CFiniteImpulseResponse oDirac( iFilterLength, fSampleRate );
oDirac.SetDirac();
float* pf = oDirac.GetData();
oBandPassFilter.process( iFilterLength, &pf );
oDirac.Store( "NativeDspFiltersTest_IR_HP_1kHz.wav" );
}
void manual_band_pass_1kHz()
{
SimpleFilter< Butterworth::BandPass< iOrder >, iChannels > oBandPassFilter;
float fCenterFrequency = 1000.0f;
float fBandWidth = fCenterFrequency * ( float ) ( sqrt( 2 ) - 1 / sqrt( 2 ) );
oBandPassFilter.setup( iOrder, fSampleRate, fCenterFrequency, fBandWidth );
CFiniteImpulseResponse oDirac( iFilterLength, fSampleRate );
oDirac.SetDirac();
float* pf = oDirac.GetData();
oBandPassFilter.process( iFilterLength, &pf );
oDirac.Store( "NativeDspFiltersTest_IR_BP_1kHz.wav" );
}
void tri_band()
{
float fLowerFrequencyCuttoff = 330.0f;
float fHigherFrequencyCuttoff = 3900.0f;
float fMidCenterFrequency = 2300.0f;
float fMidBandWidth = 4000;
SimpleFilter< Butterworth::LowPass< iOrder >, iChannels > oLPF;
oLPF.setup( iOrder, fSampleRate, fLowerFrequencyCuttoff );
SimpleFilter< Butterworth::HighPass< iOrder >, iChannels > oHPF;
oHPF.setup( iOrder, fSampleRate, fHigherFrequencyCuttoff );
SimpleFilter< Butterworth::BandPass< iOrder >, iChannels > oBPF;
assert( fMidBandWidth > 0 );
oBPF.setup( iOrder, fSampleRate, fMidCenterFrequency, fMidBandWidth );
CFiniteImpulseResponse oIR( iFilterLength, fSampleRate );
oIR.SetDirac();
float* pf = oIR.GetData();
oLPF.process( iFilterLength, &pf );
oIR.Store( "NativeDspFiltersTest_IR_Triband_Low.wav" );
oIR.SetDirac();
pf = oIR.GetData();
oBPF.process( iFilterLength, &pf );
oIR.Store( "NativeDspFiltersTest_IR_Triband_Mid.wav" );
oIR.SetDirac();
pf = oIR.GetData();
oHPF.process( iFilterLength, &pf );
oIR.Store( "NativeDspFiltersTest_IR_Triband_High.wav" );
}
\ No newline at end of file
%% Manual filters at 1kHz
IR_LP_1kHz = ita_read( 'NativeDspFiltersTest_IR_LP_1kHz.wav' );
IR_HP_1kHz = ita_read( 'NativeDspFiltersTest_IR_HP_1kHz.wav' );
IR_BP_1kHz = ita_read( 'NativeDspFiltersTest_IR_BP_1kHz.wav' );
IR_manual_filters_1kHz = ita_merge( IR_LP_1kHz, IR_HP_1kHz, IR_BP_1kHz );
IR_manual_filters_1kHz.channelNames = { 'Low pass 1kHz', 'High pass 1kHz', 'Band pass 1kHz and bandwidth 707Hz' };
%IR_manual_filters_1kHz.pf
%% Tribands
IR_Triband_Low = ita_read( 'NativeDspFiltersTest_IR_Triband_Low.wav' );
IR_Triband_Mid = ita_read( 'NativeDspFiltersTest_IR_Triband_Mid.wav' );
IR_Triband_High = ita_read( 'NativeDspFiltersTest_IR_Triband_High.wav' );
IR_Triband = ita_merge( IR_Triband_Low, IR_Triband_Mid, IR_Triband_High );
IR_Triband = ita_merge( IR_Triband, IR_Triband.sum );
IR_Triband.channelNames = { 'Low pass 250kHz cutoff', ...
'Band pass 1kHz bandwidth 3.75kHz', ...
'High pass 4kHz cutoff', ...
'Triband identity (sum)' };
IR_Triband.pf
Supports Markdown
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