index previous next

Signal Processing Tools

Free downloadable Matlab functions for scientists

Last updated September, 2014

A retirement project by Tom O'Haver
Professor Emeritus
Department of Chemistry and Biochemistry
University of Maryland at College Park

Have a question? E-mail: toh@umd.edu
or join our group on Facebook

Scripts written for Matlab (PC, Macintosh, or Unix)

This page describes a series of downloadable Matlab interactive signal processing tools for x,y time-series data. Documentation and examples of application are provided in "A Pragmatic Introduction to Signal Processing", available in HTML and PDF formats.

Note: all of the scripts and functions described below are written as self-contained Matlab functions (m-files) and require no add-on toolboxes to run. They have been developed and tested in Matlab 7.8 R2009a. All of the interactive functions run in the Figure window and use a simple set of keystroke commands, rather than a GUI (Graphic User Interface), in order to reduce screen clutter, minimize overhead, and maximize processing speed. Press K to see the list of keystroke commands within each program. The Figure window can be re-sized as you wish, including maximized to full-screen to see the maximum detail in the signals. My goal is to make these programs very easy to get working, with flexible input syntax, built-in help, extensive online documentation, and many simple examples that you can copy and paste into your Matlab command window.
   
These scripts are downloaded about 1000 times per month on average and have been used by thousands of scientists, engineers, researchers, instructors, and students. They have been applied in many areas of investigation and have been cited in over 70 published papers, theses, and patents. See the unsolicited user comments below from actual users of these programs. User comments and suggestions have often resulted in changes and new features being added to the latest version; keep those emails coming.

First time here? Check out the animated demos of ipeak.m and ipf.m. Or download these Matlab demos that compare ipeak.m with peakfit.m for signals with a few peaks and signals with many peaks and that shows how to adjust ipeak to detect broad or narrow peaks. These are self-contained demos that include all required Matlab functions. Just place them in your path and click Run or type their name at the command prompt. Or you can download all these demos together in idemos.zip.

Author's appreciation: I wish to express my thanks and appreciation for all those who have made useful suggestions, corrected errors, and who have sent me data from their work to test my programs on.  These contributions have really helped to correct bugs and to expand the capabilities of my programs.
 

Peak Finding and Measurement  

Matlab routines for locating and measuring the peaks (or valleys) in noisy time-series data sets. It detects peaks by looking for downward zero-crossings (or upward zero-crossings for valleys) in the smoothed first derivative then determines the position, height, and width of each peak by least-squares curve-fitting of the raw data near the detected peaks. (This is useful primarily for signals that have several data points in each peak, not for spikes that have only one or two points).

There are both command-line and interactive versions:
(1) a set of command-line functions for Matlab and Octave, for finding peaks in signals and measuring their positions, heights, widths, and areas by least-squares curve-fitting, especially useful as modules to use in your own custom scripts and functions to automate data processing.
(2) a Matlab-only interactive keypress-operated function (iPeak) for adjusting the peak detection criteria interactively to optimize peak detection and measurement, for Matlab. There is an animated demonstration.  

These tools are the ones to use when (a) the quantities of greatest interest are the peak positions and amplitudes of the positive peaks in your signal, (b) the peaks have distinct (even if noisy) maxima, and (c) when you want all the peaks numbered and quantified in one operation. You can use the interactive iPeak function to determine the ideal input arguments for the findpeaks.m and findpeaksfit.m command-line functions.  Note: the latest version of  iPeak can perform iterative non-linear curve fitting on the peaks that it finds, using the built-in peakfit.m function (described below); this is useful for highly overlapped or non-Gaussian peaks. For some demos, download idemos.zip.

iSignal: Interactive Smoothing, Derivative, and Signal Analysis

iSignal is a Matlab function, written as a single self-contained m-file, for performing smoothing, differentiation, peak sharpening (resolution enhancement), frequency spectrum, least-squares peak fitting, and other useful functions on time-series data. Using simple keystrokes, you can adjust the signal processing parameters continuously while observing the effect on your signal dynamically.  Click here to download the ZIP file "iSignal3.zip" that also includes some sample data for testing. You can also download it from the Matlab File Exchange

This is the tool to use when you want to explore and clean up your signals and to try smoothing, differentiation, and peak sharpening. It measures things like peak-to-peak signal amplitude, standard deviation, frequency spectra, and the area under the curve of selected portions of your signal. It's also good for quickly measuring peak positions, heights, areas (one peak at a time) and for determining how smoothing, differentiation, and peak sharpening effect the signal and its frequency spectrum. It can also pre-process signals to re-sample them by interpolation, and reduce or remove artifacts such as spikes (with the median filter) and steps (with a rate-limiting filter). 


Peak Fitters 

Peak fitting programs for time-series signals, which use a non-linear optimization algorithm to decompose a complex overlapping-peak signal into its component parts. The objective is to determine whether your signal can be represented as the sum of fundamental underlying peaks shapes. Accepts signals of any length, including those with non-integer and non-uniform x-values. Fits groups of peaks of many different shapes). There two different versions:

(1) peakfit.m, a command line versionfor Matlab and Octave, that fits a predetermined number of peaks, and findpeaksfit.m, which uses findpeaks.m to locate peaks as input for the peakfit.m function (Octave users must install the "optim_1.2.2" package).
(2) Interactive Peak Fitter, ipf.m, a keypress-operated interactive version, for Matlab, that allows you to pan and zoom through the signal to pick the groups of peaks to fit.. Does not work in Octave. There is an animated demonstration.

The difference between them is that peakfit.m and findpeaksfit.m are completely controlled by command-line input arguments and returns its information via command-line output arguments; ipf.m allows interactive control via keypress commands. Otherwise they have the same curve-fitting capabilities. You can also download a ZIP file containing peakfit.m, DemoPeakFit.m, ipf.m, Demoipf.m, some sample data for testing, and a test script (testpeakfit.m) that runs all the examples sequentially to test for proper operation. 

These tools are the ones to use when (a) you need to measure the peak positions, amplitudes, widths, and areas of the positive peaks in your signal, (b) the peaks are highly overlapped, (c) you want specific peaks in your signal quantified, and (d) your peaks are approximately Gaussian, Lorentzian, Pearson, Logistic, or exponentially-  broadened Gaussian. You can use the interactive ifp.m function to determine the ideal input arguments for the peakfit.m and command-line function. Note: iterative non-linear curve fitting can also performed by the latest version of the interactive peak finder described above (iPeak). For some demos comparing peakfit.m to iPeak.m, download idemos.zip.


iFilter: Interactive Fourier Filter


iFilter is a Matlab implementation of a Fourier filter function for time-series signals, including interactive versions that allow you to adjust the filter parameters continuously while observing the effect on your signal dynamically. By adjusting the parameters, you can create lowpass, highpass, bandpass, and band-reject
(notch), comb pass, and comb reject filters with variable, frequency, width, and cut-off rate. . The x-axis is labeled for time-based signals, where the independent variable is time in seconds, but the program can be used with any frequency axis (e.g. spacial frequency, etc).  Click here to view or download iFilter.m  You can also download it from the Matlab File Exchange. Version 4, May, 2014.

This is the tool to use when you want to explore the frequency components of your signals and to design a custom filter that will optimize your signals.

Hyperlinear quantitative absorption spectroscopy

Matlab implementation of a computational method for quantitative analysis by multiwavelength absorption spectroscopy, called the transmission-fitting or ďTFitĒ method, based on measuring the underlying absorbance by fitting a model of the instrumentally-broadened transmission spectrum to the observed transmission data, rather than by direct calculation of absorbance as simply log10(Izero/I). 

Advantages of the TFit method compared to conventional methods are: (a) wider dynamic range; (b) greatly improved calibration linearity; (c) ability to operate under conditions that are optimized for signal-to-noise ratio ratio rather than for optical ideality. With a linear response, absorbance can be converted to concentration simply by multiplying by a constant factor.

Just like the multilinear regression (classical least squares) methods conventionally used in absorption spectroscopy, the Tfit method (a) requires an accurate reference spectrum of each analyte, (b) utilizes multiwavelength data such as would be acquired on diode-array, Fourier transform, or automated scanning spectrometers, and (c) applies both to single-component and multi-component mixture analysis.

tfit.m is a command-line demo function for Matlab or Octave. TFitDemo.m is an interactive demo m-file that works in recent versions of Matlab. Version 2.1, November 2011.

iPower: Interactive Power Spectrum Demo

Matlab keyboard-controlled interactive power spectrum demonstrator, useful for teaching and learning about the power spectra of different types of signals and the effect of signal duration and sampling rate. Single keystrokes allow you to select the type of signal (12 different preset signals included), the total duration of the signal, the sampling rate, and the global variables f1 and f2 which are used in different ways in the different signals. If you know some basic Matlab programming, you can even add your own custom signal functions to this program. When the Enter key is pressed, the signal (y) is sent to the Windows WAVE audio device. Press K to see a list of all the keyboard commands. Tested in Matlab version 7.8 (R2009a).

Click here to view or download.  You can also download it from the Matlab File Exchange. Version 2, October 2011

Diffraction Grating Demos

A set of keyboard-controlled interactive demonstration modules, written as self-contained Matlab functions, that are useful for learning and teaching the principles of diffraction gratings. Shows a working cross section of the geometry of a diffraction grating (a common illustration in textbooks of optics, spectroscopy, and analytical chemistry). Single keystrokes allow you to control such variables as the angle of incidence, grating ruling density, wavelength, and diffraction order. One module shows how the operation of a diffraction grating emerges naturally just by adding up a bunch of sine waves, without any higher math at all. 

Press K to see a list of all the keyboard commands. Tested in Matlab version 7.8 (R2009a).

Click here to download ZIP file.  You can also download it from the Matlab File Exchange. Version 2, November 2011.

There is also a set of spreadsheets in Excel (.xls) and OpenOffice (.ods) format that illsutrate grating operation in an interactive way, with sliders and number wheels to change parameters. 

Note: The interactive functions iPeak, iSignal, and ipf, all have several keystroke commands in common: all share the same set of pan and zoom keys (cursor arrow keys, < and > keys, [ and ] keys, etc) to adjust the portion of the signal that is displayed in the upper panel. All use the K key to display the list of keystroke commands. All use the T key to cycle through the four baseline connection modes. All use the Shift-Ctrl-S, Shift-Ctrl-F, and Shift-Ctrl-P keys to transfer the current signal between iSignal, ipf, and iPeak, respectively. To make it easier to transfer settings from one of these functions to other related functions, all use the W key to print out the syntax of other related functions, with the pan and zoom settings and other numerical input arguments specified, ready for you to Copy, Paste and edit into your own scripts or back into the command window. For example, you can convert a curve fitting operation performed in ipf.m into the command-line peakfit.m function; or you can convert a peak finding operation performed in ipeak.m into a command-line findpeaks.m or findpeaksb.m functions.

Background information on these and other signal processing methods is available in:

A Pragmatic Introduction to Signal Processing in Chemical Analysis

An illustrated essay available in Web, OpenOffice, Word , and PDF  format




Unsolicited Comments from Users

" Your program iPeak is like falling out of a tree and landing in a soft couch complete with a book and a good reading light!"

"...thanks a lot for...your wonderful [peak fitter] program. I use it on a regular basis...."

"...your interactive peak fitter code for Matlab...has been very useful!"

"Interactive Peak Fitter...worked very well. In a word, it's perfect!" 

"...iSignal 3...is a great tool!!"

"Your code is quite amazing."

"Iíve just download your very nice PeakFitter. Itís WONDERFUL!"

"You have great detailed instructions!"

"...you can't imagine how MUCH we'll use this."

"...thank you for taking the time to create these incredible tools."

"...your scripts findpeaks.m and ipeaks.m ... [are] super useful"

" ...thank you for the scripts that you developed which are a very useful help for a lot of people in science research."

"I got some really good results using Ipeak.

"This program [Peak Fitter] is perfect."

"I find these routines and the information on your website immensely valuable."

"I recently found your website and Iím really impressed, great work! "

"I have been using your "findpeaks" routine (matlab version) and it is working superbly."

"Your peak picking algorithm is very helpful to me."

"As far as I am concerned your code is perfect..."

"Your peakfit function is very powerful. I had test many data with success."

"I'm impressed at the convenience of your Peak Fitter and Interactive Peak Fitter programs."

"I found your Peak Fitter program to be incredibly useful for some work I am doing...."

"I found your Matlab functions for peak detection very useful for my research. Thanks for making this resource available, it's been of great help to me". 

"Best fitter available for Matlab, thanks for this wonderful work."

"I have to say thank you for the great work you done with the peak finding methods for Matlab. It is really great."

"I've been using ipeak over the past few weeks and this is a wonderful tool."

"These are very good script(s)....The scripts are very useful to help to solve my problem...."

"[It's] exactly what I needed....The result looks really great!"

"I have been using your interactive peak fitter Matlab tool for a few months now, and I have to say that itís a wonderfully powerful and easy to use program.  I have been recommending it to everyone who asks for peak fitting programs".  

"Great code....Wonderfully documented!

"I am using your peakfitter in Matlab and love it....worked like a charm

"I've been having great success with ipf and peakfit..."

"...it really is a fine manual - your pdf document on curve fitting." 

"Your Interactive Peak Fitter ... is very helpful."

"Your peak finding and fitting scripts ... turned out handy in analyzing my research data."

"I found your peakfit.m program and it is great - thank you very much for sharing it!"

"...the codes for finding peaks and mathematical fits to noisy data...were very helpful for my experimental work."

"I appreciate all the work that must have gone into the PeakFit matlab coding. I've been using it for a couple of weeks, now, and it is becoming extremely useful."

"Thank you for your Matlab function findpeaks(). It is quite literally EXACTLY what I was looking for and far better than I could have hoped."

"Thank you so much for designing and creating MATLAB code for scientists! It's such a great resource to have code on MATLAB Central. I really appreciate your efforts."

"Thank you for making available your absolutely superb Peakfinder software. It is a snap to use...."

"Wonderful program."

"This program is fantastic."

"...incredibly useful...."

"... thanks for all the spectroscopy MatLab scripts that you have written and meticulously documented.  Finding them has saved me more than a few hours."

"...excellent piece of software...really useful and instructive".


"...I would like to express my thanks for making such a wonderful tool for derivative spectroscopy, it has been much help for me!

"...Interactive Fourier Filter is a great tool to help with low-, high-, band-pass-, and band-stop filtering, and best of all, you can view the effect of filtering parameters on your time-series as you change them! " (reference)

" I have been using iSignal for the past day to analyze my data, and it works GREAT!.... I am able to extract lots of information from my spectra now.'

"...such a great analysis program....Thank you...for designing such a wonderful program."

"...the tutorials on your website have been of tremendous help to me."

"My data is quite noisy and yet your program is able to fit it with a very low error."

"Your web site has helped me a lot to solve one problem, I will send to you the paper after publishing, so you will see how much important it was for me."

"Your [iSignal] function is very good to explore the smoothing and differentiation filters, I'll recommend it to my new colleagues".

"Thank you for your valuable website & code."

"...your homepage about peak finding and measurement is amazing!"

"This is great. Thank you!"

"...thanks for the great tool! Saved me a lot of work."

"...iPeak ... is very useful."

"...your scripts are wonderful." 

" ...thank you very much for sharing your scripts. It helped me a lot!"

index previous next


Copyright (c) 2014, Thomas C. O'Haver
 
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.


THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.


First edition created in 2006. Last updated August, 2014. This website was created with SeaMonkey. This site is a retirement project maintained by Prof. Tom O'Haver, Professor Emeritus, Department of Chemistry and Biochemistry, The University of Maryland at College Park. Comments, suggestions and questions should be directed to Prof. O'Haver at toh@umd.edu. Number of unique visits to this website since May 17, 2008: