%% Lowpass Filter Design with Weighted Fit
% Design an FIR lowpass filter. The passband ranges from DC to 0.45\pi rad/sample. The stopband ranges from 0.55\pi rad/sample to the Nyquist frequency. Produce three different designs, changing the weights of the bands in the least-squares fit.
% In the first design, make the stopband weight higher than the passband weight by a factor of 100. Use this specification when it is critical that the magnitude response in the stopband is flat and close to 0. The passband ripple is about 100 times higher than the stopband ripple.

bhi = firls(18,[0 0.45 0.55 1],[1 1 0 0],[1 100]);

%
% In the second design, reverse the weights so that the passband weight is 100 times the stopband weight. Use this specification when it is critical that the magnitude response in the passband is flat and close to 1. The stopband ripple is about 100 times higher than the passband ripple.

blo = firls(18,[0 0.45 0.55 1],[1 1 0 0],[100 1]);

%
% In the third design, give the same weight to both bands. The result is a filter with similar ripple in the passband and the stopband.

b = firls(18,[0 0.45 0.55 1],[1 1 0 0],[1 1]);

%
% Visualize the magnitude responses of the three filters.

hfvt = fvtool(bhi,1,blo,1,b,1,'MagnitudeDisplay','Zero-phase');
legend(hfvt,'bhi: w = [1 100]','blo: w = [100 1]','b: w = [1 1]')

% Copyright 2015 The MathWorks, Inc.