%% Transform Lowpass Filter to Highpass Filter
% This example transforms an IIR filter from lowpass to highpass by moving the magnitude response at one frequency in the source filter to a new location in the transformed filter.
% Generate a least P-norm optimal IIR lowpass filter with varying attenuation levels in the stopband. Specify a numerator order of 10 and a denominator order of 6. Visualize the magnitude response of the filter.

[b,a] = iirlpnorm(10,6,[0 0.0175 0.02 0.0215 0.025 1], ...
    [0 0.0175 0.02 0.0215 0.025 1],[1 1 0 0 0 0], ...
    [1 1 1 1 20 20]);

fvtool(b,a)

% To generate a highpass filter whose passband flattens out at 0.4π rad/sample, select the frequency in the lowpass filter at 0.0175π, the frequency where the passband starts to roll off, and move it to the new location. Compare the magnitude responses of the filters using FVTool.
%

wc = 0.0175;
wd = 0.4;
[num,den] = iirlp2hp(b,a,wc,wd);

hvft = fvtool(b,a,num,den);
legend(hvft,'Prototype','Target')

% The transition band for the highpass filter is essentially the mirror image of the transition for the lowpass filter from 0.0175π to 0.025π, stretched out over a wider frequency range. In the passbands, the filter share common ripple characteristics and magnitude.
% Copyright 2012 The MathWorks, Inc.