This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
Computes the reflection of a sequence of indices of refraction without interference and absorption effects. | |
y = multipleReflections(n) | |
author: Cuchu & lnacquaroli | |
""" | |
function multipleReflections(n::Array{Real}) | |
R1::Float64 = 0.0 | |
R::Float64 = 0.0 | |
for i = 1:length(n)-1 | |
R2 = ( (n[i] - n[i+1])/(n[i] + n[i+1]))^2 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
Returns the spectral radiance (W·sr^-1·m^-3), given the wavelength (m) and the absolute temperature (K). | |
B = blackbodyRadiation(λ, T) | |
B = blackbodyRadiation((.1:.01:3)*1e-6, [3000., 4000, 5000]) | |
source: https://en.wikipedia.org/wiki/Planck%27s_law | |
""" | |
function blackbodyRadiation(λ::AbstractArray{T1}, T::AbstractArray{T2}) where {T1<:Number, T2<:Number} | |
h = 6.626070040e-34 # Planck's constant, J·s | |
c = 299792458 # speed of light, m·s | |
kB = 1.38064852e-23 # Boltzmann constant, J·K^-1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
Returns an RGB matrix-color based on the wavelength input in nm. | |
RBG = wavelength2rgb(λ) | |
Wavelength range: 380nm and 780nm, black otherwise. | |
Source: https://stackoverflow.com/questions/3407942/rgb-values-of-visible-spectrum | |
""" | |
function wavelength2rgb(λ::AbstractArray{<:Number}) | |
Γ = 0.8 | |
# warm up | |
R = Array{Float64, 1}(undef, length(λ)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
Asymmetric Least Squares Smoothing by P. Eilers and H. Boelens in 2005 | |
For a more options and detailed implementation, see https://github.com/charlesll/Spectra.jl/blob/master/src/baseline.jl | |
Requires using LinearAlgebra and SparseArrays | |
""" | |
function baselineCorrection(y, lam, p, ninter=10) | |
L = length(y) | |
eyeL = Matrix(1.0I, L, L) | |
D = sparse(diff(diff(eyeL, dims=2), dims=2)) | |
w = ones(L) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
E.g.: | |
x = collect(1:100) | |
y = movingAverage(x, w) | |
""" | |
function movingAverage(x::Vector, wind::Int) | |
y = Vector{Float64}(undef, length(x)) | |
for i in 1:length(x) | |
lo = max(1, i - wind) | |
hi = min(len, i + wind) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function findClosest(x::Array, x0::Number) | |
return findmin(abs.(x .- x0))[2] | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
Polynomial smoothing with the Savitzky Golay filters. Adapted for julia >= 1.0. | |
Sources: https://github.com/BBN-Q/Qlab.jl/blob/master/src/SavitskyGolay.jl | |
Requires LinearAlgebra and DSP modules loaded. | |
""" |