Я пытаюсь понять, дает ли дискретное преобразование Фурье такое же представление кривой, как регрессия с использованием базиса Фурье. Например,
library(fda)
Y=daily$tempav[,1] ## my data
length(Y) ## =365
## create Fourier basis and estimate the coefficients
mybasis=create.fourier.basis(c(0,365),365)
basisMat=eval.basis(1:365,mybasis)
regcoef=coef(lm(Y~basisMat-1))
## using Fourier transform
fftcoef=fft(Y)
## compare
head(fftcoef)
head(regcoef)
БПФ дает комплексное число, тогда как регрессия дает действительное число.
Они передают ту же информацию? Есть ли карта один к одному между двумя наборами чисел?
(Я был бы признателен, если бы ответ был написан с точки зрения статистики, а не с точки зрения инженера. Многие онлайн-материалы, которые я могу найти, содержат повсеместно технический жаргон, что делает их менее приемлемыми для меня.)
Ответы:
Они одинаковые. Вот как...
Делать регрессию
Допустим, вы подходите для модели где t = 1 , … , N и n = этаж ( N / 2 ) . Это не подходит для линейной регрессии, поэтому вместо этого вы используете некоторую тригонометрию ( cos ( a + b ) = cos
и β 2,J=Σ N т = 1 утгреха(2πт[J/N])
Выполнение дискретного преобразования Фурье
Когда вы запускаете преобразование Фурье, вы вычисляете для :j=1,…,n
I <- abs(fft(Y))^2/length(Y)
, which is sort of weird, because you have to scale it.Also you can define the "scaled periodogram"
P <- (4/length(Y))*I[(1:floor(length(Y)/2))]
.The Connection Between the Two
It turns out the connection between the regression and the two periodograms is:
Source: https://www.amazon.com/Time-Analysis-Its-Applications-Statistics/dp/144197864X
источник
R
objects I posted.fft()
doesn't scale the way I wrote (I already mentioned this), that I haven't proved anything with intercepts, and thatcreate.fourier.basis()
scales the basis functions weirdly.They are strongly related. Your example is not reproducible because you didn't include your data, thus I'll make a new one. First of all, let's create a periodic function:
Now, let's create a Fourier basis for regression. Note that, withN=2k+1 , it doesn't really make sense to create more than N−2 basis functions, i.e., N−3=2(k−1) non-constant sines and cosines, because higher frequency components are aliased on such a grid. For example, a sine of frequency kω is indistinguishable from a costant (sine): consider the case of N=3 , i.e., k=1 . Anyway, if you want to double check, just change
N-2
toN
in the snippet below and look at the last two columns: you'll see that they're actually useless (and they create issues for the fit, because the design matrix is now singular).Note that the frequencies are exactly the right ones, but the amplitudes of nonzero components are not (1,2,3,4). The reason is that the1,sinωx,cosωx,… . It's not 1π√ either, as it would have been for the orthonormal Fourier basis, 12π√,sinωxπ√,cosωxπ√,… .
fda
Fourier basis functions are scaled in a weird way: their maximum value is not 1, as it would be for the usual Fourier basisYou clearly see that:
Simply scaling the Fourier basis given by
fda
, so that the usual Fourier basis is obtained, leads to regression coefficients having the expected values:Let's try
fft
now: note that sinceYper
is a periodic sequence, the last point doesn't really add any information (the DFT of a sequence is always periodic). Thus we can discard the last point when computing the FFT. Also, the FFT is just a fast numerical algorithm to compute the DFT, and the DFT of a sequence of real or complex numbers is complex. Thus, we really want the moduluses of the FFT coefficients:We multiply by2N−1 in order to have the same scaling as with the Fourier basis 1,sinωx,cosωx,… . If we didn't scale, we would still recover the correct frequencies, but the amplitudes would all be scaled by the same factor with respect to what we found before. Let's now plot the fft coefficients:
Ok: the frequencies are correct, but note that now the basis functions are not sines and cosines any more (they're complex exponentialsexpniωx , where with i I denote the imaginary unit). Note also that instead than a set of nonzero frequencies (1,2,3,4) as before, we got a set (1,2,5). The reason is that a term xnexpniωx in this complex coefficient expansion (thus xn is complex) corresponds to two real terms ansin(nωx)+bncos(nωx) in the trigonometric basis expansion, because of the Euler formula expix=cosx+isinx . The modulus of the complex coefficient is equal to the sum in quadrature of the two real coefficients, i.e., |xn|=a2n+b2n−−−−−−√ . As a matter of fact, 5=33+42−−−−−−√ .
источник
daily
comes with thefda
package.