From 11e64481f5b8a2996e1cd044e4ec93962dc51fd9 Mon Sep 17 00:00:00 2001 From: Sam Quinn Date: Fri, 17 May 2024 15:43:43 -0400 Subject: [PATCH] Add default (undocumented) cosine windowing function --- src/SampledCorrelations/CorrelationSampling.jl | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/src/SampledCorrelations/CorrelationSampling.jl b/src/SampledCorrelations/CorrelationSampling.jl index 3ea40b92f..1bdfa9bb0 100644 --- a/src/SampledCorrelations/CorrelationSampling.jl +++ b/src/SampledCorrelations/CorrelationSampling.jl @@ -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] @@ -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) @@ -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