Remove DC component
DCBlocker object filters
or blocks the DC component of an incoming signal.
To filter the DC component of a signal:
H = dsp.DCBlocker creates a DC blocker System object™,
that removes the DC component of each channel, i.e., column, of an
H = dsp.DCBlocker( creates
a DC blocker object,
H, with each specified property
set to the specified value. You can specify additional name-value
pair arguments in any order as (
DC offset algorithm type
Specify the DC offset estimating algorithm as one of
Normalized bandwidth of the lowpass IIR elliptic filter or the lowpass CIC filter
Specify the normalized bandwidth of the IIR or CIC filter used
to estimate the DC component of the input signal as a real scalar
greater than 0 and less than 1. This property applies when the
Order of the lowpass IIR elliptic filter
Specify the order of the IIR elliptic filter used to estimate
the DC level. This property applies when the
Number of past input samples for the FIR algorithm
Specify the number of past inputs used to estimate the running
mean. This property applies when the
|clone||Create DC blocker object with same property values|
|fvtool||Show the frequency response of the filter used by the |
|isLocked||Locked status for input attributes and nontunable properties|
|release||Allow property value and input characteristics changes|
|reset||Reset states of the |
|step||Blocks DC components of input signal|
This example shows how to use the DC Blocker System object to remove an input signal's DC component using using three of the estimation algorithms.
Create a signal composed of a 15 Hz tone, a 25 Hz tone, and a DC offset.
t = (0:0.001:100)'; x = sin(30*pi*t) + 0.33*cos(50*pi*t) + 1;
Create three DC Blocker objects for the
Subtract mean estimation algorithms.
hDC1 = dsp.DCBlocker('Algorithm','IIR','Order', 6); hDC2 = dsp.DCBlocker('Algorithm','FIR','Length', 100); hDC3 = dsp.DCBlocker('Algorithm','Subtract mean');
For each second of time, use the
step function to pass the input signal through the DC blockers. By implementing the DC blockers in 1 second increments, you can observe differences in the convergence times.
for idx = 1 : 100 range = (1:1000) + 1000*(idx-1); y1 = step(hDC1,x(range)); % IIR estimate y2 = step(hDC2,x(range)); % FIR estimate y3 = step(hDC3,x(range)); % Subtract mean end
Plot the input and output data for the three DC blockers for the first second of time and show the mean value for each signal. Looking at the mean values for the three algorithm types, you can see that the
Subtract mean algorithms converge more quickly.
plot(t(1:1000),x(1:1000),... t(1:1000),y1, ... t(1:1000),y2, ... t(1:1000),y3); xlabel('Time (sec)') ylabel('Amplitude') legend(sprintf('Input DC:%.3f',mean(x)), ... sprintf('IIR DC:%.3f',mean(y1)), ... sprintf('FIR DC:%.3f',mean(y2)), ... sprintf('Subtract mean DC:%.3f',mean(y3)));
This example shows a comparison of the spectrum of an input signal with a DC offset to the spectrum of the same signal after application of a DC blocker using the
FIR estimation algorithm.
Create an input signal composed of three tones and 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 with the
Algorithm property set to
hDCBlock = dsp.DCBlocker('Algorithm','FIR','Length',100);
SpectrumAnalyzer System object 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 method, create a second spectrum analyzer to display the response of the output. Then, use the
Name property to label the two objects.
hsa = dsp.SpectrumAnalyzer('SampleRate',fs, ... 'PowerUnits','dBW','FrequencySpan','Start and stop frequencies',... 'StartFrequency',-30,'StopFrequency',30); hsb = clone(hsa); hsa.Name = 'Signal Spectrum'; hsb.Name = 'Signal Spectrum after DC Blocker';
Pass the input signal,
x, through the DC blocker to generate the output signal,
y = step(hDCBlock,x);
Use the spectrum analyzer,
hsa, to display the frequency characteristics of the input signal. Note that the tones at 15 Hz, 20 Hz, and 25 Hz, and the DC component are clearly visible.
Use the second spectrum analyzer,
hsb, to display the frequency characteristics of the output signal. Note that the DC component has been removed.
This example shows how to use the DC Blocker to remove a DC offset from a fixed-point signal. The DC Blocker uses the CIC lowpass filtering method to estimate the DC offset.
Generate random binary data.
data = randi([0 1],1.2e5,1);
Modulate the data by creating a 64-QAM modulator System object and using its
hMod = comm.RectangularQAMModulator('ModulationOrder',64, ... 'BitInput',true); modOut = step(hMod,data);
Determine the constellation reference points for the modulator.
cRefPts = constellation(hMod);
Add AWGN to the modulated signal using the appropriate System object along with its
hNoise = comm.AWGNChannel('EbNo', 14.75, ... 'BitsPerSymbol', 6, ... 'SignalPower', 42, ... 'SamplesPerSymbol', 1); noisyOut = step(hNoise,modOut);
Display the scatter plot of the noisy signal by using a Constellation Diagram object. The red '+' markers show the ideal symbol locations.
hCPlot = comm.ConstellationDiagram('Name','Noisy Constellation',... 'ReferenceConstellation',cRefPts, ... 'XLimits',[-8 8],'YLimits',[-8 8]); step(hCPlot,noisyOut)
Add a DC offset of 1 to the modulated signal.
noisyOut = noisyOut + 1;
Display the spectrum of the signal. The spike at 0 kHz is due to the introduced offset.
hSpectrum = dsp.SpectrumAnalyzer(... 'YLimits',[-40,40], ... 'Title','Noisy Spectrum with DC Offset'); step(hSpectrum,noisyOut);
View the effect of the DC offset on the constellation. Observe that the constellation has shifted one unit to the right.
step(hCPlot,noisyOut) hCPlot.Name = 'Noisy Constellation with DC Offset';
Convert the noisy signal to a signed, fixed-point object that has a 16-bit word length and an 11-bit fraction length.
noisyOut = fi(noisyOut,1,16,11);
Remove the offset by creating a DC Blocker object. Set the
Algorithm property of the object to
hBlock = dsp.DCBlocker('Algorithm','CIC');
Visualize the frequency response of the CIC estimating filter.
Pass the offset, noisy signal through the DC Blocker and convert its output to a double.
dcBlockerOutFxP = step(hBlock,noisyOut); dcBlockerOut = double(dcBlockerOutFxP);
Plot the signal spectrum to show the effect of removing the DC offset. The spike at 0 kHz has been removed.
step(hSpectrum,dcBlockerOut); hSpectrum.Title = 'Noisy Spectrum with DC Removed';
Plot the constellation and verify that the signal shifted back to the left.
step(hCPlot,dcBlockerOut) hCPlot.Name = 'Noisy Constellation with DC Removed';
To see the effects of removing a DC offset, vary the value of the
DCBlocker System object subtracts the DC
component from the input signal. The DC component is estimated by
one of the following:
Passing the input signal through an IIR lowpass elliptical filter
Passing the input signal through an FIR filter that uses a non-recursive, moving average from a finite number of past input samples
Passing the input signal through a CIC filter. Because the CIC filter amplifies the signal, the filter gain is estimated and subtracted from the DC estimate.
Computing the mean value of the input signal
The elliptical IIR filter has a passband ripple of 0.1 dB and a stopband attenuation of 60 dB. You specify the normalized bandwidth and filter order.
The FIR filter coefficients are given as
where you specify the
Length parameter. The FIR
filter structure is a direct form 1 transposed.
The Cascaded Integrator-Comb (CIC) filter consists of two integrator-comb pairs. This helps to ensure that the peak of the first sidelobe of the filter response is attenuated by at least 25 dB relative to the peak of the main lobe. The normalized 3-dB bandwidth is used to calculate the differential delay. The delay is used to determine the gain of the CIC filter. The inverse of the filter gain is used as a multiplier which is applied to the output of the CIC filter. This ensures that the aggregate gain of the DC estimate is 0 dB.
The aggregate magnitude response of the filter and the multiplier is characterized by the following equation:
Bnorm is the normalized bandwidth such that 0 < Bnorm < 1.
M is the differential delay in samples.
N is the number of sections, equal to 2.
The differential delay is found by setting M to the smallest integer such that |H(ejω)| < 1/√2. Once M is known, the gain of the CIC filter is calculated as MN. Therefore, to precisely compensate for the filter gain, the multiplier is set to (1/M)N.
 Nezami, M., "Performance Assessment of Baseband Algorithms for Direct Conversion Tactical Software Defined Receivers: I/Q Imbalance Correction, Image Rejection, DC Removal, and Channelization", MILCOM, 2002.