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

Add fft frequency transformation #62

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open

Conversation

SaraPido
Copy link
Contributor

@SaraPido SaraPido commented Nov 7, 2024

Fft frequency transformation when data sampling rate is not at least twice the signal's bandwidth.

Previous solution:
- Designed for cases where amplitude values include both positive and negative frequency components.
- Designed for data where sampling rate is at least twice the signal's bandwidth.
- Not suitable for our use case, which assumes amplitude values represent only the positive side of the FFT result.
- The formula was using the Numpy fftfreq function: frequency_values = np.fft.fftfreq(len(amplitude_values), 1 / sampling_frequency)

Current solution:
- Addresses the limitations of numpy.fft.fftfreq and numpy.fft.rfftfreq, which do not directly align with our assumptions about positive-only FFT amplitudes.
- Assumes a uniformly spaced frequency axis starting at zero and progressing in increments based on the sampling frequency, ensuring compatibility with our assumptions.
- Now, the function is: frequency_values = np.arange(0, len(amplitude_values)) * sampling_frequency

@SaraPido SaraPido requested a review from sarahmish November 13, 2024 14:39
Copy link
Contributor

@sarahmish sarahmish left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks @SaraPido!

For our reference, which formula did you implement for this solution here? It would be good to reference why we changed the implementation.

@@ -16,6 +16,7 @@ def fft_freq(amplitude_values, sampling_frequency):
* `amplitude_values (numpy.ndarray)`
* `frequency_values (numpy.ndarray)`
"""
frequency_values = np.fft.fftfreq(len(amplitude_values), 1 / sampling_frequency)
# frequency_values = np.fft.fftfreq(len(amplitude_values), 1 / sampling_frequency)
frequency_values = np.arange(0, len(amplitude_values)) * sampling_frequency
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't it be divided by len(amplitude_values)?
Screenshot 2024-11-14 at 9 53 28 AM

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Theoretically the end time is:
End Time = Timestamp + (Length of Values * sampling frequency )
So the frequencies values are
np.arange(0, N)* sampling frequency

Copy link
Contributor

@sarahmish sarahmish left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! Thanks @SaraPido!

Maximum frequency value = sampling_frequency * len(amplitude_values)

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

Successfully merging this pull request may close these issues.

2 participants