Hacktoberfest 2026:メンテナが10月に向けて印を付けた、オープンで初心者向けの issue。 Hacktoberfest の issue を見る

Unwanted sine modes appearing in convolution using FFT

オープン
#257 コメント 1 件 リアクション 0 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

評価

難易度
4/5
見積もり時間
3〜5日
初心者へのやさしさ
35/100
issue の種類
バグ
明瞭さ
おおむね明確
活発さ
停滞
技術スタック
julia
領域
tooling

調査の方向性

まず issue の Julia MWE を実行し、fft の周波数構成、weight_hat の計算、および real(ifft(I_hat)) の結果に注目してください。FFT 畳み込みを手動で評価した積分と比較し、残っている振動が畳み込みの設定によるものか FastTransforms.jl によるものかを判断してください。原因と、再現可能な修正または制限事項を文書化してください。

索引モデルが issue の本文から書いたものです。

説明

Hi All, I don't know if this is an issue with FastTransforms.jl specifically or something that I've done, but any guidance that could be provide will be appreciated.

To give a little bit of background, I'm trying to perform the following convolution (nV, r and r' are vectors):

 n_\mathbf{V}(r) = \int d\mathbf{r}' \rho (r') \delta(|r-r'|-R) \frac{r-r'}{|r-r'|}

Where rho(r) is a profile which looks like (I've made sure it's periodic):
Screenshot 2025-01-15 at 12 51 45 PM

I have obtained an analytical expression for the fourier transform of the last two terms in the integral as:

\hat{w} = 4\pi i \frac{k}{|k|^3} (\sin(|k|R)-|k|R\cos(|k|R))

If I use just regular Float64, the resulting nV profile looks fine:
Screenshot 2025-01-15 at 12 56 35 PM
Except when I zoom in:
Screenshot 2025-01-15 at 12 56 00 PM
While these values are small, in a later part of my code, I need to divide this profile by a small number which makes this 'noise' blow up and affects calculations downstream.

I tried using FastTransforms.jl since it would let me go to higher precision. However, even when I use BigFloat, although it removes the noise, some unphysical oscillations remain:
Screenshot 2025-01-15 at 12 59 44 PM
Im no longer certain that these remaining oscillations are due to floating point errors. I also call these oscillations unphysical as, aside from the nature of this convolution integral, if I perform this convolution integral manually, the oscillations disappear completely (and I'm able to obtain the integral to higher precision).

Am I doing something wrong in the way I'm performing the convolution integral? Thanks!

I've attached an MWE below:

using FFTW, FastTransforms

# Generating the density profile
tanh_prof(x,start,stop,shift,coef) = 1/2*(start-stop)*tanh((x-shift)*coef)+1/2*(start+stop)

ub = 10
lb = -10
z = LinRange(lb,ub,4000)
rho1 = 1e3
rho2 = 1e-12
rho = @. tanh_prof(z,rho1,rho2,(ub/4+3*lb/4),20)*(z<=0) +
         tanh_prof(z,rho2,rho1,(3*ub/4+lb/4),20)*(z>0)

# Obtaining the fourier transform of w_hat
freq = fftfreq(4000,4000/20)
R = 1/2*2pi

weight_hat = @. 0.0 - 4π*im*freq/abs(freq)^3*(sin(abs(freq)*R)-R*abs(freq)*cos(abs(freq)*R)) *(freq != 0.0)

# Performing the convolution integral
rho_hat = fft(rho)
I_hat = @. rho_hat*weight_hat
nV = real(ifft(I_hat))
主要言語
Julia
スター
282
フォーク
27
平均マージ
53分
マージ済み PR(30日)
1

環境構築

このプロジェクトには開発コンテナ、Dockerfile、コントリビューションガイドがありません。まず README を読み、一般的な手順ははじめてのコントリビューションガイドを参照してください。

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

JuliaApproximation/FastTransforms.jl のほかの issue

JuliaApproximation/FastTransforms.jl の issue をすべて見る

似ている issue

Julia の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。