Hi, I'm trying to optimize the coefficients of a filter in Matlab. I have the code that generates zillions of H(z) for various quantization level of coefficients etc...Now I would like the same script to tell me which ones of those filters still meet my specification (passband and stopband attenuation etc...). I usually use fvtool(H) to eyeball the frequency response, but now that I have so many to look at, this doesn't make sense anymore. I then started to play with freqz(H) and writing some code to go through the magnitude response array. This somewhat works, but would still requires a lot of work, unless there is an easier way. Seems like functions to do this should exist already in Matlab??? Thanks a lot, Dave
How to automatically check if a filter meets specs
Started by ●October 9, 2008
Reply by ●October 9, 20082008-10-09
On Oct 9, 10:28�am, "gretzteam" <gretzt...@yahoo.com> wrote:> Hi, > I'm trying to optimize the coefficients of a filter in Matlab. I have the > code that generates zillions of H(z) for various quantization level of > coefficients etc...Now I would like the same script to tell me which ones > of those filters still meet my specification (passband and stopband > attenuation etc...). > I usually use fvtool(H) to eyeball the frequency response, but now that I > have so many to look at, this doesn't make sense anymore. > I then started to play with freqz(H) and writing some code to go through > the magnitude response array. This somewhat works, but would still requires > a lot of work, unless there is an easier way. Seems like functions to do > this should exist already in Matlab??? > > Thanks a lot, > DaveAre you comparing specification vectors against acheived magnitude vectors? If you are doing them point by point (in a loop) instead of using vector functions, that can slow things down dramatically. Could formulate both not in dB to save some calculations (may require computing mag spectrum without freqz (using fft), if freqz gives results dB; I don't remember what units freqz outputs in, you can check). Dirk Dirk
Reply by ●October 9, 20082008-10-09
Dave, I think doing it in matlab will be slow. maybe a C program can be written to perform the checking. but since your rest of the program lies in matlab (i assume so), it might be good to do it in C-mex kind of interface to speeden it up. But zillion checks might take a lot of time. Maybe you are ok with this, as you can fire overnight runs. freqz is the right approach. Freqz output is complex vector (in linear domain). Regards Bharat Pathak Arithos Designs www.Arithos.com DSP Design Consultancy and Training Company.
Reply by ●October 9, 20082008-10-09
On Oct 9, 10:28�am, "gretzteam" <gretzt...@yahoo.com> wrote:> Hi, > I'm trying to optimize the coefficients of a filter in Matlab. I have the > code that generates zillions of H(z) for various quantization level of > coefficients etc...Now I would like the same script to tell me which ones > of those filters still meet my specification (passband and stopband > attenuation etc...). > I usually use fvtool(H) to eyeball the frequency response, but now that I > have so many to look at, this doesn't make sense anymore. > I then started to play with freqz(H) and writing some code to go through > the magnitude response array. This somewhat works, but would still requires > a lot of work, unless there is an easier way. Seems like functions to do > this should exist already in Matlab??? > > Thanks a lot, > DaveBTW, roughly how many is "zillions"? Dirk
Reply by ●October 9, 20082008-10-09
dbell wrote:> On Oct 9, 10:28 am, "gretzteam" <gretzt...@yahoo.com> wrote: >> Hi, >> I'm trying to optimize the coefficients of a filter in Matlab. I have the >> code that generates zillions of H(z) for various quantization level of >> coefficients etc...Now I would like the same script to tell me which ones >> of those filters still meet my specification (passband and stopband >> attenuation etc...). >> I usually use fvtool(H) to eyeball the frequency response, but now that I >> have so many to look at, this doesn't make sense anymore. >> I then started to play with freqz(H) and writing some code to go through >> the magnitude response array. This somewhat works, but would still requires >> a lot of work, unless there is an easier way. Seems like functions to do >> this should exist already in Matlab??? >> >> Thanks a lot, >> Dave > > BTW, roughly how many is "zillions"?A bit less than a google, I hope. jerry -- Engineering is the art of making what you want from things you can get. ����������������������������������������������������������������������� ** Posted from http://www.teranews.com **
Reply by ●October 9, 20082008-10-09
On 9 Okt, 16:28, "gretzteam" <gretzt...@yahoo.com> wrote:> Hi, > I'm trying to optimize the coefficients of a filter in Matlab. I have the > code that generates zillions of H(z) for various quantization level of > coefficients etc...Now I would like the same script to tell me which ones > of those filters still meet my specification (passband and stopband > attenuation etc...). > I usually use fvtool(H) to eyeball the frequency response, but now that I > have so many to look at, this doesn't make sense anymore. > I then started to play with freqz(H) and writing some code to go through > the magnitude response array. This somewhat works, but would still requires > a lot of work, unless there is an easier way. Seems like functions to do > this should exist already in Matlab???Probably no canned solution, but hardly difficult. I would compute the log squared magnitude of the filter frequency responses and compare them directly to the spec. You compare the actual response to the spec in both passband and stopband, and raise an alarm if the response goes outside. The only possible problem I can see is that the filter design formulas are approximate, not exact. For instance, the rule- of-thumb is that a half-power attenuation equals 3 dB. This is not quite true, the actual number is -20*log10(1/sqrt(2)) = 3.01029995663981 so even well-designed filters might go *slightly* outside the spec. But after a test-run or two I am sure you will find what tolerances to use with the alarms. Rune
Reply by ●October 10, 20082008-10-10
Hi all, Thanks for the help. Here is a little more information: Basically I can design the filter in matlab and get a good set of initial coefficients in double precision. Depending on the order, I have between 5-8 coefficients - those are equiripple IIR wave digital filters. I then want to quantize those coefficients to either powers of two, or CSD. I just realized that the problem seems simpler than I thought, since I can only concentrate on the stopband attenuation since the passband is taken care of by the structure. So now the program simply tries a bunch of filters using coefficients 'around' their closest available quantized value and I keep the one that has the 'lowest worst-stopband-attenuation' -there has to be a better term for this:) It's pretty crazy how fast the search space increases when increasing the range of local-search around each coefficients. I guess overnight runs will be needed! Dave>On 9 Okt, 16:28, "gretzteam" <gretzt...@yahoo.com> wrote: >> Hi, >> I'm trying to optimize the coefficients of a filter in Matlab. I havethe>> code that generates zillions of H(z) for various quantization level of >> coefficients etc...Now I would like the same script to tell me whichones>> of those filters still meet my specification (passband and stopband >> attenuation etc...). >> I usually use fvtool(H) to eyeball the frequency response, but now thatI>> have so many to look at, this doesn't make sense anymore. >> I then started to play with freqz(H) and writing some code to gothrough>> the magnitude response array. This somewhat works, but would stillrequires>> a lot of work, unless there is an easier way. Seems like functions todo>> this should exist already in Matlab??? > >Probably no canned solution, but hardly difficult. > >I would compute the log squared magnitude of the filter >frequency responses and compare them directly to the spec. >You compare the actual response to the spec in both passband >and stopband, and raise an alarm if the response goes outside. > >The only possible problem I can see is that the filter design >formulas are approximate, not exact. For instance, the rule- >of-thumb is that a half-power attenuation equals 3 dB. This >is not quite true, the actual number is > > -20*log10(1/sqrt(2)) = 3.01029995663981 > >so even well-designed filters might go *slightly* outside >the spec. But after a test-run or two I am sure you will >find what tolerances to use with the alarms. > >Rune >