DSPRelated.com
Forums

Polyphase decimating filter - not working - why?

Started by Tamara February 1, 2007
"dbd" <dbd@ieee.org> writes:
> [...] > 1) Use a sinc instead of remez waveform if you choose > to create windowed filter coefficients.
I consider this bad advice. One should not choose a filtering method based on whether or not they want to window. Rather, they should choose the filtering method based on their needs and available tools, then window *if required*. Since Tamara has Matlab, and remez is going to create a much better filter than a windowed sinc, I don't think we should be encouraging her to use windowed sincs. Tamara - simply take the windowing off your remez coefficients. That's your best bet. -- % Randy Yates % "The dreamer, the unwoken fool - %% Fuquay-Varina, NC % in dreams, no pain will kiss the brow..." %%% 919-577-9882 % %%%% <yates@ieee.org> % 'Eldorado Overture', *Eldorado*, ELO http://home.earthlink.net/~yatescr
>Hi Tamara, > >Who told you that windowing improves these things? It actually >degrades rather than improves them.
Hi Randy.... This is a learning process for me. Everything I write here is so that you can see my thought process. I did a lot of reading on digital filters. Every book I read says to apply a window to reduce ripple due to Gibbs' phenomenom. Page 176 - Richard Lyons - Understanding Digital Signal Processing. "We can minimize FIR passband ripple with window functions the same way we minimized DFT leakage".
>You still have the windowing in - take it out and see what you get.
I did take the window out and I still have the same problem. The window is included in the matlab code so that I could compare graphically the windowed versus non-windowed versions - sorry that I did not explain this.
>Here is my Matlab code.. >> >> [n,fo,mo,w] = remezord([20 23.2],[1 0],[.00001 .1],100); >> h=remez(n,fo,mo); >> b = 14; >> h = h(:); >> scale1 = h/max(abs(h)); >> scale1 = scale*0.90; >> h_quant = floor(scale1*((2^(b-1))-1)); >> h_quant = h_quant(:); >> freqz(h_quant)
This is the plot of the non windowed filter !!!! Really poor of me to not include comments nor labels.
>> figure >> w = blackmanharris(n+1); >> hh = h.*w; >> scale2 = hh/max(abs(hh)); >> scale2 = scale2*0.90; >> h1_quant = floor(scale2*((2^(b-1))-1)); >> h1_quant = h1_quant(:); >> subplot(2,1,2); >> freqz(h1_quant)
This is a plot of the windowed filter !!!! (NOTE: If anyone would like the coefficient or comparison matlab plot - I can send them via e-mail - thall@naic.edu ) #1. I need a filter with the lowest passband ripple and highest stopband attenuation - I'm not to worried about transition bandwidth as long as I can meet nyquist. It looks like to me from the Matlab comparison ( zooming in ) that the windowed filter does just that. So where did I go wrong? Is Matlab not a good tool? #2. I still have my initial problem when removing the window. It seems to be a seperate problem because with my same testbench - using a Xilinx Coregen filter that using my same coefficients works fine. I look forward to your response. In the mean time I'm reading up on the Remez function and your Fixed-point arithmetic paper. BTW, the rose is NOT as beautiful :-) Tamara
Hello Srikanth.  Thanks for your response.

1./2.I switched to remezord when I realized not everyone has the same
version of matlab as me.  Remezord is obsolete and will be removed later. 


3.  Read my last post.

4.  I'm scaling to avoid overflow/underflow - I got this trick from f.
Harris multirate book.  Altough I'm not sure how to calculate the scaling
factor ??  I'm blindly going though this.  

> > i think there is a better way in calculating the filter taps > > 1. use remezord to calculate the order of the filter rather than >firpmord > and in the remezord mention the pass band attenuation and the > stopband ripple properly > 2. use the order returned by "remezord" function to calculate the > coefficients using "remez" function > 3. no need to window the coefficients that come as output from step 2 > 4. i dont think u need to do scaling also (not sure....) > >regards, >srikanth konjeti
On Feb 6, 6:37 am, Randy Yates <y...@ieee.org> wrote:
> "dbd" <d...@ieee.org> writes: > > [...] > > 1) Use a sinc instead of remez waveform if you choose > > to create windowed filter coefficients. >>[...] >>4) If you use a good remez designed filter you do not need a >>windowed filter design.
> > I consider this bad advice. One should not choose a filtering method > based on whether or not they want to window. Rather, they should > choose the filtering method based on their needs and available tools, > then window *if required*. >
Randy, I didn't give advice either way. I just thought that when there are (at least) two techniques, they should be described correctly. Item 4). shows we agree that the two approaches shouldn't be mixed. I think people are more likely to succeed if they understand the choices they have available. All I interjected was a correction to a confusing misrepresentation of one choice.
> Tamara - simply take the windowing off your remez coefficients. > That's your best bet. > -- > % Randy Yates % "The dreamer, the unwoken fool -
Dale B. Dalrymple http://dbdimages.com
A little update. 

I put in hooks into the VHDL code to check for overflow of each of the MAC
operations( positive and negative directions).  There is no overflow
detected.  

Tamara... 
Tamara wrote:
> Hello. I have used all this valuable feedback, tested and I still have the > same problem.... I'm curious to know why everyone suggests not to window - > I'm windowing with Blackman to minimize passband ripple, have better > stop-band attenuation and group delay. ...
Some people think that if a little bit is good, more must be better. That doesn't work with salt, and it doesn't work with windows. One way to design a low-pass filter makes use of a sinc function; the inverse Fourier transform of an ideal filter. A sinc has infinite extent, and so must be truncated. The truncation introduces ripple and ringing; a window can reduce those artifacts. The window degrades some other aspects of th filter, but engineering, like life, involves trade-offs. Applying the same window twice won't reduce the artifacts more, but it will increase the degradation. Remez(n,fo,mo) returns the coefficients of an optimized filter. Never mind the process, the result is the same as a sinc windowed with a window custom designed for that particular filter. It is already optimum. Windowing it again will only mess it up. Jerry -- Engineering is the art of making what you want from things you can get. &macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;
"Tamara" <thall@naic.edu> writes:

>>Hi Tamara, >> >>Who told you that windowing improves these things? It actually >>degrades rather than improves them. > > Hi Randy.... This is a learning process for me. Everything I write here > is so that you can see my thought process.
Hi Tamara, Hey, we're all still learning until we're toes-up. I didn't intend to be smart with you - just asking a question. I apologize if my wording conveyed an unfriendly attitude - that wasn't my intention. (Many people say I should go to charm school, but I err on the side of just saying plainly what needs to be said.)
> I did a lot of reading on digital filters. Every book I read says > to apply a window to reduce ripple due to Gibbs' phenomenom.
Right, and why do you think Gibb's phenomenom is present in a remez-designed filter? Rather, Gibbs phenomenom happens when you truncate a series or function. For example, when the ideal, theoretical brick-wall filter, which is a sinc(W*t) function in the time domain, is hacked off at some finite extent, say, after +/- T. The remez algorithm will produce a set of coefficients, an impulse response, that is not truncated - they generate the desired response as is, thus there is no need to window it.
> Page 176 - Richard Lyons - Understanding Digital Signal Processing. "We > can minimize FIR passband ripple with window functions the same way we > minimized DFT leakage".
Yes, but look at where that section is in context. Chapter 5 is FIR filters. Section 5.3 is lowpass filters, and section 5.3.1 is "Window Design Method," where Rick describes the ripple problem with truncating a sinc() and discusses how windowing can be used to reduce it. Section 5.3.2 is on the windows themselves, but they were meant to be applied in the case of filters which use the "Window Design Method." I suggest you read section 5.3.1.
>>You still have the windowing in - take it out and see what you get. > > I did take the window out and I still have the same problem. The window > is included in the matlab code so that I could compare graphically the > windowed versus non-windowed versions - sorry that I did not explain this.
OK, well... hmmm. Then your problem is not in the filter design itself.
>>Here is my Matlab code.. >>> >>> [n,fo,mo,w] = remezord([20 23.2],[1 0],[.00001 .1],100); >>> h=remez(n,fo,mo); >>> b = 14; >>> h = h(:); >>> scale1 = h/max(abs(h)); >>> scale1 = scale*0.90; >>> h_quant = floor(scale1*((2^(b-1))-1)); >>> h_quant = h_quant(:); >>> freqz(h_quant) > > This is the plot of the non windowed filter !!!! Really poor of me to not > include comments nor labels.
Not a problem for anyone even slightly familiar with Matlab.
>>> figure >>> w = blackmanharris(n+1); >>> hh = h.*w; >>> scale2 = hh/max(abs(hh)); >>> scale2 = scale2*0.90; >>> h1_quant = floor(scale2*((2^(b-1))-1)); >>> h1_quant = h1_quant(:); >>> subplot(2,1,2); >>> freqz(h1_quant) > > This is a plot of the windowed filter !!!! > (NOTE: If anyone would like the coefficient or comparison matlab plot - I > can send them via e-mail - thall@naic.edu ) > > #1. I need a filter with the lowest passband ripple and highest stopband > attenuation - I'm not to worried about transition bandwidth as long as I > can meet nyquist. It looks like to me from the Matlab comparison ( > zooming in ) that the windowed filter does just that. So where did I go > wrong? Is Matlab not a good tool? > > #2. I still have my initial problem when removing the window. It seems to > be a seperate problem because with my same testbench - using a Xilinx > Coregen filter that using my same coefficients works fine. > > I look forward to your response.
Well, thanks, but I'm not sure I'm helping you get your problem solved. It sounds to me, Tamara, that you've got something totally different going on that's causing this. Here's a couple ideas: 1. Have you checked the analog signal at the input to the A/D at the 35 MHz frequency that is causing the problem to see if perhaps there is something in the analog chain generating a spur at 17 MHz? 2. Maybe there are errors in the VHDL implementation that are causing this. Did you write a testbench and run test vectors against the code? 3. Where are you measuring the output at? Are you taking the digital data out of the decimator? Or are you converting that back into analog and using a spectrum analyzer? If the latter, then maybe there's something wrong in the D/A conversion. Can't think of anything else right now. It's pretty hard to try to debug something through usenet.
> [...] > BTW, the rose is NOT as beautiful :-)
She is the love of my life! -- % Randy Yates % "How's life on earth? %% Fuquay-Varina, NC % ... What is it worth?" %%% 919-577-9882 % 'Mission (A World Record)', %%%% <yates@ieee.org> % *A New World Record*, ELO http://home.earthlink.net/~yatescr
Well, thanks to everyone for your help.  Especially Randy and Jerry.  I
definately have gained a lot from this post.  As for my problem - I will
work on it some more and post when I figure it out.  It's sooo painful
because I have done the math, the timing - the code looks good.  I do have
a testbench - and have verified it with the Xilinx decimating core.  

Best of luck and BTW - I didn't take any comment as unfriendly....   

Tamara....


On Tue, 06 Feb 2007 11:58:04 -0600, "Tamara" <thall@naic.edu> wrote:

> >>Hi Tamara,
Hi Tamara, I'd better stick my nose in this thread.
>>Who told you that windowing improves these things? It actually >>degrades rather than improves them. > >Hi Randy.... This is a learning process for me. Everything I write here >is so that you can see my thought process. I did a lot of reading on >digital filters. Every book I read says to apply a window to reduce >ripple due to Gibbs' phenomenom. > >Page 176 - Richard Lyons - Understanding Digital Signal Processing. "We >can minimize FIR passband ripple with window functions the same way we >minimized DFT leakage".
Well, ... I didn't say you "should" apply a window, I said you "can" apply a window sequence to your coefficients. Then at the bottom of the page I warned that while windowing the coefficients will flatten (smooth) the filter's passband ripple, it will degrade (make wider) the filter's passband-to-stopband transition region. (Randy's convolution description explained why this happens.)
>>You still have the windowing in - take it out and see what you get. > >I did take the window out and I still have the same problem. The window >is included in the matlab code so that I could compare graphically the >windowed versus non-windowed versions - sorry that I did not explain this. > > >>Here is my Matlab code.. >>> >>> [n,fo,mo,w] = remezord([20 23.2],[1 0],[.00001 .1],100); >>> h=remez(n,fo,mo);
(snipped) Your code didn't run because you had an undefined "scale" variable. If you set that "scale" variable to "scale1" then your code runs. Tamara, I played around a little bit with designing a tapped-delay line FIR filter. My design yields a filter with less than half the number of coefficients as your code. (Have a look at my code.) Tamara, read the "remez()" command instructions on what is the purpose of the "Weight" vector. (You can change the value in that vector and see what happens.) In any case, your filter and my filter should both work OK. If you're seeing some sort of spectral wrapping, or whatever, then somehow you're not "implementing" your filter properly. The filter coefficients are not causing your trouble---your problem is somewhere in how you actually use those coeffs to perform filtering. Good Luck, [-Rick-] My code is: clear % Added by Lyons %[n,fo,mo,w] = remezord([20 23.2],[1 0],[.00001 .1],100); %h = remez(n,fo,mo); % Code from Lyons % Design lowpass FIR using remezord() & remez() commands. Rp = 1; % Desired passband ripple in dB Rs = 30; % Desired stopband attenuation in dB Fs = 100; % Sampling frequency Freq = [20, 23.2]; % End of passband & start of stopband Mag = [1,0]; % Desired magnitudes % Compute deviations vector needed by the remezord() command. Dev = [(10^(Rp/20)-1)/(10^(Rp/20)+1),10^(-Rs/20)]; [n,Freq,Mag,Weight] = remezord(Freq,Mag,Dev,Fs); Weight = Weight h = remez(n,Freq,Mag,Weight); b = 14; h = h(:); scale1 = h/max(abs(h)); scale1 = scale1*0.90; % Modified by Lyons to make code run h_quant = floor(scale1*((2^(b-1))-1)); h_quant = h_quant(:); %%%%%%%%%%%%%%%%%%%%%%%%%%%% % Plot the coeffs %%%%%%%%%%%%%%%%%%%%%%%%%%%%% figure (1), clf % Added by Lyons plot(h,'-g') % Added by Lyons hold on plot(h_quant, '-b') %%%%%%%%%%%%%%%%%%%%%%%%%%%% % Analyze the unwindowed-coeff filter %%%%%%%%%%%%%%%%%%%%%%%%%%%%% [H,W] = freqz(h_quant); % Modified by Lyons Hmag = abs(H); % Added by Lyons Hmag_dB = 20*log10(Hmag/max(Hmag )); % Added by Lyons figure (3), clf % Modified by Lyons subplot(2,1,1) % Added by Lyons plot(W/(2*pi), Hmag_dB, '-b') % Added by Lyons %%%%%%%%%%%%%%%%%%%%%%%%%%%% % Now window the coeffs & analyze %%%%%%%%%%%%%%%%%%%%%%%%%%%%% w = blackmanharris(n+1); hh = h.*w; scale2 = hh/max(abs(hh)); scale2 = scale2*0.90; h1_quant = floor(scale2*((2^(b-1))-1)); h1_quant = h1_quant(:); figure (1) % Added by Lyons plot(h1_quant, '-r') hold off title('h = green, h-quant = blue, h1-quant = red ') grid on, zoom on % Added by Lyons %subplot(2,1,2); % Commented out by Lyons [H1,W] = freqz(h1_quant); % Modified by Lyons H1mag = abs(H1); % Added by Lyons H1mag_dB = 20*log10(H1mag/max(H1mag )); % Added by Lyons figure(3) % Added by Lyons subplot(2,1,1) % Added by Lyons hold on plot(W/(2*pi), H1mag_dB, '-r') hold off subplot(2,1,1) % Added by Lyons hold on plot(W/(2*pi), H1mag_dB, '-r') hold off title('Unwindowed = blue, Windowed = red ') grid on, zoom on % Added by Lyons %%%%%%%%%%%%%%%%%%%%%%%%%%%% % Zoom in on the passband %%%%%%%%%%%%%%%%%%%%%%%%%%%%% PR = 1:230; % Plot Range subplot(2,1,2) % Added by Lyons plot(W(PR)/(2*pi), Hmag_dB(PR), '-b') % Added by Lyons hold on plot(W(PR)/(2*pi), H1mag_dB(PR), '-r') hold off title('Unwindowed = blue, Windowed = red ') grid on, zoom on % Added by Lyons