2. Spectral Transform
The transform starts by first determining the peak total range of the data in the temporal domain; this range will become the base amplitude of the spectral series. The computer then generates a series of sine and cosine functions at each frequency within the spectral domain, and compares each of these sinusoidal functions to the temporal data to be transformed. In the comparison, a coefficient of determination is found and saved. To accommodate fluctuations in phase, each frequency generates both a sine and cosine function; this ultimately results in real and imaginary spectral components. Finally, the magnitudes of the coefficient of determination data are normalized, and the result is an accurate spectral representation of the temporal function.
The Fourier Transform is one of the most utilized mathematical transforms in science and engineering. By definition, a Fourier Transform will take a given function and represent it by a series of sinusoidal functions of varying frequencies and amplitudes. Analytically, the spectral function
is represented as [
1,
2]
where
i is the imaginary term (
),
f(t) is any temporal function of
t to be transformed, and
(rad/s) represents the frequency of each sinusoidal function. The inverse of this function is
Conceptually, the spectral function
represents the amplitudes of a series of sinusoidal functions of discrete frequencies
(rad/s)
Often in practical application, one does not have an exact analytical function, but a series of discrete data points at discrete times
. If it is necessary to convert these discrete data into the spectral domain, the traditional approach has been to use the Discrete Fourier Transform (DFT) algorithm, often known as Fast Fourier Transform (FFT). The DFT algorithm is, by definition [
11,
12]
where
is a discrete spectral data point, and
is a discrete data point in the temporal domain. With DFT, the spectral resolution is proportional to the temporal resolution, and it is often the case that the limited temporal data will not be sufficient to obtain the spectral resolution desired.
If one wants to obtain frequency information, there is a certain minimum temporal resolution necessary to properly distinguish the frequencies; this is known as the Nyquist rate [
13,
14,
15,
16,
17].
As demonstrated in
Table 1 and
Figure 1, two different cosine functions with frequencies of 1 and 9 have exactly the same results when resolved at a temporal resolution
.
There are many approaches to implementing Fourier transforms on data of limited resolution. One method is to introduce a scaled coordinate system and identifying the Fourier variables as the direction cosines of propagating light have been used to spectrally characterize diffracted waves in a method known as Angular Spectrum Fourier Transform (FFT-AS) [
18,
19,
20,
21]. Another technique of numerical Fourier Transform is Direct Integration (FFT-DI) [
22], using Simpson’s rule to improve the calculations accuracy. Finally, one of the simplest approaches to taking the Fourier transform with a limited temporal resolution is to use Non-uniform Discrete Fourier Transforms (NDFT) [
23,
24,
25,
26,
27,
28,
29,
30,
31]
where
are relative sample points over the range, and
is the frequency of interest.
3. Spectral Transform Algorithm
This algorithm, which the author calls the Coefficient of determination Fourier Transform (CFT), is an approach to obtain greater spectral resolution; the full spectral domain, or any frequency range or resolution desired, is determined by the user. Greater resolution or a larger domain will inherently take longer to solve, depending on the computer resources available. One advantage of this approach is that the spectral domain can also have varying resolutions, for enhanced resolution at points of interest without dramatically increasing the computation cost of each spectral transform.
At each discrete point in the spectral domain, the algorithm generates two sinusoidal functions
where
is to represent the real spectral components,
is to represent the imaginary spectral components,
is the discrete frequency of interest,
t is the independent variable of the data of interest, and
A is the amplitude of the function
defined and the total range within the temporal data.
% MatLab code of the CFT algorithm
% FFO is the function in the temporal domain. Sfct is a discrete function
% of frequencies, selected by the user, to define the spectral domain
FFavg=mean(FF0); FFstd=max(FF0)-min(FF0);
for ii=2:ct
sinfct=sin(2∗pi∗t∗(Sfct(ii))); % Real cosine function
cosfct=cos(2∗pi∗t∗(Sfct(ii))); % Imaginary sine function
corrR=R2fct(cosfct,FF0); % R^2 of real component
corrI=R2fct(sinfct,FF0); % R^2 of imaginary component
SpecFct(ii)=corrR+(i∗corrI); % Saving the Spectral Function
end
SpecFct=FFstd∗SpecFct/(sum(abs(SpecFct))); % Normalize the spectral function
SpecFct(1)=FFavg; % Set the average of the temporal function (Sfct(1)=0)
The next step is to take each of these functions, and find the Coefficient of Determination between the function and the temporal data, all with the same temporal domain and resolution [
9,
32,
33,
34,
35]. The coefficient of determination is a numerical representation of how much variance can be expected between two functions. To find the coefficient of determination between two equal-length discrete functions
and
, three coefficients are first calculated
where
N is the discrete length of the two functions, and
and
represent the arithmetic mean value of functions
and
. The correlation coefficient, represented as
R, is then determined as
and the closer the two functions match, the closer the value of the correlation coefficient reaches
. If there is no match at all, the correlation coefficient will be
, and if the two functions are perfectly opposite of each other (
), the correlation coefficient goes down to
R = −1. In practice, the coefficient of determination is often represented as the
value
This process is repeated for every sine and cosine function generated with each frequency within the spectral domain. The coefficients of determinations can be used to represent the spectral values, both real (cosine function) and imaginary (sine functions), for the given discrete frequency point. These functions of
values for the real and imaginary components are then normalized to the maximum real and imaginary values, and multiplied by the amplitude
A determined in Equation (
8). The final outcome is a phase-resolved spectral transformation of the input function, but with a spectral domain as large or resolved as desired.
% Correlation Coefficient Function
function [R2]=R2fct(X,Y)
ctx=length(X); foo=zeros(ctx,3);
for ii=1:ctx
foo(ii,1)=(X(ii)-(mean(X)))∗(Y(ii)-(mean(Y)));
foo(ii,2)=(X(ii)-(mean(X)))^2;
foo(ii,3)=(Y(ii)-(mean(Y)))^2;
end
foo=sum(foo);
foo2=(sqrt((foo(2))∗(foo(3))));
if foo2==0
corr=0;
else
corr=foo(1)/foo2; % Closer to 1 is best
end
R2=corr^2;
end
Finally, this spectral transformation can easily be converted back to the temporal domain. By definition, the temporal domain is merely the sum of the series of sinusoidal waves (Equation (
3)), and thus the inverse CFT transform can simply be defined as
% MatLab code of the inverse CFT algorithm
% Ftest = temporal output function, of discrete length ctT
% t = time domain of discrete length ctT
% SpecFct = spectral function of discrete length ct to be transformed
% back to the temporal domain
Ftest=zeros(ctT,1);
for ii=1:ct
Ftest=((real(SpecFct(ii)))∗cos(2∗pi∗t∗Sfct(ii)))+Ftest;
Ftest=((imag(SpecFct(ii)))∗sin(2∗pi∗t∗Sfct(ii)))+Ftest;
end
4. Initial Demonstration of the Spectral Transform Algorithm
To demonstrate the capability of this algorithm, six functions are generated based on the two similar functions demonstrated in
Table 1 and
Figure 1; the two functions are used with a temporal range of 0 to 1, with the same temporal resolution of
, and frequencies of both
f = 1 and
f = 9. The cosine functions are modified to have a phase shift of
. The
supplementary file Run_Initial_Study.zip contains the MATLAB code to run this analysis and replicate these results.
The spectral transform was taken of all six of these functions with both the CFT algorithm, as well as the NDFT algorithm defined in Equation (
6). The spectral magnitude and phase from both methods are plotted in
Figure 2. By using Equation (
12) to get back to the temporal domain (one example is plotted in
Figure 3), all six functions matched (
> 0.996) with the spectral magnitude and phase from the CFT; there is no coherent match for the NDFT. This is realized by finding the coefficient of determination between the recovered temporal data and the original temporal data; the
results are tabulated in
Table 2. While the NDFT may give a clear picture of the spectral domain of the function, it is impossible to recover the function back to the original temporal domain without excessively computationally intensive matrix analysis. The strength of CFT transform lies in its inverse operator defined in Equation (
12), with which the true temporal function can be obtained back from the spectral domain obtained with highly resolved CFT.
One important point is that, while the CFT transform is a spectral representation of the transformed temporal function, the spectral function of this method is not a true Fourier transform defined analytically in Equation (
1). Both functions are similar (see
Figure 2), but not exact; this function, by definition, is the magnitude of the coefficient of determination
of the temporal function with the associated sine and cosine wave. For this reason, the CFT versions of the spectral representation, while similar, are not identical to the NDFT versions, and thus are not true Fourier transforms. The power of these CFT spectral plots lie in the fact that they can be easily transformed back to the temporal domain.
5. Performance of the Spectral Transform Algorithm
In the previous sections, this algorithm was demonstrated to be an effective tool to determine spectral magnitude and phase. Next, this algorithm’s performance was compared to both traditional FFT [
11,
12] of limited resolution, as well as the higher resolution NDFT method [
23,
24,
25,
26,
27,
28,
29,
30,
31]. Often in practical applications it is necessary to determine the frequencies of the peak spectral magnitudes with temporal data of limited resolution. In this example, a temporal function is comprised of four sinusoidal functions with an amplitude of 1.25, 1.5, 1.75, and 2, at frequencies of 20.80 Hz, 38.38 Hz, 61.38 Hz, and 77.55 Hz, at a phase shift of 0
, 120
, 240
, and 0
, respectively. Mathematically, the function can be described as
The function is performed over a temporal duration of 1 unit of time. The function is plotted in
Figure 4a, where the green lines represent the highly resolved function, and the blue circles represent the limited temporal data of 100 Hz one might practically receive if collecting experimental data.
A traditional FFT of this limited-resolution temporal data was collected, along with a CFT with a spectral domain of 0.01 Hz ranging from 0.01 Hz to 100 Hz, as well as a NDFT transform with the same refined spectral domain; the spectral magnitudes are all plotted in
Figure 4b. The peak spectral magnitudes were numerically found in the spectral range of 10–30 Hz, 30–50 Hz, 50–70 Hz, and 70–90 Hz, and tabulated in
Table 3. For all four frequencies, the CFT improved upon traditional FFT in terms of accurately centering on the frequency with peak spectral magnitude. In addition, with limited resolution tradition FFT cannot even characterize frequencies higher than half the resolution (Equation (
5)); the spectral plots are limited up to 50 Hz. The NDFT method with the higher resolution allowed for spectral characterization above 50 Hz, and improved upon the accuracy of the spectral peaks when compared to the traditional FFT, but still with greater error than the CFT. In addition, the CFT results can be accurately transformed back to the temporal domain with Equation (
12), and in this case the transform of the spectral results matched remarkably (
R = 0.99999) with the original temporal function, as demonstrated in
Figure 4c.
6. Parametric Study of the Spectral Transform Algorithm
A parametric study of this transform was conducted to demonstrate that it can be used for high resolution measurements of the spectral frequency with a limited temporal resolution. To demonstrate this, 15 random frequencies were selected, ranging from 2 to 17 cycles over the duration of the measured window. Both the independent and dependent temporal variables are arbitrary values to demonstrate the transform function; the independent scale ranges from 0 to 1 and has 180 data points. The arbitrary dependent data had random averages between −1000 and 1000, with an amplitude of 200 and random noise to represent the typical randomness found in typical test data. Each of these 15 random frequencies was phase shifted by three random phases. All forty-five arbitrary functions were transformed into the spectral domain with this transform, with a frequency domain ranging from 0 to 20 cycles per unit time duration, and a frequency resolution of 1 mHz; two examples of these spectral results are presented in
Figure 5. As a further test of the robustness of the transform, the spectral data were then converted back to the temporal domain, and the new temporal function was compared to the original function with the coefficient of determination method to ascertain errors from the transform.
This spectral transform was remarkably effective at finding the peak primary frequency, often with accuracies down to tens of mHz. The functions of the peak frequencies (
Figure 6), both of which were used for the initial function and the peak of the spectral transform, match with an
value of 0.999991—effectively identical. The functions of the random phase angle at the peak frequencies (
Figure 7), both of which were used for the initial function and the phase of the spectral transform at the peak frequency, match with an
value of 0.9982, demonstrating that this transform can be used to capture both spectral magnitude and phase with great accuracy.
Finally, the inverse of this spectral transform was conducted for each spectral output, and the errors between the original functions and the transformed-inverse-transformed function are minimal. As expected, not all of the fine random noise is captured; this would require a near infinite spectral domain, which would further increase computational costs, but the overarching shapes, magnitudes, and phases of the functions are consistently captured. Taking the coefficient of determination of each function pair, the value of
is never less than 0.92. Two examples of the original function (lines) and the transformed-inverse-transformed function (stars) are represented in
Figure 8. The tabulated results of all fifteen studies, for each of the three phase magnitude shifts, are demonstrated in
Table 4,
Table 5 and
Table 6.