Skip to content

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.

"""
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)

@sarahmish sarahmish assigned sarahmish and SaraPido and unassigned sarahmish Feb 13, 2025
@sarahmish sarahmish added the enhancement New feature or request label Feb 13, 2025
@sarahmish sarahmish added this to the 0.2.1 milestone Feb 13, 2025
@sarahmish sarahmish merged commit ba65f10 into master Feb 13, 2025
@sarahmish sarahmish deleted the fft_freq_allband branch February 13, 2025 15:31
@sarahmish sarahmish modified the milestones: 0.2.1, 0.3.0 Feb 18, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants