%% Frequency Response Before and After DC Blocker
% *Note*: If you are using R2016a or earlier, replace each call to the object 
% with the equivalent step syntax. For example, obj(x) becomes step(obj,x).
% 
% Compare the spectrum of an input signal with a DC offset to the spectrum 
% of the same signal after applying a DC blocker. Enable the DC blocker to use 
% the |FIR| estimation algorithm.
% 
% Create an input signal composed of three tones and that has a DC offset 
% of 1. Set the sampling frequency to 1 kHz and set the signal duration to 100 
% seconds.

fs = 1000;
t = (0:1/fs:100)';
x = sin(30*pi*t) + 0.67*sin(40*pi*t) + 0.33*sin(50*pi*t) + 1;
%% 
% Create a DC blocker object that uses the FIR algorithm to estimate the 
% DC offset.
%%
dcblker = dsp.DCBlocker('Algorithm','FIR','Length',100);
%% 
% Create a spectrum analyzer with power units set to |dBW| and a frequency 
% range of |[-30 30]| to display the frequency response of the input signal. Using 
% the |clone| function, create a second spectrum analyzer to display the response 
% of the output. Then, use the |Title| property of the spectrum analyzers to label 
% them.
%%
hsa = dsp.SpectrumAnalyzer('SampleRate',fs, ...
    'PowerUnits','dBW','FrequencySpan','Start and stop frequencies',...
    'StartFrequency',-30,'StopFrequency',30,'YLimits',[-200 20],...
    'Title','Signal Spectrum');

hsb = clone(hsa);
hsb.Title = 'Signal Spectrum After DC Blocker';
%% 
% Pass the input signal, |x|, through the DC blocker to generate the output 
% signal, |y|.
%%
y = dcblker(x);
%% 
% Use the first spectrum analyzer to display the frequency characteristics 
% of the input signal. The tones at 15, 20, and 25 Hz, and the DC component, are 
% clearly visible.
%%
hsa(x)
%% 
% Use the second spectrum analyzer to display the frequency characteristics 
% of the output signal. The DC component has been removed.
%%
hsb(y)

%% 
% Copyright 2012 The MathWorks, Inc.