function that finds the cutoff frequency for low pass filter (in matlab)

22,659

Solution 1

You can use the bandwidth command on LTI objects (transfer functions, etc.):

G = tf(1, [1 1])
bandwidth(G)

ans =

    0.9976

Solution 2

If you don't have the Control System Toolbox you can do it like that:

% some filter
[b, a] = butter(5, 0.6);

% Determine frequency response
[h, w] = freqz(b, a, 2048);

% linear approximation of 3 dB cutoff frequency
ind = find(abs(h) < sqrt(1/2), 1, 'first');
slope = (abs(h(ind)) - abs(h(ind - 1))) / (w(ind) - w(ind - 1));
w_3dB = ( sqrt(1/2) - abs(h(ind - 1)) + slope * w(ind - 1) ) / slope;

% check result
figure; plot(w,abs(h))
hold on;
plot(w_3dB, sqrt(1/2), 'rx');

Addmitedly, you'll need the DSP Toolbox for freqz().

Share:
22,659
user1564762
Author by

user1564762

Updated on November 29, 2020

Comments

  • user1564762
    user1564762 over 3 years

    I want to find the cutoff frequency for a lot of low pass filters. Therefor I want a function that can do that for me. I can make a Bode plot and find the frequency for -3dB, but that is boring and time-consuming. Does someone know how I can automatic this procedure? I was trying with

    [mag,phase] = bode(sys) 
    

    but failed. How should I go about this?

    I have filter coefficients a,b available. I try to use some different technique when I discretize the transform function, therefore I want the cutoff frequency empirically from EKV:

    y_k = b(1)*x_k + b(2)*x_{k-1} – a(2)*y_{k-1}
    
  • user1564762
    user1564762 over 11 years
    Can I make bandwith(G) easily work with HP,BP,BS-filter (as it does with LP-filter)?
  • Kavka
    Kavka over 11 years
    Not directly, since the description says "...the gain drops below 70.79 percent (-3 dB) of its DC value". For example, the DC value of an HP filter is 0, so this command would not work. However, for an HP filter, 1-HP is a LP filter for which the command would work.