dsp.Differentiator

Direct form FIR fullband differentiator filter

Description

The dsp.Differentiator System object™ applies a fullband differentiator filter on the input signal to differentiate all its frequency components. This object uses an FIR equiripple filter design to design the differentiator filter. The ideal frequency response of the differentiator is $D\left(\omega \right)=j\omega$ for $-\pi \le \omega \le \pi$. You can design the filter with minimum order with a specified order. This object supports fixed-point operations.

To filter each channel of your input:

1. Create the dsp.Differentiator object and set its properties.

2. Call the object with arguments, as if it were a function.

Creation

Description

example

DF = dsp.Differentiator returns a differentiator, DF, which independently filters each channel of the input over time using the given design specifications.

DF = dsp.Differentiator(Name,Value) sets each property name to the specified value. Unspecified properties have default values.

Properties

expand all

Unless otherwise indicated, properties are nontunable, which means you cannot change their values after calling the object. Objects lock when you call them, and the release function unlocks them.

If a property is tunable, you can change its value at any time.

Option to design a minimum-order filter, specified as a logical scalar. The filter has 2 degrees of freedom. When you set this property to

• true — The object designs the filter with the minimum order that meets the PassbandRipple value.

• false — The object designs the filter with order that you specify in the FilterOrder property.

This property is not tunable.

Order of the filter, specified as an odd positive integer.

This property is not tunable.

Dependencies

You can specify the filter order only when 'DesignForMinimumOrder' is set to false.

Data Types: single | double | int8 | int16 | int32 | int64 | uint8 | uint16 | uint32 | uint64

Maximum passband ripple in dB, specified as a positive real scalar.

This property is not tunable.

Dependencies

You can specify the passband ripple only when 'DesignForMinimumOrder' is set to true.

Data Types: single | double | int8 | int16 | int32 | int64 | uint8 | uint16 | uint32 | uint64

Option to scale the filter coefficients, specified as a logical scalar. When you set this property to true, the object scales the filter coefficients to preserve the input dynamic range.

This property is not tunable.

Fixed-Point Properties

Word and fraction lengths of coefficients, specified as a signed or unsigned numerictype object. The default, numerictype(1,16), corresponds to a signed numeric type object with 16-bit coefficients. To give the best possible precision, the fraction length is computed based on the coefficient values.

This property is not tunable.

The word length of the output is the same as the word length of the input. The object computes the fraction length of the output such that the entire dynamic range of the output can be represented without overflow. For details on how the object computes the fraction length of the output, see Fixed-Point Precision Rules for Avoiding Overflow in FIR Filters.

Rounding method for output fixed-point operations, specified as a character vector. For more information on the rounding modes, see Precision and Range.

This property is not tunable.

Usage

Description

example

y = DF(x) applies a fullband differentiator filter to the input signal, x. y is a differentiated version of x.

Input Arguments

expand all

Data input, specified as a vector or a matrix. If the input signal is a matrix, each column of the matrix is treated as an independent channel. The number of rows in the input signal denotes the channel length. The data type characteristics (double, single, or fixed-point) and the real-complex characteristics (real or complex valued) must be the same for the input data and output data.

Data Types: single | double | int8 | int16 | int32 | int64 | uint8 | uint16 | uint32 | uint64 | fi
Complex Number Support: Yes

Output Arguments

expand all

Differentiated signal, returned as a vector or matrix of the same size, data type, and complexity as the input signal, x.

Data Types: single | double | int8 | int16 | int32 | int64 | uint8 | uint16 | uint32 | uint64 | fi
Complex Number Support: Yes

Object Functions

To use an object function, specify the System object as the first input argument. For example, to release system resources of a System object named obj, use this syntax:

release(obj)

expand all

 getFilter Get underlying FIR filter
 step Run System object algorithm release Release resources and allow changes to System object property values and input characteristics reset Reset internal states of System object

Examples

collapse all

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).

Estimate the group delay of a linear phase FIR filter using a dsp.TransferFunctionEstimator object followed by dsp.PhaseExtractor and dsp.Differentiator objects. The group delay of a linear phase FIR filter is given by , where is the phase information of the filter, is the frequency vector, and N is the order of the filter.

Set Up the Objects

Create a linear phase FIR lowpass filter. Set the order to 200, the passband frequency to 255 Hz, the passband ripple to 0.1 dB, and the stopband attenuation to 80 dB. Specify a sample rate of 512 Hz.

Fs = 512;
LPF = dsp.LowpassFilter('SampleRate',Fs,'PassbandFrequency',255,...
'DesignForMinimumOrder',false,'FilterOrder',200);

To estimate the transfer function of the lowpass filter, create a transfer function estimator. Specify the window to be Hann. Set the FFT length to 1024 and the number of spectral averages to 200.

TFE = dsp.TransferFunctionEstimator('FrequencyRange','twosided',...
'SpectralAverages',200,'FFTLengthSource','Property',...
'FFTLength',1024);

To extract the unwrapped phase from the frequency response of the filter, create a phase extractor.

PE = dsp.PhaseExtractor;

To differentiate the phase , create a differentiator filter. This value is used in computing the group delay.

DF = dsp.Differentiator;

To smoothen the input, create a variable bandwidth FIR filter.

Gain1 = 512/pi;
Gain2 = -1;
VBFilter = dsp.VariableBandwidthFIRFilter('CutoffFrequency',10,...
'SampleRate',Fs);

To view the group delay of the filter, create an array plot object.

AP = dsp.ArrayPlot('PlotType','Line','YLimits',[-500 400],...
'YLabel','Amplitude','XLabel','Number of samples');

Run the Algorithm

The for-loop is the streaming loop that estimates the group delay of the filter. In the loop, the algorithm filters the input signal, estimates the transfer function of the filter, and differentiates the phase of the filter to compute the group delay.

Niter = 1000; % Number of iterations
for k = 1:Niter
x = randn(512,1);  % Input signal = white Gaussian noise
y = LPF(x);   % Filter noise with Lowpass FIR filter
H = TFE(x,y); % Compute transfer function estimate
Phase = PE(H); % Extract the Unwrapped phase
phaseaftergain1 = Gain1*Phase;
DiffOut = DF(phaseaftergain1); % Differentiate the phase
phaseaftergain2 = Gain2 * DiffOut;
VBFOut = VBFilter(phaseaftergain2); % Smooth the group delay
AP(VBFOut); % Display the group delay
end

As you can see, the group delay of the lowpass filter is 100.

Create an FM wave on a 100 Hz carrier signal sampled at 1.5 kHz.

Fc = 1e2;   % Carrier
Fs = 1.5e3; % Sample rate
sinewave = dsp.SineWave('Frequency',10,...
'SamplesPerFrame',1e3,...
'SampleRate',Fs);

Convert the FM signal to an AM signal.

ts = timescope('TimeSpanSource','Property',...
'TimeSpan',0.3,...
'BufferLength',10*Fs,...
'SampleRate',Fs,...
'ShowGrid',true,...
'YLimits',[-1.5 1.5],...
'LayoutDimensions',[2 1]);

df = dsp.Differentiator;

tic
while toc<2.2
x = step(sinewave);
fm_y = modulate(x,Fc,Fs,'fm');
am_y = step(df,fm_y);
step(ts,fm_y,am_y);
end

release(df);
release(ts);

expand all

References

[1] Orfanidis, Sophocles J. Introduction to Signal Processing. Upper Saddle River, NJ: Prentice-Hall, 1996.

Version History

Introduced in R2016a