Skip to content

Commit

Permalink
Add default (undocumented) cosine windowing function
Browse files Browse the repository at this point in the history
  • Loading branch information
Lazersmoke committed May 17, 2024
1 parent 045f533 commit 11e6448
Showing 1 changed file with 14 additions and 4 deletions.
18 changes: 14 additions & 4 deletions src/SampledCorrelations/CorrelationSampling.jl
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ function no_processing(::SampledCorrelations)
nothing
end

function accum_sample!(sc::SampledCorrelations)
function accum_sample!(sc::SampledCorrelations; window)
(; data, M, observables, samplebuf, nsamples, fft!) = sc
natoms = size(samplebuf)[5]

Expand Down Expand Up @@ -121,7 +121,17 @@ function accum_sample!(sc::SampledCorrelations)
sample_β = @view samplebuf[β,:,:,:,j,:]
databuf = @view data[c,i,j,:,:,:,:]

corr = FFTW.fft(FFTW.ifft(sample_α .* conj.(sample_β),4) ./ n_contrib,4)
corr = FFTW.ifft(sample_α .* conj.(sample_β),4) ./ n_contrib

if window == :cosine
# Apply a cosine windowing to force the correlation at Δt=±(T-1) to be zero
# to force periodicity. In terms of the spectrum S(ω), this applys a smoothing
# with a characteristic lengthscale of O(1) frequency bins.
window_func = cos.(range(0,π,length = num_time_offsets + 1)[1:end-1]).^2
corr .*= reshape(window_func,1,1,1,num_time_offsets)
end

corr = FFTW.fft(corr,4)

if isnothing(M)
for k in eachindex(databuf)
Expand Down Expand Up @@ -171,7 +181,7 @@ separately prior to calling `add_sample!`. Alternatively, the initial spin
configuration may be copied into a new `System` and this new `System` can be
passed to `add_sample!`.
"""
function add_sample!(sc::SampledCorrelations, sys::System)
function add_sample!(sc::SampledCorrelations, sys::System; window = :cosine)
new_sample!(sc, sys)
accum_sample!(sc)
accum_sample!(sc; window)
end

0 comments on commit 11e6448

Please sign in to comment.