Computers Windows Internet

Digital filtering algorithm. Algorithms for digital filtering of signals based on the theory of fuzzy sets dmitry anatolevich titov. Intelligent automation in coursework and diploma projects

Saint Petersburg State Polytechnic University

Faculty of Technical Cybernetics

Department of Automation and Computer Engineering

REPORT

for laboratory work No. 3

Research of recurrent digital filtering algorithms

signals by the averaging method.

Completed by student gr. 4081/1 Volykhin A.N.

Checked by: V.D. Yarmiychuk

St. Petersburg

1. Objectives of the work

The purpose of the work is to get acquainted with various algorithms for digital filtering of signals by the averaging method and study the efficiency of their work in conditions when a noise of the "white noise" type with zero mathematical expectation is imposed on the useful signal and

controlled dispersion.

2. Research methodology

Filters based on the following algorithms are being investigated:

1). Recurrent averaging algorithm with infinite memory.

The purpose of the filter is to isolate the constant component of the useful signal against the background of interference.

Expression for it in recurrent form:

When he provides .

2). Recurrent averaging algorithm with constant correction factor.

The purpose of the filter is to isolate the low-frequency components of the input useful signal against the background of noise.

If you accept, then you can write this equation in the form:

Whence, when passing to continuous time, we obtain the transfer function of the filter:

That is, the filter constructed according to this algorithm, for small values, is equivalent to

a first-order analog low-pass filter.

3). Recurrent finite memory averaging algorithm.

The purpose of the filter is to highlight the low-frequency components of the input signal

using averaging of only a limited number of its most recent measurements.

The efficiency of digital filtering, that is, a measure of reducing the level of noise at the filter output in comparison with the level of noise at the input, will be estimated as follows:

Where: - noisy signal at the filter input

Useful signal at the filter input

Filter output signal

Useful signal at the filter output

3. Scheme of the experiment (see Appendix 1)

4. Experimental results

4.1. Recurrent averaging algorithm with infinite memory

The studies were carried out with a constant sampling period of 100 ms.

Consider how the efficiency of the filter changes from the magnitude of the constant input signal (X).

LABORATORY WORK

SIGNAL FILTERING ALGORITHMSIn the process control system

Target. Acquaintance with the algorithms for filtering measured random signals, most common in the process control system, conducting a comparative analysis of their accuracy and implementation features in a computer.

Exercise

1) for the given characteristics of random signals, calculate the optimal filter parameters,

2) simulate the filtration system on a computer and calculate the filtration error for each of the considered methods,

3) to carry out a comparative analysis of the effectiveness of the considered algorithms.

Basic provisions. 1 Statement of the optimal filtration problem. Signals from measuring devices often contain a random error - interference. The task of filtering is to separate the useful signal component from the interference to one degree or another. As a rule, both the useful signal and the interference are assumed to be stationary random processes for which their statistical characteristics are known: mathematical expectation, variance, correlation function, spectral density. Knowing these characteristics, it is necessary to find a filter in the class of linear dynamic systems or in a narrower class of linear systems with a given structure so that the signal at the filter output differs as little as possible from the useful signal.

Fig. 1. On the statement of the filtration problem

Let us introduce notation and formulate the filtration problem more precisely. Let the input of the filter with an impulse response To(t) and the corresponding (due to the Fourier transform) 0

AFKh W() useful signals are received x(t) and interference that is not correlated with it z(t) (fig. 1). The correlation functions and spectral densities of the useful signal and interference are denoted by R x (t), S x (t), R z (t) and S z (t) ... It is required to find the characteristics of the filter k (t) or W (t) so that the rms value of the difference ε between the signal at the filter output and the useful signal x was minimal. If the filter characteristic is known with an accuracy of one or several parameters, then the optimal values ​​of these parameters must be chosen.

Error ε contains two components. The first ( ε 1 ) is connected with the fact that some part of the noise will still pass through the filter, and the second ( ε 2 ) - so that the shape of the useful signal will change when passing through the filter. Thus, the determination of the optimal filter characteristic is a search for a compromise solution that minimizes the total error.

Let's represent the frequency response of the filter in the form:

W (iω) = A (ω) exp.

Using the formulas connecting the spectral densities of random processes at the input and output of a linear system with its frequency response, we calculate the spectral densities of each of the error components.

For the error associated with the skipping of the noise, we obtain

S ε1 (ω) = S z (ω ) A 2 (ω )

The spectral density of the error associated with the distortion of the useful signal is

S ε2 (ω) = S x (ω )|1 – W()| 2

The sum of these components S ε has the spectral density

S ε (ω ) = S ε1 (ω ) + S ε2 (ω )

Considering that

|1 – W()| 2 = 2 + A 2 (ω ) sin 2 f(ω ),

S ε (ω ) = S z (ω) A 2 (ω) + S x (ω) A 2 (ω ) + S x (ω) - 2S x (ω) A(ω) cosf(ω) . (1)

The root mean square error is related to the spectral density by the expression

By minimizing S ε (ω ) on f(ω) and A (ω), we arrive at the equations

cosf * (ω ) = 1
f *(ω ) = 0

2S z (ω ) A (ω) - 2S x (ω) = 0

(2)

The found characteristics of the optimal filter correspond to the spectral error density

Minimum root mean square error

(3)

Unfortunately, the found filter is not realizable, since the condition of equality to zero at all frequencies of the phase-frequency response means that the impulse response of the filter is an even function, it is nonzero not only for t>0 , but also at t(Figure 2, a).

For any physically realizable filter, the following requirement is true: To(t) = 0 at t (Fig. 2, b). This requirement should be introduced into the problem statement. Naturally, the achievable error σ at the same time would increase. The problem of optimal filtering taking into account the physical feasibility has been solved.

Rice. 2. Impulse characteristics of unrealizable (a) and realizable (b) filters

Rice. 3. Spectral densities of the useful signalS x (ω) and noiseS z (ω) and the amplitude-frequency characteristic of the optimal filter A * (ω) with non-overlapping (a) and overlapping (b)S x (ω) andS z (ω)

N. Wiener. Its solution is much more complicated than the one given above, therefore, in this work, we will look for physically realizable filters only in the class of filters whose characteristics are specified accurate to parameter values. The quantity calculated by formula (3) can serve as a lower estimate of the attainable filtering error.

The physical meaning of relation (2, b) is illustrated in Fig. 3. If the spectra of the useful signal and interference do not overlap, then A (ω) should be equal to zero where the spectral density of the interference is different from zero, and equal to one for all frequencies at which S x (ω)>0 ... In fig. 3, b shows the character A * (ω) in the case when the spectral densities of the signal and interference overlap each other.

Among filters with a given structure, the most widespread are filters based on the moving average operation, as well as an exponential filter and the so-called statistical filter of zero order. An exponential filter is a first-order aperiodic filter, and a zero-order statistical filter is an amplifying link. Let's consider each of the mentioned filters in more detail.

Moving average filter. The filter output is related to its input by the ratio

The impulse transient function of the filter is shown in Fig. 4, a. Frequency characteristics are equal


The impulse response can be expressed in terms of the Heaviside function 1(t)

k(t) = k.

Adjustable filter parameters are gain k and memory T.

Exponential filter(Fig. 4, b). The output signal is determined by the differential equation

y/ γ + y = kg

The impulse response is:

Frequency characteristics


The filter parameters are the gain k and the time constant inverse to γ .

Rice. 4. Impulse transient functionsk(t) and amplitude-frequency characteristics А (ω) of typical filters: а - current average; b - exponential; c) static zero order

Zero-order statistical filter. This filter, as mentioned above, is an amplifying link. Its characteristics

y(t) = kg(t) ; A(ω) = k; f(ω) = 0

The weight of the listed filters does not allow achieving ideal filtering even with disjoint signal and interference spectra. Minimize error σ ε you can select the parameters k, T, γ... This requires filter characteristics A (ω) and f(ω) as a function of frequency and parameters, substitute in formula (1), take the integral of the resulting expression, which will be a function of the filter parameters, and find the minimum of this integral over the parameters.

For example, for a statistical filter of Coulomb order, the spectral density of the error will have the form:

S ε (ω ) = S z (ω ) k 2 + S x ω (1 – k 2 )

Integral S ε is equal to the variance of the interference multiplied by π ... We get

Let us take into account that the integrals on the right-hand side of this equality are equal to the variances of the useful signal and the noise, so that

The condition for the minimum of this expression with respect to k leads to equality

After substitution of the found value k into the expression for the variance of the error, we get:

The filters of the current average and exponential have two adjustable parameters each, and their optimal values ​​cannot be expressed so easily through the characteristics of the useful signal and noise, but these values ​​can be found by numerical methods for finding the minimum of a function in two variables.

Fig. 5 Block diagram of computer simulation of a random signal filtering system

2. Description of the simulated system. The work is carried out by modeling on a computer a system consisting of the following blocks (Fig. 5).

1. Generator of input signal I, including a random signal generator (GSS) and two shaping filters with specified characteristics W x () and W z () , at the output of which a useful signal is received x(t) and hindrance z(t) ... Between the random signal generator and the shaping filter W z included a delay link Δ, providing a shift of two to three clock cycles. In this case, the input of the filter that forms the noise and the input of the filter that forms the useful signal are uncorrelated with each other.

2. Block for calculating correlation functions
.

3. Filtration unit (II), including the actual filter
and a block for calculating the filtering error
.

Useful signal generated in the system x(t) and hindrance z(t) are stationary random processes, the correlation functions of which can be approximately approximated by exponents of the form (Fig. 6)

(6)

where

Signal variance estimates and calculated using a block (at τ = 0); parameters α and α z are set by the teacher.

3. Discrete Implementation of Continuous Filters. We use discrete implementations of the continuous filters described above. Discreteness step t o take significantly less than the decay time of the correlation functions of the useful signal and noise. Therefore, the above expressions (1) for calculating σ ε through the spectral characteristics of the input signal and noise can be used in the discrete case as well.

Let us first find discrete analogs of filters that form random processes with correlation functions from the signal received from the GSS (6). The spectral densities corresponding to these correlation functions have the form


(7)

The transfer functions of the shaping filters for the case when the dispersion of the signal at the output of the GSS is equal to one, are


It is not hard to see that

If the signal at the input of each of the shaping filters is denoted by ξ , then the differential equations corresponding to the transfer functions written above have the form


The corresponding difference analogs will be written in the form;


Thus, the algorithm of the filter, which forms the useful signal, has the form:

(8a)

Likewise for the noise-shaping filter

(8b)

Analogs of continuous filters designed to isolate interference are as follows:

for moving average filter

(9)

where the value l choose from the condition (l + 1) t O = T;

for exponential filter

(10)

for the zero-order statistical filter

at i = kg i (11)

Execution order. 1. Create and debug the subroutines of the block for filtering current information and calculating filtering errors.

2. Obtain realizations of random processes at the output of the shaping filters and use them to find estimates of the variances of the useful signal and noise, as well as correlation functions R x (τ) and R z (τ) ... Approximately define α NS and α z and compare with the calculated ones.

3. Calculate by S x (ω) and S z (ω) analytically or on a computer lower bound for the rms filtering error.

4. Using formula (4), find the optimal gain of the zero-order statistical filter and the corresponding value which is compared with.

5. I use one of the well-known methods of finding the minimum of a function of two variables and a program compiled in advance to find the optimal parameters of the moving average and exponential filters and the root-mean-square errors of filtering. In this case, a specific combination of filter parameters corresponds to the spectral error density S ε (ω) defined by formula (1), and from it find the value after numerical integration.

6. Enter the filtering program into the computer, determine experimentally the root-mean-square error for the optimal and non-optimal filter parameters, compare the results with the calculated ones.

7. Conduct a comparative analysis of the effectiveness of various filtering algorithms for the following indicators: a) the minimum achievable root-mean-square error; b) required volume random access memory; c) computer counting time.

The report should contain: 1) block diagram of the system (see Fig. 5);

2) subroutines of shaping and synthesized filters;

3) calculation of the optimal parameters of the filters and the corresponding values ​​of the root-mean-square error;

4) the results of the analysis of the considered algorithms and conclusions.

Booth 6.2. Project creation 6.3. Study APCS at the training laboratory... certain goals their activities. Goals activities ...

  • Name Surname "" 20 g

    Document

    Mode work) ;. … […) [Mode name work] ... according to laboratory analyzes; 5) ... requirements for APCS... Technological processes ... processing and analysis of information ( signals, messages, documents, etc. ... algorithms filtration and algorithms eliminate noise from aim ...

  • Intelligent automation in coursework and diploma projects

    abstract

    The wire. target... product ... signal HART for integration into systems APCS ... filtration there are different types of dust sensors. DT400G works ... algorithm... the chemical industry. Technical means and laboratory work/ G.I. Lapshenkov, L.M. ...

  • Work program of the discipline "automation of technological processes"

    Working programm

    ... GOALS AND OBJECTIVES OF LEARNING THE DISCIPLINE The purpose... the main components APCS- controllers ... views signals c ... bug fixes, filtration messages, ... algorithms and programs, discussions, performance of control works. Laboratory classes. Laboratory ...

  • Physically feasible digital filters that operate in real time can use the following data to generate the output signal at a discrete moment in time: a) the value of the input signal at the moment of sampling, as well as a certain number of "past" input samples a certain number of previous samples of the output signal Integers the type determines the order of the CF. The classification of CFs is carried out in different ways, depending on how information about the past states of the system is used.

    Transversal CFs.

    This is the name given to filters that work in accordance with the algorithm.

    where is a sequence of coefficients.

    The number is the order of the transversal digital filter. As can be seen from formula (15.58), the transverse filter carries out a weighted summation of the previous samples of the input signal and does not use the past samples of the output signal. Applying the z-transformation to both sides of expression (15.58), we make sure that

    Hence it follows that the system function

    is a fractional rational function z with a multiple pole at and zeros, the coordinates of which are determined by the filter coefficients.

    The algorithm for the functioning of the transversal DF is illustrated by the block diagram shown in Fig. 15.7.

    Rice. 15.7. Scheme for constructing a transversal DF

    The main elements of the filter are blocks of delay of sample values ​​for one sampling interval (rectangles with symbols), as well as scale blocks that perform digital multiplication by the corresponding coefficients. From the outputs of the scale blocks, the signals go to the adder, where they add up to form a sample of the output signal.

    The form of the diagram presented here explains the meaning of the term "transverse filter" (from the English transverse - transverse).

    Software implementation of the transversal DF.

    It should be borne in mind that the block diagram shown in Fig. 15.7 is not a schematic diagram electrical circuit, but only serves graphic image signal processing algorithm. Using the means of the FORTRAN language, let us consider a fragment of a program that implements transverse digital filtering.

    Let two one-dimensional arrays of M cells each be formed in the computer's RAM: an array with the name X, which stores the values ​​of the input signal, and an array with the name A, containing the values ​​of the filter coefficients.

    The contents of the cells in array X change each time a new sample of the input signal is received.

    Suppose that this array is filled with the previous samples of the input sequence, and consider the situation that arises at the moment of the arrival of the next sample, which is given the name S in the program. This sample should be placed in cell number 1, but only after the previous record is one position to the right, i.e. towards the lagging side.

    The elements of the array X formed in this way are multiplied term-by-term by the elements of the array A and the result is entered into a cell named Y, where the sample value of the output signal is accumulated. Below is the text of the transversal digital filtering program:

    Impulse response. Let's return to formula (15.59) and calculate the impulse response of the transversal digital filter by performing the inverse z-transformation. It is easy to see that each term of the function makes a contribution equal to the corresponding coefficient, shifted by positions towards the delay. So here

    This conclusion can be reached directly, considering the block diagram of the filter (see Fig. 15.7) and assuming that a "single pulse" is fed to its input.

    It is important to note that the impulse response of a transversal filter contains a finite number of terms.

    Frequency response.

    If we change the variable in formula (15.59), then we get the frequency transmission coefficient

    With a given sampling step A, a wide variety of frequency response forms can be realized by appropriately selecting the filter weights.

    Example 15.4. Investigate the frequency characteristics of a second-order transverse digital filter that averages the current value of the input signal and two previous samples according to the formula

    The system function of this filter

    Rice. 15.8. Frequency characteristics of the transversal DF from example 15.4: a - frequency response; b - PFC

    whence we find the frequency transmission coefficient

    Elementary transformations lead to the following expressions for the frequency response in the phase response of this system:

    The corresponding graphs are shown in Fig. 15.8, a, b, where the value is plotted along the horizontal axes - the phase angle of the sampling interval at the current frequency value.

    Suppose, for example, that, that is, there are six samples per one period of the harmonic input oscillation. In this case, the input sequence will have the form

    (the absolute values ​​of the samples do not matter, since the filter is linear). Using algorithm (15.62), we find the output sequence:

    It can be seen that a harmonic output signal of the same frequency as at the input corresponds to it, with an amplitude equal to the amplitude of the input oscillation and with an initial phase shifted by 60 ° towards the delay.

    Recursive DFs.

    This kind digital filters is characterized by the fact that for the formation of the output count, the previous values ​​of not only the input and output signals are used:

    (15.63)

    and the coefficients that determine the recursive part of the filtering algorithm are not equal to zero at the same time. To emphasize the difference between the structures of the two types of digital filters, transversal filters are also called non-recursive filters.

    System function of recursive digital function.

    Performing the z-transformation of both sides of the recurrence relation (15.63), we find that the system function

    describing the frequency properties of a recursive DF, has poles on the z-plane. If the coefficients of the recursive part of the algorithm are real, then these poles either lie on the real axis or form complex conjugate pairs.

    Structural diagram of a recursive digital filter.

    In fig. 15.9 shows a diagram of the algorithm of calculations carried out in accordance with the formula (15.63). Top part structural diagram corresponds to the transverse (non-recursive) part of the filtering algorithm. For its implementation, in the general case, large-scale blocks (multiplication operations) and memory cells are required in which input samples are stored.

    The lower part of the block diagram corresponds to the recursive part of the algorithm. It uses successive output values, which are shifted from cell to cell during filter operation.

    Rice. 15.9. Structural diagram of a recursive digital filter

    Rice. 15.10. Structural diagram of the canonical recursive digital function of the 2nd order

    The disadvantage of this implementation principle is the need for a large number of memory cells, separately for the recursive and non-recursive parts. The canonical schemes of recursive digital functions are more perfect, in which the minimum possible number of memory cells is used, equal to the largest of the numbers. As an example, Fig. 15.10 shows a block diagram of the second-order canonical recursive filter, which corresponds to the system function

    In order to make sure that this system implements a given function, consider an auxiliary discrete signal at the output of the adder 1 and write down two obvious equations:

    (15.67)

    Performing the -transformation of equation (15.66), we find that

    On the other hand, in accordance with the expression (15.67)

    Combining relations (15.68) and (15.69), we arrive at the given system function (15.65).

    Stability of recursive digital functions.

    A recursive digital function is a discrete analogue of a dynamic feedback system, since the values ​​of its previous states are stored in memory cells. If some initial conditions are given, that is, a set of values, then in the absence of an input signal, the filter will form elements of an infinite sequence that plays the role of free oscillations.

    A digital filter is called stable if the free process arising in it is a non-increasing sequence, i.e., the values ​​at do not exceed some positive number M, regardless of the choice of the initial conditions.

    Free oscillations in a recursive digital function based on algorithm (15.63) are a solution to the linear difference equation

    By analogy with the principle of solving linear differential equations we will seek a solution to (15.70) in the form of an exponential function

    with a still unknown value. Substituting (15.71) into (15.70) and canceling by a common factor, we see that a is the root of the characteristic equation

    Based on (15.64), this equation exactly coincides with the equation that is satisfied by the poles of the system function of the recursive CF.

    Let the root system of equation (15.72) be found. Then the general solution of the difference equation (15.70) will have the form

    The coefficients must be selected so that the initial conditions are satisfied.

    If all poles of the system function, i.e., the numbers do not exceed one in absolute value, being located inside the unit circle centered at a point, then on the basis of (15.73) any free process in the CF will be described by terms of decreasing geometric progressions and the filter will be stable. It is clear that only stable digital filters can be practically applied.

    Example 15.5. Investigate the stability of a recursive 2nd order digital filter with a system function

    Characteristic equation

    has roots

    The curve described by the equation on the coefficient plane is the boundary above which the poles of the system function are real and below which they are complex conjugate.

    For the case of complex conjugate poles, therefore, one of the boundaries of the stability region is straight line 1.

    Rice. 15.11. Stability region of the 2nd order recursive filter (the poles of the filter are complex conjugate in the region marked with color)

    Considering the real poles at, we have the stability condition in the form

    This type of digital filters is characterized by the fact that for the formation i th output count the previous values ​​of not only the input, but also the output signals are used (filtering algorithm):

    and the coefficients (b (, b 2, ..., b n _ Ts, defining the recursive part of the filtering algorithm, are not equal to zero at the same time.

    Let's write down system function recursive CF. After completing z- transformation of both sides of the recursive relation (7.28), we find that the system function describing the frequency properties of the recursive CF has the form

    It follows from this expression that the system function of the recursive CF has on the z-plane (t-1) zeros and (NS- 1) poles. If the coefficients of the recursive part of the algorithm are real, then the poles either lie on the real axis or form complex conjugate pairs.

    Let's calculate impulse response recursive CF. A characteristic feature that distinguishes a recursive DF from a non-recursive DF is that due to the presence feedback its impulse response has the form of an infinitely extended sequence. Therefore, often recursive filters are called IIR filters (Infinite Impulse Response Filters). Let us show this using the example of the simplest 1st order filter described by the system function

    As you know, the impulse response can be found using the inverse ^ -transformation of the system function. Using the formula for the inverse ^ -transformation, we find the mth term in the sequence }