FIR Filter Coefficients

Hello,

I am new in JUCE, and for an application I need to make a FIR highpass filter.

Within dsp::FilterDesign<float> there is no highpass filter option.

For this reason I generated the coefficients in MATLAB

Array<float> FIRcoefArray = {-0.0101734714107676, -0.0122506759629416, -0.0143718530453590, -0.0164958064465909, -0.0185621912702936, -0.0205255291316120, -0.0223238341040484, -0.0239128402851982, -0.0252347842328143, -0.0262527256143736, -0.0269193556274284, -0.0272112716305976, -0.0270976666649357, -0.0265744105336639, -0.0256324734459157, -0.0242916705039672, -0.0225686836772538, -0.0205103444958692, -0.0181611428619517, -0.0155959531605888, -0.0128869544480617, -0.0101357462109057, -0.00743964971607974, -0.00492320824562922, -0.00270389037001115, -0.000923021792812946, 0.000289036156740522, 0.000782424306544012, 0.000423009053910194, -0.000937755396741232, -0.00342736675504764, -0.00718227003003217, -0.0123123561555809, -0.0189310208351042, -0.0271198339593511, -0.0369588757072921, -0.0484917880983565, -0.0617565929201952, -0.0767513188594650, -0.0934654794513529, -0.111846434757848, -0.131831665515925, -0.153315979497040, -0.176184663260284, -0.200281583641518, -0.225443235056679, -0.251467720567198, -0.278149645441663, -0.305249895120078, -0.332531260094519, -0.359728865272646, -0.386586352546905, -0.412826762732425, -0.438189055370412, -0.462399205105592, -0.485206807340119, -0.506356129067676, -0.525622536746971, -0.542783239288691, -0.557653282246349, -0.570055738348270, -0.579857039479847, -0.586936406722050, -0.591220336681963, 21.3027116094365, -0.591220336681963, -0.586936406722050, -0.579857039479847, -0.570055738348270, -0.557653282246349, -0.542783239288691, -0.525622536746971, -0.506356129067676, -0.485206807340119, -0.462399205105592, -0.438189055370412, -0.412826762732425, -0.386586352546905, -0.359728865272646, -0.332531260094519, -0.305249895120078, -0.278149645441663, -0.251467720567198, -0.225443235056679, -0.200281583641518, -0.176184663260284, -0.153315979497040, -0.131831665515925, -0.111846434757848, -0.0934654794513529, -0.0767513188594650, -0.0617565929201952, -0.0484917880983565, -0.0369588757072921, -0.0271198339593511, -0.0189310208351042, -0.0123123561555809, -0.00718227003003217, -0.00342736675504764, -0.000937755396741232, 0.000423009053910194, 0.000782424306544012, 0.000289036156740522, -0.000923021792812946, -0.00270389037001115, -0.00492320824562922, -0.00743964971607974, -0.0101357462109057, -0.0128869544480617, -0.0155959531605888, -0.0181611428619517, -0.0205103444958692, -0.0225686836772538, -0.0242916705039672, -0.0256324734459157, -0.0265744105336639, -0.0270976666649357, -0.0272112716305976, -0.0269193556274284, -0.0262527256143736, -0.0252347842328143, -0.0239128402851982, -0.0223238341040484, -0.0205255291316120, -0.0185621912702936, -0.0164958064465909, -0.0143718530453590, -0.0122506759629416, -0.0101734714107676};

but I do not know how to add them to the method:

dsp::FIR::Coefficients<float>::Coefficients(const NumericType *samples, size_t numSamples);

Or simply how to make the filter from these coefficients,

Thank you.

There is a high pass filter? https://docs.juce.com/master/structdsp_1_1FilterDesign.html#ab37cbc9918ee475b1ccb0c4d0aced12e

You need to add that array as a float/double array not an Array using the method you mentioned.

You should get a high-pass filter by using a shifted impulse and subtracting the lowpass coefficients. The shift is around half of your FIR filter length (where the maximum is).

Make sure you normalize your coefficients, the maximum of 21.302... could get quite loud :slight_smile:

You basically have two ways to construct your coefficients

using namespace dsp;
FIR::Coefficients<float>::Ptr coeffs = new FIR::Coefficients<float> (size);
coeffs->coefficients = FIRcoefArray; // I hope the copy constructor will do its job

// OR
FIR::Coefficients<float>::Ptr coeffs = new FIR::Coefficients<float> (data, length);
// with your look up table as an Array<float>:
FIR::Coefficients<float>::Ptr coeffs = new FIR::Coefficients<float> (FIRcoefArray.getRawDataPointer(), FIRcoefArray.size());

By the way:

  • make sure the sampling frequency matches, otherwise your cut-off frequency would be wrong → resampling or recalculation of your coefficients
  • you also can use the dsp::Convolution class in case you have longer FIR filters (what was the magic number again? 128 samples? 256?) it will also resample your impulse response for you
1 Like

Thank you danielrudrich,
Your answer helped me a lot, I have solved the problem.