A Simple Spectral Observer

The principal aim of a spectral observer is twofold: the reconstruction of a signal of time via state estimation and the decomposition of such a signal into the frequencies that make it up. A spectral observer can be catalogued as an online algorithm for time-frequency analysis because is a method that can compute on the fly the Fourier Transform (FT) of a signal, without having the entire signal available from the start. In this regard, this paper presents a novel spectral observer with an adjustable constant gain for reconstructing a given signal by means of the recursive identification of the coefficients of a Fourier series. The reconstruction or estimation of a signal in the context of this work means to find the coefficients of a linear combination of sines a cosines that fits a signal such that it can be reproduced. The design procedure of the spectral observer is presented along with the following applications: (1) the reconstruction of a simple periodical signal, (2) the approximation of both a square and a triangular signal, (3) the edge detection in signals by using the Fourier coefficients, (4) the fitting of the historical Bitcoin market data from 1 December 2014 to 8 January 2018 and (5) the estimation of a input force acting upon a Duffing oscillator. To round out this paper, we present a detailed discussion about the results of the applications as well as a comparative analysis of the proposed spectral observer vis-à-vis the Short Time Fourier Transform (STFT), which is a well-known method for time-frequency analysis.


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, s(t), which actually is used to compute the observation error e(t) = s(t) − ŷ(t), where ŷ(t) is the observer output, (2) A frequency step ω = 2π/T, 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.

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 s(t) 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 a 0 , a 1 , b 1 , ..., a n , b n are the Fourier coefficients and ω is the fundamental angular frequency of the signal to be estimated.
In this work, we assume that the signal s(t) 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 a 0 from Equation (1) such that the series for approximating the time function s(t) can be expressed as follows If the order of the Fourier series is n = 1, we need to formulate a dynamical system with N = 2 states, each one to recover each coefficient (a 1 and b 1 ).Thus, the two first states are the Fourier series and its first derivative.
where ν i 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 n = 2, then N = 4, 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 N = 2n, A ω and A k 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
is said to satisfy the observability rank condition if ∀ν(t), rank (O(ν(t))) = N, where N is the state dimension of (10) and O(ν(t)) 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 C = [1, 0, ..., 0], has full rank.Therefore, since system ( 7) is observable, a spectral observer can be designed as follows: where " ˆ" means estimation, ŷ(t) is the estimated signals and A is given by ( 12), with constant coefficients expressed by γ i (ω).The gain of the state observer K, involved in the correction term of Equation ( 13), can be calculated as K = S −1 C T , 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 ĉk = Ω(t) ν(t), where ĉk = [ â1 b1 ... ân bn ] T and Notice that cos, sin and Γ n − 1. 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.

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.

Example 1: A Simple Example
Let be the signal s(t) = 4 cos (t) + sin (t) + 2 cos (2t) + 5 sin (2t).It is obvious that the series order to reproduce the signal is n = 2, then the order of system (7) for the conception of the observer should be N = 4. Figure 2 shows the estimation of the coefficients that was performed by the observer with a gain λ = 8, which actually was initialized with ν(0) = 0.The step time to perform the estimation in Simulink was ∆t = 0.005 [s] and the used solver was ODE3.

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 ω = 1 [rad/s].The observer was tuned with λ = 15.The order of the series was set n = 2, i.e., N = 4.The frequency step was set ω = 5 [rad/s].The step time to perform the estimation in Simulink was set ∆t = 0.01 [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.

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 s(t) = sign(sin (0.5t)) − 0.05sign(sin (2t)), which is plot in Figure 6a.The aim of this test is to detect the discontinuities in the principal signal with period T = 2 [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 λ = 15.The order of the series was set n = 2, i.e., N = 4.The frequency step was set ω = 1 [rad/s].The step time to perform the estimation in Simulink was set ∆t = 0.01 [s] and the used solver was ODE3. Figure 6a shows s(t) and its reconstruction ŷ(t).Figure 6b shows the index r 1 (t) and r 2 (t) that becomes greater at the discontinuities indicating where they are.

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 λ = 1.The order of the series was set n = 20, i.e., N = 40.The frequency step was set ω = 10 [rad/s].The step time to perform the estimation in Simulink was set ∆t = 0.01 [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, ln (|a 1 |) is plotted versus a cubic polynomial calculated to interpolate it.

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 x(t) is the displacement, which is assumed as available in this example, ẋ(t) is the velocity and ẍ(t) is the acceleration.In addition, δ, α and β are parameters, which in this example are assumed to be known.Finally, u(t) 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 x 1 (t) = x(t) and x 2 (t) = ẋ(t) 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 u(t) is unknown and needs to be estimated, we propose its estimation by using a spectral observer with n = 1.Therefore, we coupled in cascade equation system (18) with equation system (4) as follows: where ν 1 (t) = u(t), 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 ξ(t) = A ξ(t) + ϕ( ξ(t)) + K(x 1 (t) − ξ1 (t)) can be designed for system (22), where K can be calculated by means of Equation (14).

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 c codes created by Hristo Zhivomirov to compute STFT and its inverse [16].The signal analyzed was (24) sampled at 1000 [Hz].To compute the STFT by using the code of Zhivomirov, the following parameters were set: τ w = 2 8 [s] as the window length, h = τ w /4 [s] as the hop size and n f f t = 2 10 as the number of FFT points.The tuning of the spectral observer was done by setting n = 10, λ = 1, ω = π [rad/s] and ν(0) = 0.The solver used for the numerical solution was ODE4 (Runge-Kutta) with a fixed step size ∆t = 0.01 [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 n = 10, the resulting vector containing the magnitude of each harmonic was 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 n f f t 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.

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.

Conclusions
In this paper, we presented the design of a novel spectral observer, which can be used to approximate periodical and non-periodical signals via state estimation.To design the spectral observer, we constructed a synthetic system in state space representation from the Fourier series.We presented some application examples to reconstruct periodical signals but also a well-know non-periodical one such as the price of the Bitcoin from its genesis.Some important aspects were not discussed in this article that require a deeper analysis, such as a comparison between the computational burden of the spectral observer and that of the Fourier Transform or an analysis of the spectral observer vis-à-vis perturbations and noise.These aspects must be treated in a continuation of this research work.

Figure 1 .
Figure 1.Schema of the reconstruction of a signal by using the spectral observer.