DSPRelated.com
Forums

Filter design with 'freqsamp' method?

Started by Pete Fraser June 30, 2010
"Tim Wescott" <tim@seemywebsite.com> wrote in message 
news:26Odnbyf_5N1YrbRnZ2dnUVZ_gadnZ2d@web-ster.com...

> Make a vector that "draws" the frequency response that you want, then take > its FFT.
That's typically how I have done it in the past (well, DFT anyway). It's just that I'm new to Matlab, trying to learn it, and assumed that was what freqsamp was supposed to do.
On 7/1/2010 12:17 AM, Pete Fraser wrote:
> "Jerry Avins"<jya@ieee.org> wrote in message > news:BdTWn.3387$OU6.1391@newsfe20.iad... > >> What is so good about a Butterworth amplitude response that you want to >> imitate it? > > Nothing. > It's just that, under some circumstances, equipment that is > later in the signal chain expects a Butterworth response.
Usually, that includes the Butterworth phase response. If magnitude alone is enough, I suspect that it's just window dressing. YMMV Jerry -- Engineering is the art of making what you want from things you can get. &#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;
Pete Fraser wrote:
> I'm new to Matlab, so this is probably a really dumb question. > I'm trying to design an FIR where I can set the points. > I want a symmetric FIR. > I'm assuming that an N tap FIR gives me N/2 degrees of freedom > for an even number of taps, and (N + 1)/2 degrees of freedom > for an odd number of taps. > This should allow me to set the frequency response at a > number of points equal to the degrees of freedom, and > have the frequency response travel through these points > exactly. If I don't specify transitions that are too sharp > relative to the number of taps, then the frequency response > should be reasonably well controlled between the set points. > > I had assumed that I could use the filter toolbox's freqsamp > method to do this, but it doesn't seem to work as I expected. > What am I doing wrong? I'd normally do this in Mathematica > or C, but I'm trying to get into the spirit of Matlab. > > I would want to solve the point setting problem anyway, but > perhaps there's an easier way to do the immediate task that > I wanted it for. I want to implement a Butterworth amplitude > response in an FIR filter (to emulate some legacy equipment) > but I can't find an easy way of doing that in Matlab (hence the > point setting experiments). > > Thanks > > Pete > >
Hi Pete! How have you been? Well, I looked into it a bit and found that I'm pretty far removed from the filter design toolbox / notation, etc. What have you done so far? any code samples? What were the results? Maybe that will get me going further. Fred
robert bristow-johnson wrote:
> On Jun 30, 10:39 pm, Tim Wescott <t...@seemywebsite.com> wrote: >> On 06/30/2010 06:21 PM, Pete Fraser wrote: >> >> >> >>> I'm new to Matlab, so this is probably a really dumb question. >>> I'm trying to design an FIR where I can set the points. >>> I want a symmetric FIR. >>> I'm assuming that an N tap FIR gives me N/2 degrees of freedom >>> for an even number of taps, and (N + 1)/2 degrees of freedom >>> for an odd number of taps. >>> This should allow me to set the frequency response at a >>> number of points equal to the degrees of freedom, and >>> have the frequency response travel through these points >>> exactly. If I don't specify transitions that are too sharp >>> relative to the number of taps, then the frequency response >>> should be reasonably well controlled between the set points. >>> I had assumed that I could use the filter toolbox's freqsamp >>> method to do this, but it doesn't seem to work as I expected. >>> What am I doing wrong? I'd normally do this in Mathematica >>> or C, but I'm trying to get into the spirit of Matlab. >>> I would want to solve the point setting problem anyway, but >>> perhaps there's an easier way to do the immediate task that >>> I wanted it for. I want to implement a Butterworth amplitude >>> response in an FIR filter (to emulate some legacy equipment) >>> but I can't find an easy way of doing that in Matlab (hence the >>> point setting experiments). >> Make a vector that "draws" the frequency response that you want, then >> take its FFT. >> >> It may not be the entirely kosher way to do it, but it certainly works. > > Pete might want to use the "window method". with an iFFT *larger* > than N, draw in the frequency response, he'll get an impulse response > that is longer than N, then window it to length N. (then maybe FFT > back to see how bad the window mangled things.) > > r b-j >
r b-j, Well, maybe I've had it wrong all these years but I'd say that the windowing method starts with N frequency samples where N is the length of the filter you want. In fact, first order, it gives you a pretty good idea of how sharp the transitions can be, etc. And, in reverse, that suggests the length of the filter you need. If you start with some higher freq resolution then you will be *more* surprised if you window down to the desired N. I'd not recommend doing it that way - but maybe there's some trick that I don't understand yet. Anyway, having selected the frequency samples [the assumption is that they are on a regular grid from 0 to Fs-1) there are a couple of options of course: 1) IFFT the samples / Window in time (i.e. not just the no-op trivial rectangular) to get rid of intersample "trillies" in frequency / FFT the result with lots of zero-padding to see what you've really got after windowing. or 2) Convolve the freq samples in frequency with the sinc-like FFT of the temporal window you have in mind to use. If the "window" function is a lot longer than the filter sample sequence then you'll also get the interpolated values between samples to see what you've really got in frequency after windowing. Fred

Pete Fraser wrote:

> "Vladimir Vassilevsky" <nospam@nowhere.com> wrote in message > news:0Jidnc3knONVbbbRnZ2dnUVZ_oSdnZ2d@giganews.com... > > >>But why would anyone want to emulate Butterworth magnitude response in a >>linear phase FIR filter whereas it is very straightforward to do the >>(**exact) Butterworth as IIR filter? > > > Butterworth will be one of several possible responses > from the same hardware. > > I'd rather not deal with Butterworth's phase issues.
Check the FDLS method of Greg Berchin. That is one of the most elegant methods of designing to a prototype. Vladimir Vassilevsky DSP and Mixed Signal Design Consultant http://www.abvolt.com
"Fred Marshall" <fmarshallx@remove_the_xacm.org> wrote in message 
news:BIednY5EMdtRg7HRnZ2dnUVZ_qmdnZ2d@centurytel.net...

> Hi Pete! How have you been?
I'm doing well thanks. Working on a couple of interesting projects.
> > Well, I looked into it a bit and found that I'm pretty far removed from > the filter design toolbox / notation, etc. > > What have you done so far? any code samples? > What were the results? > Maybe that will get me going further.
I think I'll just do it the brute force way (using Matlab), then post the code I used. Hopefully then folks can tell me how I _should_ have done it. Pete
"Vladimir Vassilevsky" <nospam@nowhere.com> wrote in message 
news:OP-dnf44bO7hJ7HRnZ2dnUVZ_t-dnZ2d@giganews.com...

> Check the FDLS method of Greg Berchin. That is one of the most elegant > methods of designing to a prototype.
Thanks. That looks like a very useful tool. I'll play with the code this morning. I'm still curious about freqsamp though. WhereGreg talks about the pseudoinverse, I had intended to give Matlab the exact number of points to correctly determine the inverse. Obviously I can do this with an explicit matrix inversion, but had assumed that freqsamp was intended to do that. Did I just assume wrong, or am I using it incorrectly? Thanks Pete
Pete Fraser <pfraser@covad.net> wrote:

>I'm still curious about freqsamp though.
Near as I can tell there is not sufficient information in the matlab documentation to state exactly (or perhaps, even generally) what they are doing here. If you're lucky someone from Mathworks will see your question and answer it for you. I believe you can also ask this on the Mathworks site, after registering. Steve
"Steve Pope" <spope33@speedymail.org> wrote in message 
news:i0ik2r$85g$2@blue.rahul.net...
> Near as I can tell there is not sufficient information in the > matlab documentation to state exactly (or perhaps, even generally) > what they are doing here.
I thought perhaps I was looking in the wrong area. The Mathworks help is a model of clarity, with lots of well-thought-out examples, but when I try to dig a little deeper I come up short.
> > If you're lucky someone from Mathworks will see your question > and answer it for you. I believe you can also ask this on the Mathworks > site, after registering.
I'll try that. Thanks.
"Vladimir Vassilevsky" <nospam@nowhere.com> wrote in message 
news:OP-dnf44bO7hJ7HRnZ2dnUVZ_t-dnZ2d@giganews.com...

> Check the FDLS method of Greg Berchin. That is one of the most elegant > methods of designing to a prototype.
I think I must be doing something dumb. I started off with a really simple half-band FIR, just as a test. The input file was: 11 100000 0 1 0 1 5000 1 -72 1 10000 1 -144 1 15000 1 -216 1 20000 1 -288 1 25000 .5 -360 1 30000 0 -432 1 35000 0 -504 1 40000 0 -576 1 45000 0 -648 1 50000 0 -720 1 N=8 D=0 delta=0 and I get B = -3.55068459956424e-018 -0.0454056666613377 2.42666919829597e-016 0.292936161872951 0.5 0.326331656363899 -2.00804673259988e-016 -0.0874864446451108 -1.76118166519034e-017 so it's doing a lot of things right. The center is 0.5, four are close to 0, but 0.29 is not 0.32, and -0.04 is not -0.08. What am I doing wrong? Thanks Pete