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