1 Introduction

The dynamic frequency characteristics of servo systems are important evaluation indicators. Currently, the sinusoidal point-by-point sweep signal is often adopted in the testing of frequency characteristics of carrier servo systems (referred to as the sweep frequency method). To calculate frequency characteristics from test data, the frequently used methods are fast Fourier transform, correlation analysis, power spectrum estimation, and least squares fitting [1,2,3]. The noise suppression and anti-interference capabilities of frequency characteristic estimation algorithms directly affect the accuracy of test results. The existing researches on the above algorithms focus more on the application of the algorithms, but less on the applicability, robustness, and accuracy of the algorithms [4, 5]. The followings are the analysis and summarization of the principles and implementations of fast Fourier transform, correlation analysis, power spectrum estimation, and least squares fitting.

2 Testing Sweep Signal of Servo System

Servo systems are highly complex, and the dynamic characteristics of the estimation mechanism also affect the output data. During the test, the output signal is inevitably susceptible to various factors. For instance, when the input signal is a sinusoidal signal with a frequency of 14.32 Hz and an amplitude of 0.4°, the output signal of the servo system is as shown in Fig. 1, and the spectrum is as shown in Fig. 2. The output signal is heavily affected by noise, and its sinusoidal form cannot be identified; over time, this output signal is offset to zero by different degrees, the drift characteristics are complex, and it is difficult to remove the influence of the drift by a simple method; the resonance has obvious influence, that is, the resonance frequency component at 30 Hz is large and is close to the highest frequency (25 Hz) of the test sweep, so its influence on the test results cannot be ignored. For the severely distorted output signal, after filtering, removing the mean value and detrending, it still cannot be evenly distributed on both sides of the zero position with small distortion, as shown in Figs. 3 and 4.

Fig. 1
figure 1

Sweep signal of a servo system (14.32 Hz)

Fig. 2
figure 2

Sweep signal spectrum of a servo system (14.32 Hz)

Fig. 3
figure 3

Servo system sweep signal after debugging and detrending (14.32 Hz)

Fig. 4
figure 4

Servo system open-loop sweep signal after debugging and detrending (30 Hz)

3 Calculation of Frequency Characteristic

3.1 Fast Fourier Transform

Fast Fourier transform can be used to quickly obtain the signal spectrum. The principle of using fast Fourier transform to obtain the frequency characteristics of the system is simple, that is, using the fast Fourier transform algorithm to calculate the spectrum of the input and output signals, respectively, the quotient of the amplitude of the spectrum, and the phase difference to obtain the frequency characteristics of the system.

A discrete signal sequence is represented as \(x(n)\), where \(n = 0,1, \ldots ,L - 1\), and the sampling frequency is \(F_{s}\). The Fourier transform of the signal is expressed as \(X_{\text{FFT}} (k)\), where \(k = 0,1, \ldots ,L - 1\). The results of the discrete Fourier transform are distributed around discrete point. The following formula can be used to approximate the Fourier transform result of \(x(n)\) at any frequency \(\omega\) (\(\omega < 2\pi F_{s}\)).

$$X(j\omega ) = X_{\text{FFT}} \left( {{\text{round}}\left( {\frac{\omega L}{{2\pi F_{s} }}} \right)} \right)$$
(1)

Here, \({\text{round}}( \cdot )\) is a rounding-off function; \(2\pi F_{s} /L\) represents the frequency resolution in the spectrum in \({\text{rad/s}}\). Let the FFT result of the system output signal be \(Y_{\text{FFT}} (k)\), then the frequency characteristic of the system can be written as:

$$G(j\omega ) = \frac{Y(j\omega )}{X(j\omega )} = \frac{{Y_{\text{FFT}} \left( {{\text{round}}\left( {\frac{\omega L}{{2\pi F_{s} }}} \right)} \right)}}{{X_{\text{FFT}} \left( {{\text{round}}\left( {\frac{\omega L}{{2\pi F_{s} }}} \right)} \right)}}$$
(2)

Usually, the frequency point \(\omega\) of interest is not exactly an integer multiple of \(2\pi F_{s} /L\). When \(2\pi F_{s} /L\) is relatively large, the error caused by the approximation in Eq. (1) may have a great impact on the final result. Therefore, fast Fourier transform should be used to obtain a frequency characteristic with sufficient accuracy, and under the fixed sampling frequency, sufficient data length must be guaranteed.

3.2 Correlation Analysis

In order to facilitate the description, the following formula for the correlation analysis of the continuous system is derived. Set the input signal of the system to \(x(t) = A_{x} \sin (\omega t)\), then, theoretically, the output signal of the linear system can be expressed as \(y(t) = A\,\sin (\omega t + \theta )\). The output signal of the actual system should include noise, harmonics, and drift interference, to retain generality. The actual output signal can be written as

$$y(t) = A_{0} + \sum\limits_{n = 1}^{ + \infty } {A_{n} \sin (n\omega t + \theta_{n} )} + r(t)$$
(3)

Here, \(r(t)\) is the noise signal. To calculate the frequency characteristics of the system at \(\omega\), only the amplitude and phase of the fundamental component are required. Expand Eq. (3) and get:

$$\begin{aligned} y(t) & = A_{0} + \sum\limits_{n = 1}^{ + \infty } {A_{n} \sin (n\omega t)\cos \theta_{n} } + \sum\limits_{n = 1}^{ + \infty } {A_{n} \cos (n\omega t)\sin \theta_{n} } + r(t) \\ & = A_{0} + \sum\limits_{n = 1}^{ + \infty } {a_{n} \sin (n\omega t)} + \sum\limits_{n = 1}^{ + \infty } {b_{n} \cos (n\omega t)} + r(t) \\ \end{aligned}$$
(4)

Here, \(a_{n} = A_{n} \cos \theta_{n}\), \(b_{n} = A_{n} \sin \theta_{n}\). Respectively calculate the cross-correlation function \(P\) of \(y(t)\) and \(\sin (\omega t)\), and the cross-correlation function \(Q\) of \(y(t)\) and \(\cos (\omega t)\) (The time difference is 0).

$$P = \frac{1}{N}\int\limits_{0}^{\text{NT}} {y(t) \cdot \sin (\omega t)} {\text{d}}t$$
(5)
$$Q = \frac{1}{N}\int\limits_{0}^{\text{NT}} {y(t) \cdot \cos (\omega t)} {\text{d}}t$$
(6)

Here, \(N\) is a positive integer that represents the number of fundamental cycles to be integrated; \(T\) is the fundamental period. By plugging Eq. (4) into Eq. (5), the following equation is obtained:

$$\begin{aligned} P & = \frac{1}{N}\left[ {A_{0} \int\limits_{0}^{\text{NT}} {\sin (\omega t){\text{d}}t} + a_{1} \int\limits_{0}^{\text{NT}} {\sin^{2} (\omega t){\text{d}}t} + b_{1} \int\limits_{0}^{\text{NT}} {\sin (\omega t)\cos (\omega t){\text{d}}t} } \right. \\ & \quad + \cdots + a_{n} \int\limits_{0}^{\text{NT}} {\sin (\omega t)\sin (n\omega t){\text{d}}t} + b_{n} \int\limits_{0}^{\text{NT}} {\sin (\omega t)\cos (n\omega t){\text{d}}t} \\ & \left. {\quad + \cdots + \int\limits_{0}^{\text{NT}} {\sin (\omega t)r(t){\text{d}}t} } \right] \\ \end{aligned}$$

According to the orthogonality of the trigonometric function, the following relationships hold in the above equations.

$$A_{0} \int\limits_{0}^{\text{NT}} {\sin (\omega t){\text{d}}t} = 0$$
$$a_{n} \int\limits_{0}^{\text{NT}} {\sin (\omega t)\sin (n\omega t){\text{d}}t} = 0$$
$$b_{n} \int\limits_{0}^{\text{NT}} {\sin (\omega t)\cos (n\omega t){\text{d}}t} = 0$$

And according to the distribution characteristics of the actual noise signal, it can be considered that the following relationship holds:

$$\int\limits_{0}^{\text{NT}} {\sin (\omega t)r(t){\text{d}}t} = 0$$

Therefore, after simplification, the following equation is obtained:

$$P = \frac{1}{N}a_{1} \int\limits_{0}^{\text{NT}} {\sin^{2} (\omega t){\text{d}}t} = \frac{{a_{1} }}{2N}\int\limits_{0}^{\text{NT}} {(1 - \cos 2\omega t){\text{d}}t} = \frac{{a_{1} T}}{2} = \frac{T}{2}A_{1} \cos \theta_{1}$$
(7)

Similarly, by plugging Eq. (4) into Eq. (6), after derivation, the following equation is obtained:

$$Q = \frac{{b_{1} T}}{2} = \frac{T}{2}A_{1} \sin \theta_{1}$$
(8)

According to Eqs. (7) and (8), the following equations are obtained:

$$A_{1} = \frac{2}{T}\sqrt {P^{2} + Q^{2} }$$
(9)
$$\theta_{1} = \arctan \left( {\frac{Q}{P}} \right)$$
(10)

Then, the frequency characteristic of the system at frequency \(\omega\) can be expressed as

$$G_{\omega } = \frac{{A_{1} }}{{A_{x} }}\angle \theta_{1}$$
(11)

If this method is applied to discrete signals, set the system input signal as \(x(n)\) and the output signal as \(y(n)\), where \(n = 0,1,2, \ldots ,L - 1\), and the data sampling period is \(T_{s}\). After substituting the integral operations in Eqs. (5) and (6) with summation operations, the following equations are obtained:

$$P = \frac{{T_{s} }}{N}\sum\limits_{n = 0}^{{{\text{NT}}/T_{s} }} {y(n) \cdot \sin (\omega t_{n} )}$$
(12)
$$Q = \frac{{T_{s} }}{N}\sum\limits_{n = 0}^{{NT/T_{s} }} {y(n) \cdot \cos (\omega t_{n} )}$$
(13)

Here, \(t_{n} = nT_{s}\). By referring to Eqs. (9)–(13), the frequency characteristics of discrete systems can be calculated. In principle, this method can effectively eliminate harmonic interference and constant value drift in the frequency sweep signal and is robust to noise and has a small computation load. This method is widely used in test software of frequency characteristics.

3.3 Power Spectrum Estimation

Set the input and output signals as sequences \(x(n)\) and \(y(n)\), respectively, where \(n = 0,1,2, \ldots ,L - 1\). Let \(x(n)\) and \(y(n)\) be the wide stationary random signals traversed by states and have a mean of zero. The following formula is often used in engineering to calculate the autocorrelation function of the input signal and the cross-correlation function of input and output signals.

$$R_{xx} (l) = \frac{1}{L}\sum\limits_{n = 1}^{L - \left| l \right|} {x(n)x(n + l),l = 0, \pm 1, \pm 2, \ldots , \pm (L - 1)}$$
(14)
$$R_{xy} (l) = \frac{1}{L}\sum\limits_{n = 1}^{L - \left| l \right|} {x(n)y(n + l),l = 0, \pm 1, \pm 2, \ldots , \pm (L - 1)}$$
(15)

Perform Fourier transform on Eq. (14) to obtain the self-power spectrum of the input signal.

$$\begin{aligned} M_{xx} (\omega ) & = \sum\limits_{l = - (L - 1)}^{L - 1} {R_{xx} (l){\text{e}}^{ - j\omega l} } \\ & = \frac{1}{L}\sum\limits_{l = - (L - 1)}^{L - 1} {\sum\limits_{n = 1}^{L - \left| l \right|} {x(n)x(n + l)} {\text{e}}^{ - j\omega l} } \\ & = \frac{1}{L}\sum\limits_{l = - (L - 1)}^{L - 1} {x(n) * x(n){\text{e}}^{ - j\omega l} } \\ & = \frac{1}{L}X(j\omega ) \cdot X^{ * } (j\omega ) \\ \end{aligned}$$
(16)

In the above formula, \(*\) represents convolution. Similarly, perform Fourier transform on the Eq. (15) to obtain the cross-power spectrum of the input and output signals.

$$M_{xy} (\omega ) = \frac{1}{L}X(j\omega ) \cdot Y^{ * } (j\omega )$$
(17)

Then, the frequency characteristics of the system can be obtained:

$$G(j\omega ) = \frac{Y(j\omega )}{X(j\omega )} = \frac{{M_{xy} }}{{M_{xx} }}$$
(18)

An important step in using the power spectrum method to obtain the frequency characteristics of the system is the estimation of the self-power spectrum of the input data and the cross-power spectrum of the input and output data. The above derivation process theoretically illustrates the feasibility of calculating the frequency characteristics of the system with power spectrum estimation. However, during actual operations, there are large power spectrum errors in the signal directly calculated with the definition and there is poor smoothness in the calculation result. Therefore, in engineering applications, the signal power spectrum is often calculated with the periodogram method and Welch’s method [6].

3.4 Least Squares Fitting

Set the input signal of the system to the sequence \(x(n) = A_{x} \sin (\omega nT_{s} ),n = 0,1,2, \ldots ,L - 1\). Here, \(T_{s}\) is the sampling period. The common least squares fitting assumes that the system output is:

$$y(n) = A_{y} \sin (\omega nT_{s} + \theta ) = A_{y} \sin (\omega nT_{s} )\cos \theta + A_{y} \cos (\omega nT_{s} )\sin \theta$$
(19)

The above formula does not take into account the complex drift interference of the output signal, and the error is large when the above formula is used to process the signals shown in Figs. 1 and 4.

$$\begin{aligned} y(n) & = k_{0} + k_{1} nT_{s} + k_{2} (nT_{s} )^{2} + \cdots + k_{N} (nT_{s} )^{N} + A_{y} \sin (\omega nT_{s} + \theta ) \\ & = k_{0} + k_{1} nT_{s} + k_{2} (nT_{s} )^{2} + \cdots + k_{N} (nT_{s} )^{N} + A_{y} \sin (\omega nT_{s} )\cos \theta \\ & \quad + A_{y} \cos (\omega nT_{s} )\sin \theta \\ \end{aligned}$$
(20)

Here, \(N\) represents the highest order of drift interference. After replacing \(nT_{s}\) with \(t_{n}\), and writing Eq. (20) as a matrix, the following equation holds.

$$y(n) = \varvec{\varphi }_{n} \cdot \varvec{K}$$
(21)

Here,

$$\varvec{\varphi }_{n} = [\begin{array}{*{20}l} 1 \hfill & {t_{n} } \hfill & {t_{n}^{2} } \hfill & \cdots \hfill & {t_{n}^{N} } \hfill & {\begin{array}{*{20}c} {\sin (\omega t_{n} )} & {\cos (\omega t_{n} )} \\ \end{array} } \hfill \\ \end{array}]$$
$$\varvec{K} = [\begin{array}{*{20}l} {k_{0} } \hfill & {k_{1} } \hfill & {k_{2} } \hfill & \cdots \hfill & {k_{N} } \hfill & {\begin{array}{*{20}c} {A_{y} \cos \theta } & {A_{y} \sin \theta } \\ \end{array} } \hfill \\ \end{array}]^{\text{T}}$$

Define the output matrix as:

$$\varvec{Y} = [\begin{array}{*{20}l} {y(0)} \hfill & {y(1)} \hfill & {y(2)} \hfill & \cdots \hfill & {y(L - 1)} \hfill \\ \end{array} ]^{\text{T}}$$

Here, \(L\) is the length of the input and output sequence. Define the input matrix as:

$$\varvec{\varPhi}= \left[ {\begin{array}{*{20}c} {\varvec{\varphi }_{0} } \\ {\varvec{\varphi }_{1} } \\ \vdots \\ {\varvec{\varphi }_{L - 1} } \\ \end{array} } \right] = \left[ {\begin{array}{*{20}c} 1 & {t_{0} } & {t_{0}^{2} } & \cdots & {t_{0}^{N} } & {\sin (\omega t_{0} )} & {\cos (\omega t_{0} )} \\ 1 & {t_{1} } & {t_{1}^{2} } & \cdots & {t_{1}^{N} } & {\sin (\omega t_{1} )} & {\cos (\omega t_{1} )} \\ \vdots & \vdots & \vdots & \ddots & \vdots & \vdots & \vdots \\ 1 & {t_{L - 1} } & {t_{L - 1}^{2} } & \cdots & {t_{L - 1}^{N} } & {\sin (\omega t_{L - 1} )} & {\cos (\omega t_{L - 1} )} \\ \end{array} } \right]$$
(22)

Then, the following relationship holds:

$$\varvec{Y} =\varvec{\varPhi}\cdot \varvec{K}$$
(22)

Under the least squares’ criterion, the solution of Eq. (23) is:

$$\varvec{K} = \left( {\varvec{\varPhi}^{\text{T}}\varvec{\varPhi}} \right)^{ - 1}\varvec{\varPhi}^{\text{T}} \varvec{Y}$$
(23)

Then, the frequency characteristics of the system at the frequency \(\omega\) can be expressed as:

$$G_{\omega } = \frac{{A_{y} }}{{A_{x} }}\angle \theta$$
(24)

In engineering, it is generally considered that the least squares method has the highest processing accuracy. The above fitting method is an improvement on the traditional least squares fitting. It has the advantages of traditional least squares method, i.e., the robustness to noise and resonance interference, and can process signals with complex drift characteristics. This method can improve the data processing accuracy of point-by-point sine sweep.

When the complex drift interference of the output signal is not considered, the traditional least squares fitting is used to obtain the frequency characteristics of the system, and the parameter vector is:

$$\varvec{K}^{{\prime }} = \left[ {\begin{array}{*{20}c} {K_{1} } & {K_{2} } \\ \end{array} } \right]^{\text{T}} = \left[ {\begin{array}{*{20}c} {A_{y} \cos \theta } & {A_{y} \sin \theta } \\ \end{array} } \right]^{\text{T}}$$
(25)

The output matrix corresponding to the output data of \(N\) cycles is:

$$\varvec{\varPhi}^{{\prime }} { = }\left[ {\begin{array}{*{20}c} {\sin (\omega t_{0} )} & {\cos (\omega t_{0} )} \\ {\sin (\omega t_{1} )} & {\cos (\omega t_{1} )} \\ \vdots & \vdots \\ {\sin (\omega t_{L - 1} )} & {\cos (\omega t_{L - 1} )} \\ \end{array} } \right]$$
(26)

Here, \(L = {\text{NT}}/T_{\text{s}}\). According to Eq. (24), the least squares solution can be written as:

$$\begin{aligned} \varvec{K}^{{\prime }} = \left[ {\begin{array}{*{20}c} {K_{1} } \\ {K_{2} } \\ \end{array} } \right] & = \left[ {\begin{array}{*{20}c} {\sum\limits_{n = 0}^{{\text{NT}/T_{s} }} {\sin^{2} (\omega t_{n} )} } & {\sum\limits_{n = 0}^{{\text{NT}/T_{s} }} {\sin (\omega t_{n} )\cos (\omega t_{n} )} } \\ {\sum\limits_{n = 0}^{{\text{NT}/T_{s} }} {\sin (\omega t_{n} )\cos (\omega t_{n} )} } & {\sum\limits_{n = 0}^{{\text{NT}/T_{s} }} {\cos^{2} (\omega t_{n} )} } \\ \end{array} } \right]^{ - 1}\varvec{\varPhi}^{{{\prime T}}} \varvec{Y} \\ & { = }\left( {\frac{N}{{T_{s} }}\left[ {\begin{array}{*{20}c} {\frac{T}{2}} & 0 \\ 0 & {\frac{T}{2}} \\ \end{array} } \right]} \right)^{ - 1}\varvec{\varPhi}^{{{\prime T}}} \varvec{Y} = \left[ {\begin{array}{*{20}c} {\frac{{2T_{s} }}{NT}\sum\limits_{n = 0}^{{\text{NT}/T_{s} }} {y(n)\sin (\omega t_{n} )} } \\ {\frac{{2T_{s} }}{NT}\sum\limits_{n = 0}^{{\text{NT}/T_{s} }} {y(n)\cos (\omega t_{n} )} } \\ \end{array} } \right] \\ \end{aligned}$$
(27)

The orthogonality of the trigonometric function is applied in the simplification process of the above formula. Comparing Eq. (28) with Eqs. (12) and (13), it is found that:

$$\varvec{K}^{{\prime }} = \left[ {\begin{array}{*{20}c} {K_{1} } \\ {K_{2} } \\ \end{array} } \right] = \frac{2}{T}\left[ {\begin{array}{*{20}c} P \\ Q \\ \end{array} } \right]$$
(28)

It is concluded that traditional least squares fitting is equivalent to correlation analysis when the data length is an integer multiple of periods. By comparing the two methods, it can be found that the solution formula of the correlation analysis method has a simpler expression form, so if the data is subject to less drift, it is recommended to use correlation analysis.

4 Conclusion

Fast Fourier transform, correlation analysis, power spectrum estimation, and least squares fitting can all derive the frequency characteristics with sufficient accuracy when the test equipment is of good quality and the measured object runs smoothly (in combination with appropriate filtering, removal of mean, and detrending). Since fast Fourier transform is the least robust under various interferences, fast Fourier transform is not recommended when the system is significantly affected by noise or resonance. Correlation analysis and least squares fitting have strong suppression ability, wide applicability, and high accuracy under various interferences. Therefore, when the signal is heavily disturbed by drift, it is recommended to use correlation analysis or least squares fitting. For the actual output signal of systems, the interference may be even more intense than the interference mentioned in this paper, or there are higher requirements for the frequency characteristic accuracy of the system, so the improved least squares fitting is recommended under such circumstances.