How to plot a lorentzian peak with known hwhm, position and height?

137 views (last 30 days)
Hi,
I would like to plot a graph to how the deconvolution of an FTIR spectrum. I've fitted the peaks with a separate program and I have the peak information for the individual peaks (hwhm, position and height).
There doesn't seem to be a simple lorentzian function on matlab as far as I can see?
Note: I am not trying to fit any data, I'm trying to plot stand alone lorentzian peaks to break down a spectrum.
I'm made the following function:
function y = lorentz(x, pos, h, H)
num = H*0.5;
den = ( x - pos ).^2 + (0.5 * H).^2;
y = h* num*(den.^-1)*(pi).^1;
end
and used the following code to plot it:
x = linspace (3100, 3700, 1000);
pos = 3624;
h = 0.7945223;
H = 2.003005*2;
d = lorentz(x, pos, h, H);
plot(x, d)
But the height of the function is not the correct height.

Answers (1)

Tiarnan Murphy
Tiarnan Murphy on 13 Jul 2020
The maximum height of a Lorentzian distribution is:
Where HWHM is the half width at half the maximum height.
In the case of your code this is:
If you wanted to scale this to a specific height then you could use the following function, which I believe should work.
function y = lorentz(x, position, half_width_half_max, height)
% A function to plot a Lorentzian (a.k.a. Cauchy) distribution given a
% space vector 'x', a position and a half width at half maximum.
% The distribution is then scaled to the specified height.
if nargin <=2
errordlg(["At least three input arguments are required.";...
"These must be in the order x_space, position, half_width.";...
"An extra height argument can be added to change scale."],...
"Input Error")
end
y = 1 ./ (half_width_half_max.*...
(1+((x-position)./half_width_half_max).^2));
if nargin == 3
height = max(y);
end
y = y.*(height/max(y));
end

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!