Skip to content

Commit

Permalink
Quick bug fix: Noise generation had a small bug
Browse files Browse the repository at this point in the history
While generating noise, ampltiude spectrum needs to be calculated
from stored power spectral density. Therefore other than taking a
square root of the PSD, the PSD needs to be multiplied
by the bin width of the PSD as well.
  • Loading branch information
anchal-physics committed Aug 10, 2024
1 parent 245746f commit 7b5dffa
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "SynthDiag"
uuid = "c6e34158-aa22-49e4-bb12-15cbcb518ce6"
authors = ["Anchal Gupta <guptaa@fusion.gat.com>"]
version = "1.0.2"
version = "1.0.3"

[deps]
ArgParse = "c7e460c6-2fb9-53a9-8c5b-16f535851c63"
Expand Down
7 changes: 4 additions & 3 deletions src/noise.jl
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,8 @@ Create a noise model from a power spectral density data given as a vector along
frequency values. The power spectral density is stored as a
`DSP.Periodograms.Periodogram` calculated from the input data.
"""
function Noise(power_spectrum::Vector{Float64}, freq::AbstractRange)::Noise
pgram = DSP.Periodograms.Periodogram(power_spectrum, freq)
function Noise(power_spectral_density::Vector{Float64}, freq::AbstractRange)::Noise
pgram = DSP.Periodograms.Periodogram(power_spectral_density, freq)
return Noise(pgram)
end

Expand All @@ -79,7 +79,8 @@ spectral density.
"""
function generate_noise(n::Noise, t::Vector{Float64})::Vector{Float64}
signal = zeros(Float64, length(t))
amp_spec = sqrt.(n.pgram.power * 2)
bw = n.pgram.freq[2] - n.pgram.freq[1]
amp_spec = sqrt.(n.pgram.power * 2 * bw)
for (ii, ff) enumerate(n.pgram.freq)
signal .+= amp_spec[ii] .* cos.(2π .* (ff .* t .+ randn()))
end
Expand Down

0 comments on commit 7b5dffa

Please sign in to comment.