This one is close, but it goes above the ±1e-6.
signal = randn(Int(1e6)) * 1e-6
plot(signal)
This one is close, but it goes above the ±1e-6.
signal = randn(Int(1e6)) * 1e-6
plot(signal)
White noise can never have a fixed amplitude. It can have a more-or-less fixed standard deviation, though.
i need such a signal, could you help me create it ?
It is mathematically impossible.
Why do you need such a signal? I think you do not understand the concept of noise.
The amplitude of white noise at any given moment is random, but follows certain statistical properties:
It’s important to note that while the instantaneous amplitude of white noise fluctuates randomly, its overall statistical properties remain constant.
This depends on what you mean by ‘random’. If you require normally distributed noise (which is what randn
returns), then you cannot guarantee a particular upper limit. There are other distributions, like the uniform distribution whis is limited.
You could use randn
and then clip the data at you desired limit, but it would no longer be normal.
So perhaps you want:
signal = (rand(10^6) .- 0.5) * 2e-6
plot(signal)
A uniform distribution with the amplitude of 1.0.
Why the Int?
julia> extrema(2e-6*(rand(10^7) .- 0.5))
(-9.999999081819787e-7, 9.999999401906048e-7)
julia> extrema(2e-6*(randn(10^7) .- 0.5))
(-1.1699182863351871e-5, 9.982354577899941e-6)
Not working for me:
julia> signal = (rand(1e6) .- 0.5) * 2e-6
ERROR: MethodError: no method matching Random.Sampler(::Type{Random.TaskLocalRNG}, ::Random.SamplerTrivial{Float64, Float64}, ::Val{1})
Closest candidates are:
Random.Sampler(::Type{<:Random.AbstractRNG}, ::Random.Sampler, ::Union{Val{1}, Val{Inf}})
@ Random ~/.julia/juliaup/julia-1.10.7+0.x64.linux.gnu/share/julia/stdlib/v1.10/Random/src/Random.jl:147
Random.Sampler(::Type{<:Random.AbstractRNG}, ::Any, ::Union{Val{1}, Val{Inf}})
@ Random ~/.julia/juliaup/julia-1.10.7+0.x64.linux.gnu/share/julia/stdlib/v1.10/Random/src/Random.jl:183
Random.Sampler(::Type{<:Random.AbstractRNG}, ::BitSet, ::Union{Val{1}, Val{Inf}})
@ Random ~/.julia/juliaup/julia-1.10.7+0.x64.linux.gnu/share/julia/stdlib/v1.10/Random/src/generation.jl:450
...
Stacktrace:
[1] Random.Sampler(T::Type{Random.TaskLocalRNG}, sp::Random.SamplerTrivial{Float64, Float64}, r::Val{1})
@ Random ~/.julia/juliaup/julia-1.10.7+0.x64.linux.gnu/share/julia/stdlib/v1.10/Random/src/Random.jl:147
[2] Random.Sampler(rng::Random.TaskLocalRNG, x::Random.SamplerTrivial{Float64, Float64}, r::Val{1})
@ Random ~/.julia/juliaup/julia-1.10.7+0.x64.linux.gnu/share/julia/stdlib/v1.10/Random/src/Random.jl:139
[3] rand(rng::Random.TaskLocalRNG, X::Random.SamplerTrivial{Float64, Float64})
@ Random ~/.julia/juliaup/julia-1.10.7+0.x64.linux.gnu/share/julia/stdlib/v1.10/Random/src/Random.jl:255
[4] rand(rng::Random.TaskLocalRNG, X::Float64)
@ Random ~/.julia/juliaup/julia-1.10.7+0.x64.linux.gnu/share/julia/stdlib/v1.10/Random/src/Random.jl:255
[5] rand(X::Float64)
@ Random ~/.julia/juliaup/julia-1.10.7+0.x64.linux.gnu/share/julia/stdlib/v1.10/Random/src/Random.jl:260
[6] top-level scope
@ REPL[1]:1
OK, I see, 1e10
is different from 10^10
.
You probably mean “Gaussian noise”, as opposed to “white noise” meaning “has a flat spectrum”. White noise does not have to be Gaussian.
You can also use Distributions.jl here — it’s always nice to use something established as opposed to hand-rolling it yourself, especially when it comes to random distributions.
In the language of a distribution, clipping is a censored
distribution:
julia> using Distributions, Plots
julia> histogram(rand(censored(Normal(0, 1e-6/3), -1e-6, 1e-6), 10^6))
Or, you could truncate the distribution, effectively resampling those points from outside the range you wanted:
julia> histogram(rand(truncated(Normal(0, 1e-6/3), -1e-6, 1e-6), 10^6))
Or you could look through Distribution.jl’s docs and find any other shape that fits your fancy.