main content

compute output, error, and coefficients using frequency-凯发k8网页登录

compute output, error, and coefficients using frequency-domain fir adaptive filter

description

the dsp.frequencydomainadaptivefilter system object™ implements an adaptive finite impulse response (fir) filter in the frequency domain using the fast block least mean squares (lms) algorithm. the length and the blocklength properties specify the filter length and the block length values the algorithm uses. the fftcoefficients property contains the discrete fourier transform of the current filter coefficients. the object offers the constrained and unconstrained versions of the algorithm with partitioned and non-partitioned modes. for details, see .

to filter a signal using frequency-domain fir adaptive filter:

  1. create the dsp.frequencydomainadaptivefilter object and set its properties.

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

to learn more about how system objects work, see what are system objects?

creation

description

example

fdaf = dsp.frequencydomainadaptivefilter returns a frequency domain fir adaptive filter system object, fdaf. this system object is used to compute the filtered output and the filter error for a given input and desired signal.

example

fdaf = dsp.frequencydomainadaptivefilter(len) returns a frequency domain fir adaptive filter object with the length property set to len.

example

fdaf = dsp.frequencydomainadaptivefilter(___,name,value) returns a frequency domain fir adaptive filter object with each specified property set to the specified value. enclose each property name in quotes. you can use this syntax with any previous input argument combinations.

example: fdaf = dsp.frequencydomainadaptivefilter('length',32,'stepsize',0.1) models a frequency-domain adaptive filter with a length of 32 taps and a step size of 0.1.

properties

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 function unlocks them.

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

for more information on changing property values, see .

method used to calculate the filter coefficients, specified as:

  • 'constrained fdaf' –– imposes a gradient constraint on the filter tap weights.

  • 'unconstrained fdaf' –– no gradient constraint is imposed on the filter tap weights.

  • 'partitioned constrained fdaf' –– partitions the impulse response of the filter to reduce latency.

  • 'partitioned unconstrained fdaf' –– partitions the impulse response of the filter to reduce latency. no gradient constraint is imposed on the filter tap weights.

for more details, see .

length of the fir filter coefficients vector, specified as a positive, integer-valued scalar.

data types: single | double | int8 | int16 | int32 | int64 | uint8 | uint16 | uint32 | uint64

block length for the coefficient updates, specified as a positive, integer-valued scalar. the adaptive filter processes the input data and the desired signal as a block of samples of length set by this property. for details on how this data is processed by the filter, see . the length of the input vector must be divisible by the blocklength property value. the default value of the blocklength property is set to the value of the length property.

data types: single | double | int8 | int16 | int32 | int64 | uint8 | uint16 | uint32 | uint64

adaptation step size factor, specified as a real scalar in the range (0,1]. using a small step size ensures a small steady-state error. however, a small step size decreases the resulting convergence speed of the adaptive filter. increasing the step size improves the convergence speed, at the cost of increased steady-state mean squared error. when the step size value is 1, the algorithm provides the optimal tradeoff between the convergence speed and the steady-state mean squared error.

tunable: yes

data types: single | double | int8 | int16 | int32 | int64 | uint8 | uint16 | uint32 | uint64 | logical

leakage factor used when implementing a leaky adaptive filter, specified as a scalar numeric value in the range [0,1]. when the value is less than 1, the system object implements a leaky adaptive algorithm. when the value is 1, the object provides no leakage in the adapting method.

tunable: yes

data types: single | double | int8 | int16 | int32 | int64 | uint8 | uint16 | uint32 | uint64 | logical

averaging factor used to compute the exponentially windowed fft input signal powers for the coefficient updates, specified as a real scalar in the range (0,1].

tunable: yes

data types: single | double | int8 | int16 | int32 | int64 | uint8 | uint16 | uint32 | uint64 | logical

offset for the normalization terms in the coefficient updates, specified as a nonnegative real scalar value. this property value is used to avoid division by zero or division by very small numbers if any of the fft input signal powers become very small.

tunable: yes

data types: single | double | int8 | int16 | int32 | int64 | uint8 | uint16 | uint32 | uint64

initial common value of all of the fft input signal powers, specified as a positive numeric scalar.

if you change this value once the object is locked, the change takes effect only after you reset the object.

tunable: yes

data types: single | double | int8 | int16 | int32 | int64 | uint8 | uint16 | uint32 | uint64

initial time-domain coefficients of the adaptive filter, specified as a scalar or a vector of length equal to the length property value. the adaptive filter object uses these coefficients to compute the initial frequency-domain filter coefficients.

if you change this value once the object is locked, the change takes effect only after you reset the object.

tunable: yes

data types: single | double | int8 | int16 | int32 | int64 | uint8 | uint16 | uint32 | uint64

locked status of the coefficient updates, specified as:

  • false –– the object continuously updates the filter coefficients.

  • true –– the filter coefficients do not get updated and their values remain at the current value.

tunable: yes

data types: logical

this property is read-only.

current discrete fourier transform of the filter coefficients, returned as a row vector. for 'constrained fdaf' and 'unconstrained fdaf' algorithms, the length of this vector is equal to the sum of the length value and the blocklength value. this property is initialized to the fft values of the initialcoefficients property. to get the discrete fourier transform of the filter coefficients, call the object, and access the fftcoefficients property of the object.

data types: single | double
complex number support: yes

usage

description

[y,err] = fdaf(x,d) filters the input signal, x, using d as the desired signal, and returns the filtered output in y and the filter error in err. the system object estimates the filter weights needed to minimize the error between the output signal and the desired signal. the fft of these filter weights can be obtained by accessing the fftcoefficients property after calling the object algorithm.

input arguments

the signal to be filtered by the frequency-domain fir adaptive filter. the input, x, and the desired signal, d, must have the same size and data type. the length of the input vector must be divisible by the blocklength property value.

the input, x, can be a variable-size signal as long as the frame length is a multiple of the blocklength. you can change the number of elements in the column vector even when the object is locked. the system object locks when you call the object to run its algorithm.

data types: single | double
complex number support: yes

the frequency domain adaptive filter adapts its filter weights to minimize the error, err, and converge the input signal, x, to the desired signal, d, as closely as possible.

the input signal and the desired signal must have the same size and data type. the length of the desired signal vector must be divisible by the blocklength property value.

the input signal can be a variable-size signal as long as the frame length is a multiple of the blocklength. you can change the number of elements in the column vector even when the object is locked. the system object locks when you call the object to run its algorithm.

data types: single | double
complex number support: yes

output arguments

filtered output, returned as a column vector. the object adapts its filter weights to converge the input signal, x, to match the desired signal, d. the filter outputs the converged signal.

data types: single | double
complex number support: yes

difference between the output signal and the desired signal, returned as a column vector. the objective of the adaptive filter is to minimize this error. the object adapts its weights to converge towards optimal filter weights which produce an output signal that matches the desired signal as closely as possible. for more details on how err is computed, see .

data types: single | double
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)
run system object algorithm
release resources and allow changes to system object property values and input characteristics
reset internal states of system object

examples

transmit a quadrature phase shift keying (qpsk) signal across a noisy transmission channel. minimize the noise in the received signal using a frequency-domain adaptive filter.

the qpsk signal, s, is transmitted across a noisy channel. the numerator and the denominator coefficients of the channel are contained in the vectors b and a, respectively. the received signal, r, obtained at the end of the transmission channel contains the transmitted qpsk signal and the noise added to the channel, n. the adaptive filter is used to extract the qpsk signal from the received noisy input. the desired signal, d, is the delayed version of the qpsk signal.

d = 16;
b  = exp(1i*pi/4)*[-0.7 1];
a  = [1 -0.7];
ntr = 1024;
s  = sign(randn(1,ntr d))   1i*sign(randn(1,ntr d));
n  = 0.1*(randn(1,ntr d)   1i*randn(1,ntr d));
r  = filter(b,a,s)   n;
x  = r(1 d:ntr d);
d  = s(1:ntr);

create a dsp.frequencydomainadaptivefilter object to model a frequency-domain adaptive filter of length 32 taps and a step size of 0.1. the adaptive filter accepts the delayed version of the received signal and the desired signal as inputs. the output of the adaptive filter is compared to the desired signal. the error between the two signals represents the noise added to the transmission channel. the adaptive filter updates its coefficients until this error becomes minimal. to get the discrete fourier transform of the filter coefficients, call the fdaf object, and access the fftcoefficients property of this object.

mu  = 0.1;
fdaf = dsp.frequencydomainadaptivefilter('length',32,'stepsize',mu);
[y,e] = fdaf(x,d);
fftcoeffs = fdaf.fftcoefficients
fftcoeffs = 1×64 complex
   0.6802 - 0.6847i  -0.2485 - 0.9427i  -0.9675 - 0.2123i  -0.5605   0.8002i   0.5748   0.7593i   0.8541 - 0.3917i  -0.2526 - 0.9022i  -0.9298   0.1255i   0.0181   0.9366i   0.9207   0.0511i   0.1063 - 0.8972i  -0.8919 - 0.1829i  -0.2668   0.9113i   0.9215   0.3186i   0.3417 - 0.8859i  -0.8285 - 0.3760i  -0.4317   0.8200i   0.8741   0.4765i   0.4874 - 0.9075i  -0.8517 - 0.4774i  -0.4709   0.7632i   0.7468   0.4833i   0.5193 - 0.7995i  -0.8218 - 0.5649i  -0.5908   0.7768i   0.7316   0.5866i   0.5806 - 0.7270i  -0.7148 - 0.5998i  -0.6287   0.6702i   0.6575   0.6379i   0.6332 - 0.7153i  -0.7659 - 0.6424i  -0.6678   0.7294i   0.6536   0.6891i   0.7006 - 0.6333i  -0.6594 - 0.7117i  -0.7207   0.6517i   0.6031   0.7239i   0.7362 - 0.5776i  -0.5869 - 0.7682i  -0.7975   0.5789i   0.5449   0.7992i   0.7909 - 0.5343i  -0.5512 - 0.8070i  -0.8392   0.5338i   0.4605   0.8493i   0.8358 - 0.3921i  -0.3751 - 0.8388i  -0.8739   0.3785i   0.3625   0.9048i

plot the in-phase and the quadrature components of the desired, output, and the error signals.

plot(1:ntr,real([d;y;e]))
legend('desired','output','error')
title('in-phase components')
xlabel('time index'); ylabel('signal value')

figure contains an axes object. the axes object with title in-phase components, xlabel time index, ylabel signal value contains 3 objects of type line. these objects represent desired, output, error.

plot(1:ntr,imag([d;y;e]))
legend('desired','output','error')
title('quadrature components')
xlabel('time index')
ylabel('signal value')

figure contains an axes object. the axes object with title quadrature components, xlabel time index, ylabel signal value contains 3 objects of type line. these objects represent desired, output, error.

create scatter plots of the received signal and the desired signal.

plot(x(ntr-100:ntr),'.')
axis([-3 3 -3 3])
title('received signal scatter plot')
axis('square')
xlabel('real[x]')
ylabel('imag[x]') 
grid on

figure contains an axes object. the axes object with title received signal scatter plot, xlabel real[x], ylabel imag[x] contains a line object which displays its values using only markers.

plot(d(ntr-100:ntr),'.')
axis([-3 3 -3 3])
title('desired signal scatter plot')
axis('square')
xlabel('real[y]')
ylabel('imag[y]')
grid on

figure contains an axes object. the axes object with title desired signal scatter plot, xlabel real[y], ylabel imag[y] contains a line object which displays its values using only markers.

the adaptive filter equalizes the received signal to eliminate noise. plot the scatter plot of the equalized signal.

plot(y(ntr-100:ntr),'.')
axis([-3 3 -3 3])
title('equalized signal scatter plot')
axis('square')
xlabel('real[y]')
ylabel('imag[y]')
grid on

figure contains an axes object. the axes object with title equalized signal scatter plot, xlabel real[y], ylabel imag[y] contains a line object which displays its values using only markers.

use a frequency-domain adaptive filter to estimate the coefficients of a long fir filter. the fir filter models the impulse response of a room. use the partitioned mode in the frequency-domain adaptive filter to reduce filter latency.

note: this example runs only in r2018a or later.

initialization

generate a long fir impulse response of 8192 samples and assign the impulse response to a dsp.firfilter object, room. this object models the impulse response of a room. create a dsp.frequencydomainadaptivefilter filter, lmsfilt, in partitioned constrained mode. set the length of the filter to one-fourth the length of the impulse response of the room. set the block length of the filter to 128 samples. set the step size to 0.025, initial power to 0.01, averaging factor to 0.98, offset to 1, and the leakage factor to 1. initialize a dsp.arrayplot object to view the filter coefficients. initialize a timescope object to show the mean-squared error between the filter output and the desired signal.

fs = 16e3;
m = 8192;
[b,a] = cheby2(4,20,[0.1 0.7]);
impulseresponsegenerator = dsp.iirfilter(...
    'numerator', [zeros(1,6) b], ...
    'denominator', a);
roomimpulseresponse = impulseresponsegenerator( ...
    (log(0.99*rand(1,m) 0.01).*sign(randn(1,m)).*exp(-0.002*(1:m)))');
roomimpulseresponse = roomimpulseresponse/norm(roomimpulseresponse);
room = dsp.firfilter('numerator',roomimpulseresponse');
lmsfilt = dsp.frequencydomainadaptivefilter(...
    'method','partitioned constrained fdaf',...
    'length',m/4, ...
    'blocklength',128,...
    'stepsize',0.025, ...
    'initialpower',0.01, ...
    'averagingfactor',0.98,...
    'offset',1,...
    'leakagefactor',1);
framesize = lmsfilt.blocklength; niter = 2000;
ap = dsp.arrayplot('ylimits',[-0.2 .2],'showlegend',true, ...
    'position',[0 0 560 420],'channelnames', ...
    {'actual coefficients','estimated coefficients'});
ts = timescope('samplerate',fs,'timespansource','property',...
    'timespan',framesize*niter/fs,...
    'timeunits','seconds',...
    'ylimits',[-50 0],'title','learning curve',...
    'ylabel','db', ...
    'bufferlength',framesize*niter,...
    'showgrid',true);
signalmean = dsp.movingaverage('specifywindowlength',false);

streaming

generate a random input signal using the randn function. the frame size of the input matches the block length of the adaptive filter. the desired signal is the sum of the output of the fir filter (room) and a white gaussian noise signal. pass the input signal and the desired signal to the adaptive filter. compute the adaptive filter output and the error between the output and the desired signal.

estimate the time-domain coefficients of the adaptive filter by taking the ifft of the frequency-domain coefficients vector returned by the lmsfilt.fftcoefficients property. compare the estimated coefficients with the actual coefficients assigned to the fir filter (room). once the adaptive filter has converged its output to the desired signal, and minimized the error signal, the estimated coefficients match closely with the actual coefficients. this means that the adaptive filter has successfully adapted itself to model the impulse response of the fir filter (room).

for k = 1:niter
    x = randn(framesize,1);
    d = room(x)   0.01*randn(framesize,1);
    [y,e] = lmsfilt(x,d);
    fftcoeffs = lmsfilt.fftcoefficients;
    w = ifft(fftcoeffs,[],2,'symmetric');
    w = w(:,1:framesize)   w(:,framesize 1:end);
    w = reshape(w.',1,m/4);
    ap([roomimpulseresponse(1:m/4),w.']);
    ts(10*log10(signalmean(abs(e).^2)));
end

as the filter adapts with time, you can see in the time scope that the mean-squared error becomes minimal. simultaneously, the estimated coefficients match the actual coefficients closely in the array plot.

algorithms

frequency-domain adaptive filtering consists of three steps - filtering, error estimation, and tap-weight adaptation. this algorithm implements fir filtering in the frequency domain using the overlap-save or overlap-add method. for more implementation details of these two methods, see the section in the dsp.frequencydomainfirfilter object page. the error estimation and the tap-weight adaptation are implemented using the fast block lms algorithm (fblms).

references

[1] shynk, j.j. "frequency-domain and multirate adaptive filtering." ieee signal processing magazine. vol. 9, number 1, 1992, pp. 14–37.

[2] farhang-boroujeny, b., adaptive filters: theory and applications, chichester, england, wiley, 1998.

[3] stockham, t. g., jr. "high speed convolution and correlation." proceedings of the 1966 spring joint computer conference, afips, vol. 28, 1966, pp. 229–233.

extended capabilities

version history

introduced in r2013b

网站地图