%% Lowpass Filtering using Two Allpass Filters
% *Note*: This example runs only in R2016b or later. If you are using an earlier 
% release, replace each call to the function with the equivalent |step| syntax. 
% For example, myObject(x) becomes step(myObject,x).
% 
% Construct the Allpass Filters

Fs  = 48000;    % in Hz
FL = 1024;
APF1 = dsp.AllpassFilter('AllpassCoefficients',...
    [-0.710525516540603   0.208818210000029]);
APF2 =  dsp.AllpassFilter('AllpassCoefficients',...
    [-0.940456403667957   0.6;...
    -0.324919696232907   0],...
    'TrailingFirstOrderSection',true);
%% 
% Construct the Transfer Function Estimator to estimate the transfer function 
% between the random input and the Allpass filtered output
%%
TFE = dsp.TransferFunctionEstimator('FrequencyRange',...
    'onesided','SpectralAverages',2);
%% 
% Construct the ArrayPlot to plot the magnitude response
%%
AP = dsp.ArrayPlot('PlotType','Line','YLimits', [-80 5],...
    'YLabel','Magnitude (dB)','SampleIncrement', Fs/FL,...
    'XLabel','Frequency (Hz)','Title','Magnitude Response',...
    'ShowLegend', true,'ChannelNames',{'Magnitude Response'});
%% 
% Filter the Input and show the magnitude response of the estimated transfer 
% function between the input and the filtered output
%%
tic;
while toc < 5
    in  = randn(FL,1);
    out = 0.5.*(APF1(in) + APF2(in));
    A = TFE(in, out);
    AP(db(A));
end

%% 
% Copyright 2012 The MathWorks, Inc.