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

FFTW.fft() fails to calculate spectrum #250

Closed
StefanPofahl opened this issue Aug 19, 2022 · 7 comments
Closed

FFTW.fft() fails to calculate spectrum #250

StefanPofahl opened this issue Aug 19, 2022 · 7 comments

Comments

@StefanPofahl
Copy link

Hi,

yesterday I observed in one measurement that fft-fails to calculate the spectrum of my data.
The data is a nice sinus. I do not know what the root cause is.
The result is the same on Julia-LTS and Julia v1.8.0.
If I use SciPy.fft.fft() instead, the spectrum is calculated as expected.
I would like to send you the data, to enable debugging on your side.
Unfortunatly the file size is above the accepted file size,
can you offer a way to send the data?

Regards,

Stefan

FFTW_Debug_figures.zip

@StefanPofahl
Copy link
Author

I was able to reproduce the error with syntetic data, here is my script:

using PlotlyJS, Printf
using SciPy, FFTW

sampling_rate = 250000
window_length = 47499754
frequ1        = 0.1
ampl1         = 2.1
phase1        = 0.0

# --- time and data vector:
vec_t    = collect(range(0, step = 1.0 / sampling_rate, length = window_length)) 
td_data_ = ampl1 .* sin.( (2 * pi * frequ1 .* vec_t) .+ deg2rad(phase1))

# --- relevant range in fft-result (meaningful bins):
bins_range = range(1, step = 1, stop = ceil(Int, window_length / 2))

# --- Frequncy Vector --------------------------------------------------------------------------------------
t_win_duration = window_length / sampling_rate
frequ_vec = 1 / t_win_duration .* (0 : (ceil(Int, window_length / 2) - 1))
frequ_vec = frequ_vec[2:end]

# --- FFTW -------------------------------------------------------------------------------------------------
amplitudes_FFTW = abs.(FFTW.fft(td_data_))[bins_range]
amplitudes_FFTW = amplitudes_FFTW .* (2/window_length)
amplitudes_FFTW = amplitudes_FFTW[2:end]

# --- SciPy -------------------------------------------------------------------------------------------------
amplitudes_SciPy = abs.(SciPy.fft.fft(td_data_))[bins_range]
amplitudes_SciPy = amplitudes_SciPy .* (2/window_length)
amplitudes_SciPy = amplitudes_SciPy[2:end]

# --- Plot --------------------------------------------------------------------------------------------------
plt_range = range(1, length = 40)
hdl1 = PlotlyJS.scatter(; x = frequ_vec[plt_range], y = amplitudes_FFTW[plt_range],  name = "FFTW")
hdl2 = PlotlyJS.scatter(; x = frequ_vec[plt_range], y = amplitudes_SciPy[plt_range], name = "SciPy")
hdl_plt = PlotlyJS.Plot([hdl1, hdl2])

@StefanPofahl
Copy link
Author

The problem occurs if I turn on the MLK by this command: FFTW.set_provider!("mkl")
If I switch back to fftw by the command: FFTW.set_provider!("fftw") the amplitude signal can be calculated correctly.
If the input is real and I can use: rfft() instead of fft() the problem can also so be prevented.

@stevengj
Copy link
Member

If it's a bug in MKL, there's nothing I can do about it — go complain to Intel. (They will probably want you to reproduce it in a minimal C program, however.)

@StefanPofahl
Copy link
Author

intel_support

@StefanPofahl
Copy link
Author

They have an open github repository, including the functionality to open issues, I have opened a ticket:
oneapi-src/oneMKL#222

@StefanPofahl
Copy link
Author

I was informed that this group was not correct, therefore, I opened a new issue in another group:
[oneAPI Math Kernel Library](https://community.intel.com/t5/Intel-oneAPI-Math-Kernel-Library/function-fft-sometimes-fails-to-calculate-result/m-p/1414125#M33641)

Let's see, if this is the right place to inform Intel about this bug.

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

3 participants
@stevengj @StefanPofahl and others