1. Introduction
The term spectral observer was proposed by Hostetter in his pioneering work [
1] to name the algorithm that permits the recursive calculation of the Fourier Transform (FT) of a band-limited signal via state estimation. Since the presentation of such a work, several designs of spectral observers with improved features have been proposed either to deal with noise [
2], disturbances, lack of data [
3] or to estimate other parameters such as frequency [
4]. The main goals of a spectral observer are both the estimation of a given signal and the transformation of such a signal to the frequency domain by means of the recursive identification of the coefficients of a Fourier series [
5]. The estimation of a signal in the context of this work means to find the coefficients of a linear combination of functions—sines a cosines functions in our case—that approximates a signal of interest such that it can be reconstructed [
6]. Spectral observers are useful in a wide number of applications, e.g., for determining the source of harmonic pollution in power systems [
7], for the simulation of the sea surface [
8], for fault diagnosis in motors [
9,
10] or in vibrating structures, such as aerospace and mechanical structures, marine structures, buildings, bridges and offshore platforms.
A spectral observer can be catalogued as an online algorithm to compute the Fourier Transform (FT) during a time window which slides along the signal, i.e., an algorithm to compute the Short Time Fourier Transform (STFT). Therefore, a spectral observer can be used for the time-frequency analysis of frequency variant signals.
The observer that we propose in this contribution is designed from a dynamical system which is constructed from the N derivatives of a n-th order Fourier series.
To perform the estimation, the observer solely requires: (1) The measurement of the signal to be approximated, , which actually is used to compute the observation error , where is the observer output, (2) A frequency step , where T is a predefined period. The estimation provided by the observer are both the reconstruction of the original signal and the Fourier coefficients to compute the signal frequency components.
This paper is organized as follows:
Section 2 presents the core of the proposed method which is the formulation of the spectral observer from the Fourier series.
Section 3 presents some examples with test results of the proposed method utilized in different applications. In
Section 4 the main results are discussed. Finally, in
Section 5 some concluding thoughts are given.
2. The Proposed Method
To construct the proposed observer, we formulate a dynamical synthetic system in state space representation by considering, firstly, that a given signal expressed as
can be approximated by a Fourier series, and secondly, that the Fourier series is the first state of the system and the rest of the states are the
N first-order derivatives of the Fourier series expressed by Equation (
1), where
n is the series order.
where
are the Fourier coefficients and
is the fundamental angular frequency of the signal to be estimated.
In this work, we assume that the signal
to be approximated has not a constant component (offset) or that this offset is removed by an online algorithm prior to be processed by the spectral observer. For this reason, we remove the term
from Equation (
1) such that the series for approximating the time function
can be expressed as follows
If the order of the Fourier series is
, we need to formulate a dynamical system with
states, each one to recover each coefficient (
and
). Thus, the two first states are the Fourier series and its first derivative.
where
are the states of the synthetic system. Consequently, the dynamical system that results from the change of coordinates, gives:
which basically is the dynamical model of a harmonic oscillator. Now, what happens if the order of the Fourier series increases? If the order increases to
, then
, since we need to recover four coefficients.
The dynamical system is then formulated as in Equation (
5) which, after some algebraic manipulations, it becomes
in
-coordinates.
By generalizing Equation (
5) for order
n, we obtain the following dynamical system:
where
,
and
are expressed by Equations (
8) and (
9), respectively.
Before presenting the state observer for system (
7), it is necessary to analyze its observability conditions. A dynamical system is said to be observable if it is possible to determine its initial state by knowledge of the input and output over a finite time interval. In this way, a state observer or state estimator is a system that estimates the internal states of a system from the measurement of its inputs and outputs. To verify is a linear systems is observable, the observability rank condition can be used, which is defined in the net lines.
Observability rank condition. A system
is said to satisfy the observability rank condition if
where
N is the state dimension of (
10) and
is the observability matrix defined as
Thus, according to the definition, the observability matrix for system (
7), which in fact can be set as system (
10) with
and
, has full rank. Therefore, since system (
7) is observable, a spectral observer can be designed as follows:
where “
” means estimation,
is the estimated signals and
A is given by (
12), with constant coefficients expressed by
. The gain of the state observer
K, involved in the correction term of Equation (
13), can be calculated as
, where
S is the unique solution of the following algebraic Lyapunov equation:
and
is a parameter that can be used to tune the convergence rate of the observer. A numerical solution for solving Equation (
14) for a particular but common case is provided in [
11].
The Fourier coefficients can be recovered from the new coordinates by the relation
, where
and
Notice that
,
and
. Check
Figure 1 to see a schema of the estimation.
Before presenting some possible applications of the spectral observer it is important to highlight an important point. Notice that matrix A of the spectral observer depends on the fundamental frequency . This means that this variable must be known. In case we want to approximate a periodic signal with a known fundamental frequency, we just need to use it in matrix A. In case we want to fit a periodic signal with unknown fundamental frequency or a non-periodic signal, we must assume, as in the Fourier Transform deduction from the Fourier series, that the period of the signal tends to infinity, which means that the fundamental frequency tends to zero. As a consequence of this assumption, should be chosen sufficiently small or according to the desired precision in the recovery of the frequency components. In other words is the frequency step that determines the resolution of the discretized frequency domain, such that we have to choose thinking how close we want the frequency components.
3. Application Examples
This section presents five examples of possible applications of the spectral observer, which were conceived such that the reader can be able to reproduce them.
3.1. Example 1: A Simple Example
Let be the signal
. It is obvious that the series order to reproduce the signal is
, then the order of system (
7) for the conception of the observer should be
.
Figure 2 shows the estimation of the coefficients that was performed by the observer with a gain
, which actually was initialized with
. The step time to perform the estimation in Simulink was
[s] and the used solver was ODE3.
3.2. Example 2: Reconstruction of Basic Signals
This example aims to show the estimation of the coefficients for basic signals such as square and sawtooth waves. The first signal to be estimated is a square wave with angular frequency
[rad/s]. The observer was tuned with
. The order of the series was set
, i.e.,
. The frequency step was set
[rad/s]. The step time to perform the estimation in Simulink was set
[s] and the used solver was ODE3.
Figure 3 shows the signal reconstruction performed by the spectral observer and the estimated coefficients. Firstly, notice that the coefficients do not converge towards a constant value; the reason for this is the number of coefficients used to approximate the signal, which is not enough to represent each harmonic that composes it. Even though the coefficients are not constant, the signal is estimated. Notice too that all the coefficients change abruptly at each discontinuity. This feature can be used for edge detection as will be seen in the next example.
Both the observer and conditions that were used to reconstruct the square wave were used to reconstruct the sawtooth signal shown in
Figure 4. Notice that the convergence time is less than one second and the coefficients become greater at the discontinuities.
To end this example, we made several simulations to show how the parameter
determines the convergence period of the estimation.
Figure 5 shows the estimation of the square signal with different values of
. Notice that the bigger its value, the faster is the convergence.
3.3. Example 3: Edge Detection by Using the Fourier Coefficients
Edge detection and the detection of discontinuities are important in many fields. In image processing, for example, one often needs to determine the boundaries of the items of which a picture is composed, [
12] or in applications that utilize time-domain reflectometry (TDR), which is a measurement technique used to determine the characteristics of transmission lines by observing reflected waveforms. TDR analysis begins with the propagation of a step or impulse of energy into a system and the subsequent observation of the energy reflected by the system. By analyzing the magnitude, duration and shape of the reflected waveform, the nature of the transmission system can be determined. TDR is a common method used to localize faults in transmission lines—such a leaks in pipelines or faults with small impedance in wires—because faults in transmission lines cause discontinuities in the reflected waveforms. For this reason, methodologies to detect discontinuities are required in order to localize the nature and position of the faults.
In order to shows how the spectral observer (
13) can be used to detect discontinuities in a function, we present the following example: Let us consider
, which is plot in
Figure 6a. The aim of this test is to detect the discontinuities in the principal signal with period
[s]. To identify the discontinuities, the coefficients provided by the spectral observer are used to calculate the following indicator function:
The observer to perform the estimation was tuned with . The order of the series was set , i.e., . The frequency step was set [rad/s]. The step time to perform the estimation in Simulink was set [s] and the used solver was ODE3.
Figure 6a shows
and its reconstruction
.
Figure 6b shows the index
and
that becomes greater at the discontinuities indicating where they are.
3.4. Example 4: Fitting Complex Signal: The Bitcoin Price
Bitcoin is the longest running and best known cryptocurrency in the world. It was released as open source in 2009 by the anonymous Satoshi Nakamoto. Bitcoin serves as a decentralized medium of digital exchange, with transactions verified and recorded in a public distributed ledger (the blockchain) without the need for a trusted record keeping authority or central intermediary. Hereafter, we will use the proposed spectral observer for fitting the historical Bitcoin market close data every 1000 [min]. The records were downloaded from the website:
https://www.kaggle.com/neelneelpurk/bitcoin/data.
The observer to perform the estimation was tuned with . The order of the series was set , i.e., . The frequency step was set [rad/s]. The step time to perform the estimation in Simulink was set [s] and the used solver was ODE8.
In
Figure 7, the Bitcoin fitting performed by the spectral observer is shown.
Figure 8 shows the estimated coefficients which are not constant and look as if they were enveloped by exponential functions. In order to have a model that represents the behavior of the Bitcoin in the specified interval, we can fit each coefficient by means of polynomials after calculating the natural logarithm of each one. In
Figure 9,
is plotted versus a cubic polynomial calculated to interpolate it.
We can perform the same procedure for each coefficient to obtain a series with the following form:
where
,
,
,
,
,
,
,
are the coefficients of the polynomial that approximates the natural logarithms of the coefficients.
3.5. Example 5: Estimation of the Input Force on a Duffing Oscillator
One of the advantages of the proposed spectral observer is its structure, which is a chain of integrators expressed in state-space representation. Such a structure permits to couple the observer to dynamic models, also expressed in state variables, that represent physical systems for control or estimation purposes. With this in mind, we present an example to show how the spectral observer can be coupled to the model of a given system, even with nonlinear structure such as the Duffing oscillator, in order to estimate an exogenous input affecting its behavior.
The Duffing oscillator is expressed by the following equation:
where
is the displacement, which is assumed as available in this example,
is the velocity and
is the acceleration. In addition,
,
and
are parameters, which in this example are assumed to be known. Finally,
is an external force, which is unknown and can be estimated by using our proposed observer. To achieve this goal, the following steps need to be executed.
Step 1. Equation (
18) must be set in state-space representation. To execute this step, we define
and
as the state variables, such that we obtain the following equation system:
If the Liénard transform [
13] is applied to system (
18) in order to set it in a more appropriate form for estimation purposes [
14], it becomes
Step 2. Since
is unknown and needs to be estimated, we propose its estimation by using a spectral observer with
. Therefore, we coupled in cascade equation system (
18) with equation system (
4) as follows:
where
, i.e., it is the force to be estimated.
System (
21) can be set in the following form:
which according to [
15] is uniformly observable. Therefore, a state observer expressed as
can be designed for system (
22), where
K can be calculated by means of Equation (
14).
For the simulation, the paramaters of the Duffing oscillator were set:
,
and
; and their initial conditions were set
. The force applied to the oscillator was
. The observer was tuned with
,
[rad/s] and their initial conditions were fixed as
. Finally, the used solver was ODE 3 with a step time
[s]. The results of the estimation are shown in
Figure 10, which particularly presents a comparison between the force and its estimation. Notice that the estimation converges to the force in 1 [s].
4. Comparative Analysis Vis-à-Vis the STFT
A spectral observer can be used to determine the frequency content of local sections of a signal as it changes over time. The classic technique for performing this task is the Short Time Fourier Transform, which is the Fourier Transform with a suitable chosen windowing function. Ensuing, we present an example to compare the results of using the STFT with the results provided by the spectral observer. For this purpose, we used the MATLAB
codes created by Hristo Zhivomirov to compute STFT and its inverse [
16]. The signal analyzed was
sampled at 1000 [Hz]. To compute the STFT by using the code of Zhivomirov, the following parameters were set:
[s] as the window length,
[s] as the hop size and
as the number of FFT points. The tuning of the spectral observer was done by setting
,
,
[rad/s] and
. The solver used for the numerical solution was ODE4 (Runge-Kutta) with a fixed step size
[s]. The spectrograms that were produced by the STFT and the spectral observer, respectively, are presented in
Figure 11. To construct the observer spectrogram, we computed de magnitude of each harmonic by means of the following equation:
On the one hand, since , the resulting vector containing the magnitude of each harmonic was . On the other hand, since the angular frequency step was chosen [rad/s], the resulting frequency vector was [Hz]. Then, the spectrogram resulted of plotting f versus A.
Notice that the spectrogram generated by using the spectral observer presents a better frequency resolution with respect to the spectral observer. This fact can be better appreciated in
Figure 12. However, this does not mean that the observer’s performance is superior, since it is well known that the frequency resolution can be improved by widening the time window length of the STFT, even if this widening implies a decreasing of the time resolution. In the case of the spectral observer, the frequency resolution is adjusted by manipulating the parameter
.
It is necessary to point out here that both the frequency resolution and the time resolution do not only depend on the parameters and , also the parameters h y used in the STFT algorithm and and n used in the spectral observer, play an important factor; nevertheless, the adjustment of these parameters directly affects in the computational burden and the amount of data to be processed.
5. Results and Discussion
We have introduced an algorithm to reconstruct signals at the same time that their frequency components are calculated: a new spectral observer. In order to show its applicability, we have presented some examples, which in addition, have allowed us to glimpse some advantages and disadvantages of its use. Firstly, we found the following benefits: (1) The structure of the observer, as a chain of integrators, is very adequate for control and parameter estimation purposes; (2) The signal is progressively incorporated at each iteration; (3) The operations required for the observer implementation are with real numbers, which simplifies its programming in single-board computers; (4) The gain of the observer can be easily computed by means of a simple numerical algorithm; (5) The convergence of the observer is exponential, this means that the convergence period can be adjusted by means of a unique parameter
, which is a clear advantage with respect to other well-known algorithms such as the proposed in [
17], where the convergence period cannot be manipulated by a unique parameter. However, there are some drawbacks that we have found for the proposed observer. (1) The computational cost can be high for a small frequency resolution; (2) The algorithm must be complemented with a methodology to choose
and
in order to obtain the best estimation.
To conclude the discussion, it is necessary to emphasize that the spectral observer is an algorithm that, like the STFT, can be used to perform a frequency-time analysis of a frequency varying signal by computing the Fourier Transform (FT) during time intervals. However, there are some differences to remark. (a) The STFT requires operations with complex numbers, the spectral observer does not; (b) The spectral observer computes the FT and its inverse at the same time, which is a clear bonus, because in case of using a recursive STFT we only get the FT, if we want to recover the reconstructed signal, we must compute the Inverse Short Fourier Transform.