1. Make sure the latest version of ipf.m
is in the Matlab path. Use the Matlab load or
File > Import
data command to get your data into
the Matlab workspace assingle vector, a pair of vectors
(x and y), or a matrix with the
independent variable (x) in the first column and the dependent
variable (y) in the second column (e.g.
2. Type ipf(y); or ipf(x,y); or ipf(mydata);
3. Matlab displays the data in the Figure window, with the
entire signal in the lower panel and a zoomed-in section in the
top panel. (In the figure below, the data are from the demo
To use those data, download Demoipf.m, place it in the Matlab
path, and type "Demoipf" at the command prompt; the "true"
values of the peaks without noise are printed out in the command
window for comparison to your results). Note: Make sure you
don't click on the “Show Plot Tools” button in the toolbar
above the figure; that will disable normal program
functioning. If you do; close the Figure window and start
4. Use the left and right cursor keys to
pan back and forth across the signal...
To pan faster, use the <
and > keys. To pan by one point, use the [
and ] keys.
Use the up and down cursor
keys to zoom in and out.
To zoom faster, use the / and ' keys.
5. To fit a peak, isolate and center that peak in the upper
6. ... select the number of peaks by pressing a number key
between 1 and 9 (1 in this case), select the peak shape (G
= Gaussian in this case), and press F (for Fit).
The best-fit line is shown in red in the upper panel, superimposed
on the data points, along with the peak position, height, and
width of the best fit model. The bottom panel displays the
residuals (difference between the best-fit line and the data). The
current number of peaks, the shape, and the percent fitting error
are shown at the bottom of the window. Press the R key to
print out the table of results in the command window.
7. Press the F key again to
compute another fit with slightly different starting first
guesses. This will show how stable the fit is with respect
to variations in starting points (first guesses). Press R to print a report of the best-fit peak
parameters in the command window.
The percent fitting error are refreshed at the bottom of the
In ipf.m version 13 (November 2017), there are 24 different
peaks shapes are available by keystroke (e.g. L=Lorentzian,
U=exponential pulse, S=sigmoid (logistic
function), etc). Press K to see a list of all commands.
You can also select the shape by number from an even larger
menu of 49 shapes by pressing the - (minus) key
and selecting the shape by number.
8. Here's another example using the same signal: to fit the
group of three overlapping peaks near x=800, press the 3
key, use the pan and zoom to isolate that group and try to line
up the peaks with the magenta dotted vertical line markers, then
Each time you press F the fit is repeated with
slightly different starting first guesses. Keep your eye on
the fitting error and stop when the error is low. The
green lines in the upper panel show the individual
model components; the red line is the sum of those
9. If the fit seems unstable, press the X key to perform
10 silent fits and display the one with the lowest fitting
error. Press R to print a report of the best-fit peak
parameters in the command window.
Percent Fitting Error 1.6439% Elapsed time =
1.3387 sec. Peak#
10. If the peaks don't line up under the magenta dotted
vertical lines, you can manually specify the first-guess peak
positions: press C, then click on your estimates of the
peak positions in the upper graph, once for each peak. A fit is
automatically performed after the last click. Peaks are numbered
in the order clicked.
11. In the figure below, using data from the demo script Demoipf2.m, the peaks are superimposed
on a gradual curving baseline. To correct for the baseline, use
the T key to cycle between the four baseline correction
("autozero") modes: None, Linear, Quadratic,
and Flat. Pan and zoom each group of peaks so that the
signal returns to the local baseline at the edges of the
selected region in the upper panel, then press F. In the
sequence shown below, a pair of peaks near x=600 is selected and
fit, first without baseline subtraction, then with linear,
and then quadratic, baseline correction. The latter two
modes work best in this case.
The current baseline correction mode is displayed at the
top of the window.
12. Alternatively, you may use multipoint background correction
to subtract a linearly-interpolated baseline for the entire
signal: press the Backspace key, type in the desired
number of background points (14 in the example below) and press
the Enter key, then click where you estimate the
baseline to be in the lower panel, starting at the left of the
lowest x-value and ending to the right of the highest x-value.
(For greatest precision, you can maximize the figure window
before this operation). After the last click, the baseline is
subtracted; then you can continue with curve fitting. (If you
mess up, press the \ key to restore the original
background and start over). When you are done, you can measure
the peaks without baseline subtraction.
The y-axis label of the bottom panel changes accordingly.
13. Some peak shapes have an extra variable
parameter that modifies the shape: the Voigt profile,
Pearson, exponentially-broadened Gaussian (ExpGaussian),
exponentially-broadened Lorentzian (ExpLorentzian), bifurcated
Gaussian, bifurcated Lorentzian, or Gaussian/Lorentzian blend.
For those shapes, you control that extra variable parameter with
the A and Z keys and adjust it to minimize the
fitting error. The current value is displayed at the bottom of
the window. In this example, the single peak near x=2800 in the
file "DataMatrix3" is fit, first with a Gaussian and
then with an exponentially broadened Gaussian (E
key), adjusting the extra parameter (the time constant)
to minimize the fitting error.
>> load DataMatrix3
14. Press Q to print out a report in the command window.
Peak Shape = Exponentially-broadened Gaussian
No baseline correction
Number of peaks = 2
Time Constant = 33.1919
Fitted x range = 1663.5 - 2050.5 (dx=387)
Percent Fitting Error = 0.090216% Peak#
15. To test the stability of your fit with respect to random
noise, press the N key a few times. That will perform
fits on subsets of data points (called "bootstrap samples").
If the N key gives reasonable-looking fits with peak
parameters that vary somewhat from trial to trial, then you can
determine the variability of the peak position, height, width,
and area by pressing the V key, which will calculate the
standard deviation of all the peak parameters of all the peaks
in 100 such bootstrap sub-samples (this may take a minute or
so). You will be asked for the number of trials per bootstrap
sample; start with 1 and increase it if the fit is not
stable. If the N key gives wildly different fits, with highly
variable fitting errors and peak parameters, then the fit is not
stable, and you should try to increase the number of trials when
asked (but of course that will increase the time it takes to
Number of fit trials per bootstrap sample (0 to cancel): 1 Peak #1
Width Area Mean:
100.31494 213.20131 STD:
0.7652 STD (IQR):
0.3713 0.35891 %RSD(IQR):
0.37216 0.35992 Elapsed time is 3.060255 seconds.
so on for Peak #2 and the other peaks if a multi-peak fit.
If the RSD and the RSD (IQR) are roughly the same (as in
the example above), then the distribution of bootstrap fitting
results is close to normal and the fit is stable. If the RSD is
substantially greater than RSD (IQR), then the RSD is
biased high by "outliers" (obliviously erroneous fits that fall
far from the norm), and in that case you should use the RSD
(IQR) rather than the RSD, because the IQR is much less
influenced by outliers. Alternatively, you could use another
model or a different data set to see if that gives more stable
Difference between in the F, X, N, and V
F key: Slightly varies the starting
values and performs a single fit using all the data.
X key: Performs 10 trial fits using
all the data, slightly varying the starting values before
each trial, then takes the one with the lowest fitting
error. Press it again to refine the fit. Takes about 10
times longer than the F key.
N key: Slightly varies the starting
values and performs a single fit using a random subset of
the data. Use to visualize the stability of the fit with
respect to random noise. Takes the same time as the F key.
V key: Asks for a number of trial fits, then
performs 100 fits each on a separate random subset of the
data, each fit using the specified number of trials and
taking the best one, then calculates the mean and standard
deviation of the peak parameters of all 100 best-fit
results. Use to quantify the
stability of peak parameters with respect to random noise.
Takes about 100 times longer than the X key.
16. Press K
to display the complete set of keystroke commands. Click here
for more details.