Function Repository Resource:

NPseudoVoigt

Source Notebook

Fast numerical approximation to the PDF of the Voigt distribution with around 1.2% of maximum deviation

Contributed by: Julien Kluge

ResourceFunction["NPseudoVoigt"][x,b,σ]

calculates the approximation at postions x of a Voigt distribution with CauchyDistribution parameter b and NormalDistribution parameter σ.

Details and Options

ResourceFunction["NPseudoVoigt"] automatically threads over lists.
ResourceFunction["NPseudoVoigt"] is approximately normed to 1 for all parameters b and σ above 0.

Examples

Basic Examples (2) 

NPseudoVoigt always returns numerical results, even for exact inputs:

In[1]:=
ResourceFunction["NPseudoVoigt"][0, 1, 1]
Out[1]=

NPseudoVoigt compared to the analytic solution:

In[2]:=
Plot[{ResourceFunction["NPseudoVoigt"][x, 1, 1], PDF[VoigtDistribution[1, 1], x]}, {x, -5, 5}]
Out[2]=

Scope (6) 

NPseudoVoigt automatically threads over lists:

In[3]:=
ResourceFunction["NPseudoVoigt"][{-1, 0, 1}, 2, {1, 2, 3}]
Out[3]=

NPseudoVoigt is approximately normed to 1 for b and σ greater than 0:

In[4]:=
NIntegrate[
 ResourceFunction["NPseudoVoigt"][x, 10, 20], {x, -Infinity, Infinity}]
Out[4]=

NPseudoVoigt's norm has four additional terms that cancel out for non-extreme values of b and σ:

In[5]:=
Integrate[
  ResourceFunction["NPseudoVoigt"][x, b, \[Sigma]], {x, -Infinity, Infinity}, Assumptions -> b > 0 && \[Sigma] > 0] /. {num_?NumericQ :> Round[num, 10^-15]}
Out[5]=

NPseudoVoigt's deviation to the analytic solution in the maximum is usually less than ±1% for every parameter combination b and σ:

In[6]:=
PercentForm /@ MinMax[Table[(PDF[VoigtDistribution[b, \[Sigma]], 0] - ResourceFunction["NPseudoVoigt"][0, b, \[Sigma]])/
    PDF[VoigtDistribution[b, \[Sigma]], 0], {b, 1/10, 3, 1/10}, {\[Sigma], 1/10, 3, 1/10}]]
Out[6]=

NPseudoVoigt's relative deviation increases if b and σ approach one another:

In[7]:=
Plot3D[(PDF[VoigtDistribution[b, \[Sigma]], 0] - ResourceFunction["NPseudoVoigt"][0, b, \[Sigma]])/
  PDF[VoigtDistribution[b, \[Sigma]], 0], {b, 0.1, 3}, {\[Sigma], 0.1,
   3}, PlotRange -> All]
Out[7]=

NPseudoVoigt is also stable against σ being 0:

In[8]:=
PDF[VoigtDistribution[1, 10^-20], 0.0] == ResourceFunction["NPseudoVoigt"][0, 1, 0]
Out[8]=

Applications (1) 

NPseudoVoigt can be compiled to obtain faster execution times:

In[9]:=
data = Range[-5, 5, 0.0005];

Total[PDF[VoigtDistribution[1, 1], data]] // Timing (*analytical solution*)
Out[3]=
In[10]:=
Total[ResourceFunction["NPseudoVoigt"][data, 1, 1]] // Timing (*uncompiled [\[FilledSmallSquare]]	NPseudoVoigt  solution*)
Out[10]=
In[11]:=
NPseudoVoigtC = Compile[{x, b, \[Sigma]}, Evaluate@
    ResourceFunction["NPseudoVoigt"][x, b, \[Sigma]]]; (*compile*)
Total[NPseudoVoigtC[#, 1, 1] & /@ data] // Timing (*compiled [\[FilledSmallSquare]]	NPseudoVoigt *)
Out[11]=

Possible Issues (2) 

Negative b parameters can produce imaginary values:

In[12]:=
ResourceFunction["NPseudoVoigt"][0, -1, 1]
Out[12]=

Negative σ parameters do not yield symmetric values:

In[13]:=
ResourceFunction["NPseudoVoigt"][0, 1, -1] == ResourceFunction["NPseudoVoigt"][0, 1, 1]
Out[13]=

Neat Examples (2) 

NPseudoVoigt can be used to approximate an atomic absorption spectrum efficiently:

In[14]:=
(* Evaluate this cell to get the example input *) CloudGet["https://www.wolframcloud.com/obj/0491b635-2333-4685-9024-5b7aae861c0e"]
Out[15]=
Out[16]=

NPseudoVoigt can be used to show that σ is negligible or even 0, whereas the VoigtDistribution could throw errors:

In[17]:=
(* Evaluate this cell to get the example input *) CloudGet["https://www.wolframcloud.com/obj/e6f1ac70-dd92-4c57-b5df-a43fc58904f8"]
Out[19]=

Publisher

Julien Kluge

Version History

  • 1.0.0 – 19 June 2019

Source Metadata

Author Notes

If used for fitting atomic Voigt spectra with several thousand data points and multiples peaks, the function should be compiled beforehand (as shown above) to maximize efficiency and evaluation speed.
Julien Kluge Quantum Optical Metrology; Joint Lab Integrated Quantum Sensors Department of Physics Humboldt-Universität zu Berlin (julien@physik.hu-berlin.de)

License Information