Quantcast
Channel: First steps - JuliaLang
Viewing all articles
Browse latest Browse all 2795

Modifying all the frequency components of an FFT to 0 EXCEPT the 0th, +-3rd, +-6th, etc

$
0
0

I have an array and I want to modify its FFT frequencies by an exponential factor except those that are a multiple of 3 (or more generally, M). For example, we can do this naively as:

N = 256
M = 3
ψ = rand(N)
fft!(ψ)
for i = 2:N/2+1
    i = Int(i)
    if (i - 1) % M != 0
       ψ[i] *= exp(-*abs(ψ[i])) # + component
        ψ[N - i + 2] *= exp(-abs(ψ[N - i + 2])) # - component
    end
end 
ifft!(ψ)

I am aware of fftshift and the FFTView.jl package, but I can’t quite figure out how to do the indexing in a more elegant way (i.e. a 1 or 2 liner). This operation is done millions or billions of times in my production code so I’d like to do it more elegantly.

4 posts - 4 participants

Read full topic


Viewing all articles
Browse latest Browse all 2795

Latest Images

Trending Articles



Latest Images