# IIRFilter aliasing

**URL:** <https://forum.juce.com/t/iirfilter-aliasing/26149>\
**Category:** General JUCE discussion\
**Created:** [January 27, 2018, 7:19pm UTC](https://forum.juce.com/t/iirfilter-aliasing/26149 "2018-01-27T19:19:05Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![vincent](https://avatars.discourse-cdn.com/v4/letter/v/e9bcb4/32.png) [@vincent](https://forum.juce.com/u/vincent)\
**Post date:** [January 27, 2018, 7:19pm UTC](https://forum.juce.com/t/iirfilter-aliasing/26149/1 "2018-01-27T19:19:06Z")

</div>

I have a set of hpf and lpfs, they do filter the audio as expected but lots of crackling happens. I think I must be missing something or not be using the filters correctly in the processBlock but I’m not sure what I’m doing wrong

In processor’s private: ([2], one for each channel)  
`IIRFilter highpassFilter[2];`  
`IIRFilter lowpassFilter[2];`

I then set initial values in the constructor. `highpassFilter[0].setCoefficients(IIRCoefficients::makeHighPass(iSampleRate, hpfFreq)); highpassFilter[1].setCoefficients(IIRCoefficients::makeHighPass(iSampleRate, hpfFreq)); lowpassFilter[0].setCoefficients(IIRCoefficients::makeLowPass(iSampleRate, lpfFreq)); lowpassFilter[1].setCoefficients(IIRCoefficients::makeLowPass(iSampleRate, lpfFreq));`

I also use `.setCoefficients` at the top of processBlock so they’re updated once each buffer. `hpfFreq` and `lpfFreq` are changed with parameters.

and then later in processBlock, outside of any loop I use these  
`highpassFilter[0].processSamples(buffer.getWritePointer(0), buffer.getNumSamples()); highpassFilter[1].processSamples(buffer.getWritePointer(1), buffer.getNumSamples()); lowpassFilter[0].processSamples(buffer.getWritePointer(0), buffer.getNumSamples()); lowpassFilter[1].processSamples(buffer.getWritePointer(1), buffer.getNumSamples());`

---

<div class="post-metadata">

**Author:** ![theaudioprogrammer](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/theaudioprogrammer/32/18383_2.png) [@theaudioprogrammer](https://forum.juce.com/u/theaudioprogrammer)\
**Post date:** [January 27, 2018, 7:34pm UTC](https://forum.juce.com/t/iirfilter-aliasing/26149/2 "2018-01-27T19:34:11Z")

</div>

I think you may want to look at refactoring your code a little. Rather than having 2 of everything, you can use a nested for loop in the process block to iterate through your read/write pointers and iir filters and do everything in one, rather than explicitly spelling out the processing on channel 0 and 1. Check this vid it will explain how…

Another option is to use `dsp::ProcessorDuplicator` Which will take the mono `dsp::IIRFilter` and extend it to stereo or your output configuration. If you need assistance check this vid on how I use it with the `dsp::StateVariableFilter`. I hope that helps!

---

<div class="post-metadata">

**Author:** ![daniel](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/daniel/32/790_2.png) [@daniel](https://forum.juce.com/u/daniel)\
**Post date:** [January 27, 2018, 7:44pm UTC](https://forum.juce.com/t/iirfilter-aliasing/26149/3 "2018-01-27T19:44:30Z")

</div>

IIRFilter is the older version, before the dsp module came out. So ProcessorDuplicator will not play with that one.  
The dsp module one is called [dsp::IIR::Filter](https://juce.com/doc/classdsp_1_1IIR_1_1Filter)

It’s worth checking it out, newer, better performance etc…

To the OP, I don’t see anything obvious, but if you change the IIRCoefficients in big steps, the results will be audible. In which case you will have to blend between the coefficient sets (I haven’t done this yet).

> [@vincent](#):
>
> I also use .setCoefficients at the top of processBlock so they’re updated once each buffer. hpfFreq and lpfFreq are changed with parameters.

Maybe save the values of hpfFreq and lpfFreq and set the coefficients only, if they have changed. Maybe that helps…

---

<div class="post-metadata">

**Author:** ![vincent](https://avatars.discourse-cdn.com/v4/letter/v/e9bcb4/32.png) [@vincent](https://forum.juce.com/u/vincent)\
**Post date:** [January 28, 2018, 1:19pm UTC](https://forum.juce.com/t/iirfilter-aliasing/26149/4 "2018-01-28T13:19:39Z")

</div>

> [@daniel](#):
>
> To the OP, I don’t see anything obvious, but if you change the IIRCoefficients in big steps, the results will be audible. In which case you will have to blend between the coefficient sets (I haven’t done this yet).

I do have the frequency smoothed so it doesn’t have too sudden changes but I could play with the speed of this thanks.

I’m trying to use the dsp::stateVariableFilter which I use in a class and pluginProcessor needs to access the filter object so I can call class.filter.process(block) but using a filter getter like below doesn’t work. Apologies I’m new to these aThing\<blah::blah, blah:blah\> style things  
`1dsp::ProcessorDuplicator<dsp::StateVariableFilter::Filter<double>, dsp::StateVariableFilter::Parameters<float>> effects::getFilter(int channel) const`  
` { return stateVariableFilter; }`  
Error code:  
`'juce::dsp::StateVariableFilter::Filter<double>::Filter(juce::dsp::StateVariableFilter::Filter<double> &&)': cannot convert argument 1 from 'juce::ReferenceCountedObjectPtr<juce::dsp::StateVariableFilter::Parameters<float>>' to 'juce::dsp::StateVariableFilter::Parameters<double> *' (compiling source file ..\..\Source\effects.cpp)`
