Re: Knowledge help: How to create own filter if I know frequencyresponse?
On 24 Mar, 11:22, "fittipaldi" <em.fittipa...@abv.bg> wrote:
> I need help with the knowledge ...
>
> Let's assume I have an idea for a 1024 point filter. I know how the
> frequency response should be: all points between 100 and 924 are 0 and all
> other 1 (I think this should be a perfect low-pass (or maybe not?).
Everybody *think* this is a perfect low-pass filter,
but it isn't. It's a disaster waiting to happen.
I'll show you below.
Just out of curiosity: If it is this easy to specify
a filter, why are there so many other methods for
filter design? Window functions, with the sidelobe
ripple and transition bandwidths; Optimization methods
with all these iterative computational nuisances?
Are these method there just because somebody wanted
to sell show-off books stuffed with maths, to screw
with student's minds in exams? Or could it be that
these methods actually are there for a reason?
Just contemplate those questions for a moment.
The the problem is that your specification above only
determines the filter response in a set of points along
the frequency axis. Those points are implicitly given
by the number of points in the data vector.
Some matlab code to illustrate:
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%%%%
N =32; % The number of samples in filter
H = zeros(N,1);
H(1:5) = 1;
H(end-3:end)=1; % 'Ideal' frequency response
w = (0:N-1)/N; % Frequency vector
clf
subplot(2,1,1)
stem(w,H,'b'),hold on % Plot the spec
title('Spectra')
h = fftshift(real(ifft(H)));
% Compute impulse response of filter
subplot(2,1,2)
stem(h,'b'),hold on % Plot impulse response
title('Impulse responses')
% At this point all looks well. The DFT of the filter
% looks like what you want, and you have got a FIR
% impulse response you can use.
% Let's see what happens if you apply the filter to
% a data set with a different number of samples.
h1 = [h; 0; 0 ;0]; % Append 3 samples to the FIR
stem(h1,'r') % Plot it ontop of the original,
% No difference in time domain
H1 = abs(fft(h1)); % Compute DFT of new filter
w1 = (0:length(H1)-1)/length(H1);
% and corresponding frequency
% vector
subplot(2,1,1)
stem(w1,H1,'r') % plot on top of original
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%%%%
The DFT of the zero-padded filter doesn't quite look
like what you expected, right?
This is why your way of specifying the filter response
is a bad one. The usual methods specify responses in
bands, not points, so with them you control ripple in
the various bands. Stick with the usual methods and you
get no surprises like this.
Rune
|