Using Matlab, I need some way to automatically find the point where an arbitrary filter response crosses a threshold. For example, given a low pass filter, use freqz to find the response, then find the frequency that where the magnitude most closely corresponds to -3dB. If the response never exactly hits -3dB, interpolation might be nice, but not really necessary as I can generate enough points in the frequency response to make the error negligibly small. I would think this could be done with some sort of table lookup function if there is such a thing. Does anyone know if there are any built-in functions to help with this? Or should I just use a brute-force approach with a "for" loop looking for the value? -- Jon Harris SPAM blocked e-mail address in use. Replace the ANIMAL with 7 to reply.
Matlab lookup table?
Started by ●November 13, 2003
Reply by ●November 13, 20032003-11-13
Hello Jon, A classic way to do this is inverse interpolation. Just sample the filter's frequency response at a bunch of points (spanning your desired point of interest) creating f(w) and w pairs. Now feed these to your favorite interpolation routine but with the f(w) and w values swapped. Now just feed your desired f(w) value into the interpolator and out will pop the corresponding w. The interpolation routine can be either a polynomial type (I.e., Lagrange, Chebyshev, etc.) or a spline type (cubic, B, etc.). Matlab should have some basic interpolation functions built in. For the case of low polynomial order, you can directly do inverse interpolation with either linear or quadratic forms. Clay "Jon Harris" <goldentully@hotmail.com> wrote in message news:bp0nmh$1j70et$1@ID-210375.news.uni-berlin.de...> Using Matlab, I need some way to automatically find the point where an > arbitrary filter response crosses a threshold. For example, given a low > pass filter, use freqz to find the response, then find the frequency that > where the magnitude most closely corresponds to -3dB. If the responsenever> exactly hits -3dB, interpolation might be nice, but not really necessaryas> I can generate enough points in the frequency response to make the error > negligibly small. I would think this could be done with some sort oftable> lookup function if there is such a thing. > > Does anyone know if there are any built-in functions to help with this?Or> should I just use a brute-force approach with a "for" loop looking for the > value? > > -- > Jon Harris > SPAM blocked e-mail address in use. Replace the ANIMAL with 7 to reply. > >
Reply by ●November 13, 20032003-11-13
Jon Harris wrote:> > Using Matlab, I need some way to automatically find the point where an > arbitrary filter response crosses a threshold. For example, given a low > pass filter, use freqz to find the response, then find the frequency that > where the magnitude most closely corresponds to -3dB.You just have to solve the polynomial |H(Z)| = 1/sqrt(2). Any numeric method will jump on solution after several iterations.> Does anyone know if there are any built-in functions to help with this? Or > should I just use a brute-force approach with a "for" loop looking for the > value?Use any of standard methods for solving equations. Vladimir Vassilevsky DSP and Mixed Signal Design Consultant http://www.abvolt.com
Reply by ●November 13, 20032003-11-13
On Thu, 13 Nov 2003 12:02:42 -0800, "Jon Harris" <goldentully@hotmail.com> wrote:>Using Matlab, I need some way to automatically find the point where an >arbitrary filter response crosses a threshold. For example, given a low >pass filter, use freqz to find the response, then find the frequency that >where the magnitude most closely corresponds to -3dB. If the response never >exactly hits -3dB, interpolation might be nice, but not really necessary as >I can generate enough points in the frequency response to make the error >negligibly small. I would think this could be done with some sort of table >lookup function if there is such a thing. > >Does anyone know if there are any built-in functions to help with this? Or >should I just use a brute-force approach with a "for" loop looking for the >value? > >-- >Jon HarrisHi John, If I understand your problem, maybe the following MATLAB code will help. If you have the A & B coefficients of your lowpass filter: [H,W] = freqz(B,A,N) Hmag = abs(H); % get the magnitude response Hmag = 20*log10(Hmag/max(Hmag)); % Log with 0 dB being largest I = find(Hmag<-3); % Find indices beyond end of passband Wcutoff = W(min(I)); % Here's the lowpass -3 dB cutoff freq Make N as large as you like. The higher N, the better freq resolution you'll have in estimating the filter's -3 dB cutoff freq. Good Luck, [-Rick-]
Reply by ●November 13, 20032003-11-13
Jon Harris wrote:> Using Matlab, I need some way to automatically find the point where an > arbitrary filter response crosses a threshold. For example, given a low > pass filter, use freqz to find the response, then find the frequency that > where the magnitude most closely corresponds to -3dB. If the response never > exactly hits -3dB, interpolation might be nice, but not really necessary as > I can generate enough points in the frequency response to make the error > negligibly small. I would think this could be done with some sort of table > lookup function if there is such a thing. > > Does anyone know if there are any built-in functions to help with this? Or > should I just use a brute-force approach with a "for" loop looking for the > value? > > -- > Jon Harris > SPAM blocked e-mail address in use. Replace the ANIMAL with 7 to reply. > >something like this I think would give you the index in x where the value is closest to 3 find(abs(x-3) == min(abs(x-3))) -Lasse
Reply by ●November 13, 20032003-11-13
Thanks Rick. The "find" function was what I was looking for. Thanks also to the rest of you who had good suggestions as well. "Rick Lyons" <ricklyon@REMOVE.onemain.com> wrote in message news:3fb404fd.48741156@news.west.earthlink.net...> On Thu, 13 Nov 2003 12:02:42 -0800, "Jon Harris" > <goldentully@hotmail.com> wrote: > > >Using Matlab, I need some way to automatically find the point where an > >arbitrary filter response crosses a threshold. For example, given a low > >pass filter, use freqz to find the response, then find the frequency that > >where the magnitude most closely corresponds to -3dB. If the responsenever> >exactly hits -3dB, interpolation might be nice, but not really necessaryas> >I can generate enough points in the frequency response to make the error > >negligibly small. I would think this could be done with some sort oftable> >lookup function if there is such a thing. > > > >Does anyone know if there are any built-in functions to help with this?Or> >should I just use a brute-force approach with a "for" loop looking forthe> >value? > > > >-- > >Jon Harris > > Hi John, > If I understand your problem, maybe the > following MATLAB code will help. If you have > the A & B coefficients of your lowpass filter: > > > [H,W] = freqz(B,A,N) > Hmag = abs(H); % get the magnitude response > Hmag = 20*log10(Hmag/max(Hmag)); % Log with 0 dB being largest > I = find(Hmag<-3); % Find indices beyond end of passband > Wcutoff = W(min(I)); % Here's the lowpass -3 dB cutoff freq > > Make N as large as you like. The higher N, the > better freq resolution you'll have in estimating > the filter's -3 dB cutoff freq. > > Good Luck, > [-Rick-] > >
Reply by ●November 13, 20032003-11-13
Not sure if this answers your question, I may have misunderstood what you where trying to do? b=[0.5263 0.4211 0.0526]; % define arbitrary filter a=1; N=100; % num points [h,w]=freqz(b,a,N); % generate mag and phase logh = 20*log10(abs(h)); % in logs plot(w,logh) % lets make sure we have something sensible now you want to find the point on the graph where it crosses -3dB yeah? val = -3; % this is the value that you want to get close to index=find(logh<val); % find the indices of all elements in the vector larger than our value logh(index(1)), w(index(1)) % use the point where it first crosses our threshold et voila! you can use the find function for all sorts of things, i mean if the freq response decides it wants to come back up and hang aroud the 3 db mark as the freq increases, then you'll have to do something clever to find all the points that the logh vector crosses the -3db mark, or gets within X% of the -3db point. As far as that code goes, if you know that it only crosses -3dB one time, then you can take the point either side of the crossing and perform the interpolation that you mentioned. All the best. col "Jon Harris" <goldentully@hotmail.com> wrote in message news:<bp0nmh$1j70et$1@ID-210375.news.uni-berlin.de>...> Using Matlab, I need some way to automatically find the point where an > arbitrary filter response crosses a threshold. For example, given a low > pass filter, use freqz to find the response, then find the frequency that > where the magnitude most closely corresponds to -3dB. If the response never > exactly hits -3dB, interpolation might be nice, but not really necessary as > I can generate enough points in the frequency response to make the error > negligibly small. I would think this could be done with some sort of table > lookup function if there is such a thing. > > Does anyone know if there are any built-in functions to help with this? Or > should I just use a brute-force approach with a "for" loop looking for the > value?