How to use One Pole/First order Low Pass Filter within a fixed Cutoff range?

DSP, Plugin and Host development discussion.
RELATED
PRODUCTS

Post

Code: Select all

a = 1.0 - exp(-2.0*pi*frequency/sampleRate);
Also from musicdsp.org. The same as your example on the first post, but with the coefficient formula: http://www.musicdsp.org/showArchiveComm ... hiveID=237

Check the comments for optimisations.

Post

matt42 wrote:

Code: Select all

a = 1.0 - exp(-2.0*pi*frequency/sampleRate);
Also from musicdsp.org. The same as your example on the first post, but with the coefficient formula: http://www.musicdsp.org/showArchiveComm ... hiveID=237

Check the comments for optimisations.
Nice, this was the formula I was asking! Sorry for the confusion (english is not my native language eheh). Thank you very much man!

Well, looking at other filter implementations (same one pole/first order formula) I can see someone calculate this coefficent in a different way.
This for example is different:

Code: Select all

lf = 2 * sin(M_PI * ((double)lowfreq / (double)mixfreq));
And also this:

Code: Select all

p = (2-cos(x)) - sqrt((2-cos(x))^2 - 1) with x = 2*pi*cutoff/samplerate
So there isnt a unique way of settings the coefficients on a fixed filter. I guess this is just DSP "talent", right? :)

Post

Nowhk wrote:So there isnt a unique way of settings the coefficients on a fixed filter.
This is just because the filter is not a strict lowpass. It's actually a sort of leaking lowpass turning into more like a high-shelf when F is approaching Fn. Hence different formulae may exist depending on how we'll prefer to see it when F goes high enough.
From above three variants the third one is looking the most fair for higher freqs (don't miss that for your implementation it will be k = 1 - p of it).

Post

Max M. wrote:
Nowhk wrote:So there isnt a unique way of settings the coefficients on a fixed filter.
This is just because the filter is not a strict lowpass. It's actually a sort of leaking lowpass turning into more like a high-shelf when F is approaching Fn. Hence different formulae may exist depending on how we'll prefer to see it when F goes high enough.
From above three variants the third one is looking the most fair for higher freqs (don't miss that for your implementation it will be k = 1 - p of it).
I see! Thanks guys!!!! :party:

I think that on biquad filters, coefficients calc follow strictly rules :D

Post

Nowhk wrote:I think that on biquad filters, coefficients calc follow strictly rules
Not really. There it also depends on what curve we need and we often need quite different things.

Post

Max M. wrote:
Nowhk wrote:I think that on biquad filters, coefficients calc follow strictly rules
Not really. There it also depends on what curve we need and we often need quite different things.
I see. So even calculate the coefficents is a sort of "filter" design. Not only the based-formula behind it. DSP makes mind crazy...
I need to learn che correlation between poles and frequency. I think it's all about Unit Circle and how fast you process phase during the filtering process.

This will give to me the response about "why 1.0 - exp(-2.0*pi*20/sampleRate); as coefficient correspond to 20hz", which is a mistery for me at this time.

Not sure if there are only visual representation of it. This is nice for DFT: https://jackschaedler.github.io/circles ... ction.html

Somethings like this for understand Filters would be amazing.

Post

Nowhk wrote: ...
Not sure if there are only visual representation of it. This is nice for DFT: https://jackschaedler.github.io/circles ... ction.html

Somethings like this for understand Filters would be amazing.
Maybe http://demonstrations.wolfram.com/Digit ... sAndZeros/

Cycling '74 Max bundle include nice design tool - https://cycling74.com/
IIRC, if you get the runtime version of Max (5, 6?) you should be able to use the project file w/o limits.

Post

bewildering.... glad i stepped in.....


a one pole filter of this nature (linear interpolation) does not have a variable slope or anything like that. it's a simple, low power filter used for rudimentary tasks such as removing dc.

the dsp document on the sem page of my website includes code similar to one of your examples above, but there is something these nice people have not discussed with you.

as you are aware, frequency is logarithmic, so for a *meaningful* parameter, you want it to convert its value via a pow(2, slider) kinda function.

see how everybody in the universe is an enemy, even though they seem friendly? it's because this business eats people alive :)

here's how a total fuckwit does it:

itfp, this algorithm was adapted from the code in the synthedit sdk, because jeff is a nice person, when people aren't trying to shut him out of the industry and thereby silence any possible effort for democratisation of a highly lucrative and memetically pertinent field:

say your slider outputs 0 to 1.

for synthedit sliders, we center the slider at 440hz (5v it you ever use synthedit)

over a 10 octave range. so that's 440/32 = 13.75hz to 440*32 = 14080hz

of course, if you're not worried about centering precisely at 440, 10 octaves is a multiple of 1024, so you could eg. do 20hz to 20480hz, or to 19.53hz to 20000hz.



anyway - the actual filter coefficient for your linear interpolation filter there (to locate the desired frequency at -3dB) is

coefficient = pow(2.f, inputslider * 10.f) * cutoffscalar;

where
cutoffscalar = 2 * pi * 13.75 / samplerate;


as you have read several places, the cutoff for such a filter is simply 2 * pi * cutoff / samplerate

using 13.75 (440/32, or down five octaves) simply is convenient for reducing calculations during the cutoff modulation.




somewhere on this place you'll fine a bilinear interpolation version of this filter by neotec, which has a more complex calculation similar to the ones other people are mentioning. you don't really need to bother with it unless your filter is in some critical location where phase matters (eg. inside a precisely tuned delay line, where the slight phase modification of the filter will slightly detune the delay- even then, the phase of this filter form can be calculated and subtracted form the delay length).
you come and go, you come and go. amitabha neither a follower nor a leader be tagore "where roads are made i lose my way" where there is certainty, consideration is absent.

Post

xoxos, did you read the first page? Scaling by octave is described there. The op was actually more interested in deriving coefficients than control scaling it turns out

Post

You could also implement a 2nd order IIR LP filter which has response of 1st order filter. Here's one way to do it using MZT (C++).

Code: Select all

// FM emphasis filter
double Fs = 44100; // higher sample rate results better filter accuracy 
double Fc = 2122.0;
double T1 = 1/(2*pi*Fc); // Hz to time constant

double p1 = -exp(-1.0/(Fs*T1));
double z1 = 1 + z1;

a0 = 1.0;
a1 = p1;
a2 = 0;

b0 = 1.0;
b1 = z1;
b2 = 0; 

// swap between a1, b1 to select pre- or de-emphasis
Coefficients from above calculations adds about +13.63dB gain so you need to normalize before use.

Same done using Octave script:

Code: Select all

% FM emphasis filter

% PACKAGES
pkg load control
pkg load signal

clear all;
clc;

fs = 44100;
samplingtime = 1/fs;

% analog prototype
A2 = [1];
B2 = [0.000075 1];
Ds = tf(B2, A2); % swap between A2 and B2 to select pre- or de-emphasis
Ds = Ds/dcgain(Ds);

% MZT
T1 = 0.000075; % 75us
z1 = -exp(-1.0/(fs*T1));
p1 = 1+z1;

a0 = 1.0;
a1 = p1;
a2 = 0;

b0 = 1.0;
b1 = z1;
b2 = 0;

% swap between a1, b1 to select pre- or de-emphasis

Bmzt = [b0 a1 b2]
Amzt = [a0 b1 a2]

DzMZT = tf(Amzt, Bmzt, samplingtime);
DzMZT = DzMZT/dcgain(DzMZT);

%% Plot
wmin = 2 * pi * 20.0; % 20Hz
wmax = 2 * pi * ((fs/2.0) - (fs/2 - 20000)); 20kHz

figure(1);
bode(Ds, 'b', DzMZT, 'c', {wmin, wmax});
legend('Analog prototype', 'MZT 2nd order','location', 'northwest');
grid on;
Last edited by juha_p on Mon Oct 24, 2016 10:14 am, edited 1 time in total.

Post

What's the point of using a "second" order filter when the second order coefficients are null?

Post

Miles1981 wrote:What's the point of using a "second" order filter when the second order coefficients are null?
to look like the topic has been knowledgeably and comprehensively answered while bewildering the correspondent.

:party:
you come and go, you come and go. amitabha neither a follower nor a leader be tagore "where roads are made i lose my way" where there is certainty, consideration is absent.

Post

Miles1981 wrote:What's the point of using a "second" order filter when the second order coefficients are null?
I don't have those null (and don't want to share what's there) ... you sure know why not.

Post Reply

Return to “DSP and Plugin Development”