%% Estimate Transfer Function of a System Represented by an Order-64 FIR Filter
%
% *Note*: If you are using R2016a or an earlier release, replace each call 
% to the object with the equivalent |step| syntax. For example, |obj(x)|
% becomes  |step(obj,x)|.
%
% Generate a sine wave. Use the |dsp.TransferFunctionEstimator| System object(TM) 
% to estimate the system transfer function and the |dsp.ArrayPlot| System object 
% to display it.

sin = dsp.SineWave('Frequency',100,'SampleRate',1000);
sin.SamplesPerFrame = 1000;
tfe = dsp.TransferFunctionEstimator('FrequencyRange','centered');
aplot = dsp.ArrayPlot('PlotType','Line','XOffset',-500,'YLimits',...
        [-120 5],'YLabel','Frequency Response (dB)',...
        'XLabel','Frequency (Hz)',...
        'Title','System Transfer Function');
%% 
% Create an FIR Filter System object of order 64 and (normalized) cutoff 
% frequency of 1/4. Add random noise to the sine wave. Step through the System 
% objects to obtain the data streams, and plot the log of the magnitude of the 
% transfer function.
%%
firFilt = dsp.FIRFilter('Numerator',fir1(64,1/4));
for ii = 1:100
x = sin() + 0.05*randn(1000,1);
y = firFilt(x);
Txy = tfe(x,y);
aplot(20*log10(abs(Txy)))
end

%% 
% Copyright 2012 The MathWorks, Inc.