Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Frequency resolution of f_hat #17

Open
UDEPWollny opened this issue Aug 27, 2021 · 1 comment
Open

Frequency resolution of f_hat #17

UDEPWollny opened this issue Aug 27, 2021 · 1 comment

Comments

@UDEPWollny
Copy link

UDEPWollny commented Aug 27, 2021

Hi,

I have a question regarding the frequency resolution for the vector of Fourier coefficients.
No matter what I do, whether I use equal M and N, or one being a multiple of the other, it doe's not change the frequency resolution of the coefficients given in f_hat. For equidistant FFT, there is is a relationship for df, which is the reciprocal of M * dt. This obviously does not apply here, since df stays always at df = 1 Hz.
Is there a chance to change this behavior, or am I doing something wrong in principle?
Here is my little test to check the right frequencies and amplitudes. I can see that the 200 Hz, for example, is always at index 200.

import numpy as np
import nfft as nf

n = 2**13
dt = 1.0e-4

x = np.linspace(0.0, n*dt, n)
y = 2. * np.sin(2. * np.pi * 2.5 * x) + 0.5 * np.sin(2. * np.pi * 50. * x) + 1.25 * np.sin(2. * np.pi * 200. * x)

f_hat = nf.nfft_adjoint(x, y, n)

import matplotlib.pyplot as plt
plt.plot(2.0/n * np.abs(f_hat[n//2:]))

plt.grid()
plt.xlim(195, 205)

plt.savefig('test.png')

THX!
Patrick

@UDEPWollny
Copy link
Author

UDEPWollny commented Aug 30, 2021

I'll now answer my own question in case someone had the same issue.
The thing is, that df = 1/(M * dt) holds. One simply has to scale the total sampling time T = M*dt to unity and apply this to the sampling location vector "x". The frequency is then index * df (with df = 1 / T).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant