There are 4 cos signals with 10,20,30 and 100 Hz each. The main signal is the sum of those 4 and I have to create a low pass filter, on the main signal for the frequency's > 50 Hz.

% design of low pass filter
f = [0 0.6 0.6 1];
m = [1 1 0 0 ];
b = fir2(30, f, m);
[h, w] = freqz(b,1,128);

hold on;
plot(w/pi, abs(h), 'r')
xlabel('Normalized Frequency (\times\pi rad/sample)')
legend('Ideal', 'fir2 designed')
legend boxoff
title('comparison of frequency Response Magnitytes');
hold off;

That's the example code that our professor gave us.On maltab using help fir2 there is a similar example

% Example 1:
%   Design a 30th-order lowpass filter and overplot the desired 
%   frequency response with the actual frequency response.

f = [0 0.6 0.6 1];      % Frequency breakpoints
m = [1 1 0 0];          % Magnitude breakpoints
b = fir2(30,f,m);       % Frequency sampling-based FIR filter design
[h,w] = freqz(b,1,128); % Frequency response of filter
legend('Ideal','fir2 Designed')
title('Comparison of Frequency Response Magnitudes')

What i don't understand is how to find the frequency breakpoints and the magnitude breakpoints? Also whats the relation of the filter order with the low-high, band filters?


The samples in the 'f' vector in the Matlab Example 1 code are arbitrary, ...just an example of a lowpass filter. The purpose of that code is to merely show you how the "designed" (actual) freq response is similar to, but not equal to, the "ideal" rectangular freq response.

I don't like that Matlab Example 1 example. It's confusing to some beginners to have two different magnitude ('m') sample values associated with a single 'f' value of 0.6. A better example would define 'f' as f = [0 0.6 0.7 1].

In any case, the Example 1 example's f = [0 0.6 0.6 1] and m = [1 1 0 0], vectors specify that the lowpass filter's "ideal" passband gain is one at $0*f_s/2$ Hz and is one at $0.6*f_s/2$ Hz. (The '*' symbol means multiply.) So the "ideal" lowpass passband extends from $0*f_s/2$ -to- $0.6*f_s/2$ Hz. The code also specifies that the lowpass filter's "ideal" stopband gain is zero at $0.6*f_s/2$ Hz and is zero at $1*f_s/2$ Hz. So the "ideal" stopband extends from $0.6*f_s/2$ -to- $1*f_s/2$ Hz.

Now if you wanted the filter's "ideal" lowpass passband to extend from $0*f_s/2$ -to- $0.5*f_s/2$ Hz (zero Hz –to- $f_s/4$ Hz), you would define vector 'f' as f = [0 0.5 0.5 1].

  • $\begingroup$ Thanks i will try to make a further research on that to make things clear. $\endgroup$
    – Argiris
    Jan 15 '16 at 16:23

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.