index previous next

iSignal: Interactive Smoothing, Differentiation, and Peak Sharpening (version 1.95)

iSignal is a Matlab function, written as a single self-contained m-file, for performing smoothing, differentiation, and peak sharpening (resolution enhancement) 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 "iSignal19.zip" that also includes some sample data for testing. You can also download it from the Matlab File Exchange. Version 1.95, May, 2012. T. C. O'Haver (toh@umd.edu). The syntax is:

Y=isignal(Data);
or
Y=isignal(Data,xcenter,xrange,SmoothMode,SmoothWidth,ends,DerivativeMode,Sharpen,Sharp1,Sharp2);

"Data" may be a 2-column matrix with the independent variable (x-values) in the first column and dependent variable (y values) in the second column, or separate x and y vectors, or a single y-vector (in which case the data points are plotted against their index numbers on the x axis). Only the first argument (Data) is required; all the others are optional. Returns the processed independent axis (Y) vector as the output argument. Plots the data in the figure window, the lower half of the window showing the entire signal, and the upper half showing a selected portion controlled by the pan and zoom keystrokes, with the initial pan and zoom settings optionally controlled by input arguments 'xcenter' and 'xrange', respectively. Other keystrokes allow you to control the smooth type, width, and ends treatment, the derivative order (0th through 4th), and peak sharpening. (The initial values of all these parameters can be passed to the function via the optional input arguments SmoothMode, SmoothWidth, ends, DerivativeMode, Sharpen, Sharp1, and Sharp2. See the examples below). Press K to see all the keyboard commands.
 
Smoothing   
Reference: http://terpconnect.umd.edu/~toh/spectrum/Smoothing.html
The S key (or input argument "SmoothMode") cycles through five smoothing modes:
    If SmoothMode=0, the signal is not smoothed.
    If SmoothMode=1, rectangular (sliding-average or boxcar)
    If SmoothMode=2, triangular (2 passes of sliding-average)
    If SmoothMode=3, pseudo-Gaussian (3 passes of sliding-average)
    If SmoothMode=4, Savitzky-Golay smooth (thanks to Diederick).
The A and Z keys (or optional input argument SmoothWidth) control the SmoothWidth, w.
The X key toggles "ends" between 0 and 1. This determins how the "ends" of the signal (the first w/2 points and the last w/2 points) are handled when smoothing:
    If ends=0, the ends are zero.
    If ends=1, the ends are smoothed with progressively smaller smooths the closer to the end.
Generally, ends=1 is best, except in some cases using the derivative mode when ends=0 result in better vertical centering of the signal.
Note: when you are smoothing peaks, you can easily measure the effect of smoothing on peak height and width by turning on peak measure mode (press P) and then press S to cycle through the smooth modes.
 
Differentiation 
Reference: http://terpconnect.umd.edu/~toh/spectrum/Differentiation.html
The D key (or optional input argument "DerivativeMode") cycles through the derivative orders 0, 1, 2, 3, 4, and then back to 0.  The default is 0.  Careful optimization of smoothing of derivatives is critical for acceptable signal-to-noise ratio. In iSignal version 1.9 and above, in SmoothModes 1 through 3, derivatives are computed with respect to the independent variable (x-values), corrected for non-uniform x axis intervals. In SmoothMode 4 (Savitzky-Golay) the derivatives are computed by the Savitzky-Golay algorithm.
 
Peak sharpening (resolution enhancement)
Reference: http://terpconnect.umd.edu/~toh/spectrum/ResolutionEnhancement.html
The E key (or optional input argument "Sharpen") turns off and on peak sharpening (resolution enhancement). The sharpening strength is controled by the F and V keys (or optional input argument "Sharp1") and B and G keys (or optional argument "Sharp2"). The optimum values depend on the peak shape and width. For peaks of Gaussian shape, a reasonable value for Sharp1 is PeakWidth2/25 and for Sharp2 is PeakWidth4/800 (or PeakWidth2/6 and PeakWidth4/700 for Lorentzian peaks), where PeakWidth is the full-width at half maximum of the peaks expressed in number of data points.  However, you don't need to do the math yourself; iSignal can calculate sharpening and smoothing settings for Gaussian and for Lorentzian peak shapes using the Y and U keys, respectively. Just isolate a single typical peak in the upper window using the pan and zoom keys, then press Y for Gaussian or U for Lorentzian peaks.  (The optimum settings depends on the width of the peak, so if your signal has peaks of widely different widths, one setting will not be optimum for all the peaks). You can fine-tune the sharpening with the F/V and G/B keys and the smoothing with the A/Z keys. You can expect a decrease in peak width (and corresponding increase in peak height) of about 20% - 50%, depending on the shape of the peak (the peak area is largely uneffected by sharpening).  Excessive sharpening leads to baseline artifacts and increased noise. iSignal allows you to experimentally determine the values of these parameters that give the best trade-off between sharpening, noise, and baseline artifacts, for your purposes. You can easily measure the effect of sharpening quantitatively by turning on peak measure mode (press P) and then press E to toggle the sharpen mode off and on. Note: In iSignal version 1.9 and above, only the Savitzky-Golay smooth mode is used for peak sharpening.

Signal measurement
The cursor keys control the position of the green cursor and the dotted red cursors that mark the selected range displayed in the upper graph window. The label under the top graph window shows the value of the signal (y) at the green cursor, the peak-to-peak (min and max) signal range, the area under the signal, and the standard deviation within the selected range (the dotted cursors).  Pressing the T key toggles off and on the autozero mode. When Autozero is ON, the program automatically subtracts a baseline from the segment of signal displayed in the upper window. The baseline is calculated by computing a quadratic least-squares fit to the signal in the first 1/10th of the points and the signal last 1/10th of the points. Try to adjust the pan and zoom to include some of the baseline at the beginning and end of the segment in the upper window, allowing the automatic baseline subtract gets a good reading of the baseline. The calculation of the signal amplitude, peak-to-peak signal, and peak area are all recalculated based on the baseline-subtracted signal in the upper window.  Pressing the Q key prints out a table of the signal information in the command window.


Signal

Noise
Signal-to-noise ratio (SNR) measurement of a signal with very high SNR.  Left: The peak height of the largest signal peak is measured by placing the green center cursor on the largest peak; peak-to-peak signal=66,000. Right: The noise is measured on a flat portion of the baseline: standard deviation of noise=0.01, therefore the SNR=66,000/.01 = 6,600,000

Background subtraction
In addition to the autozero basline subtraction mode for peak measurement, a background (or baseline) can be subtracted manually from the entire signal in one operation.  The Backspace key starts background correction operation.  In the command window, type in the number of background points to click and press the Enter key. The cursor changes to crosshairs; click along the presumed background in the figure window, starting to the left of the x axis and placing the last click to the right of the x axis.  When the last point is clicked, the linearily interpolated baseline between those points is subtracted from the signal. To restore the original background (i.e. to start over), press the '\' key (just below the backspace key).

Saving the results
To save the processed signal as a .mat file, press the 'o' key, the type in the desired file name, then press Enter or click Save.

Peak and valley measurement
The P key toggles off and on the "peak parabola" mode, which attempts to measure the one peak (or valley) that is centered in the upper window under the green cursor by superimposing a least-squares best-fit parabola, in red, on the center portion of the signal displayed in the upper window. (Zoom in so that the red overlays just the top of the peak or the bottom of the valley as closely as possible). The peak position, height, width are measured by least-squares curve fitting of a parabola to the isolated peak. The "RSquared" value is the coefficient of determination; the closer to 1.000 the better. The peak widths will most accurate if the peaks are Gaussian; other shapes, and very noisy peaks of any shape, will give only approximate results. However, the position, height, and area values are pretty good for any peak shape as long as the "RSquared" value is at least 0.99. The peak area is measured by the trapezoidal method over the entire selected segment displayed in the upper window. If the peaks are superimposed on a non-zero background, subtract the background before measuring peaks, either by using the autozero mode (T key) or the multi-point background subtraction (backspace key). Press the R key to print out the peak parameters in the command window.

Other keystroke controls
The L key toggles off and on the Overlay mode, which shows the original signal as a dotted line overlayed on the current processed signal, for the purposes of comparison. The tab key restores the original signal and cursor settings. The ";" key sets the selected region to zero (to eliminate artifacts and spikes). The "-" (minus sign) key is used to negate the signal (flip + for -).  Press H to toggle display of semilog y plot in the lower window, which is useful for signals with very wide dynamic range, as in the example in the figures below (zero and negative points are ignored in the log plot). Press K to see all the keyboard commands:

Linear y-axis mode

Log y mode (H key)


EXAMPLE 1: Single input argument; data in a two columns of a matrix [x;y] or in a single y vector
              >> isignal(y);
              >> isignal([x;y]);
 
EXAMPLE 2: Two input arguments. Data in separate x and y vectors.
              >> isignal(x,y);
 
EXAMPLE 3: Three or four input arguments. The last two arguments specify the initial values of pan (xcenter) and zoom (xrange) in the last two input arguments. Using data in the ZIP file:          
              >> load data.mat

              >> isignal(DataMatrix,180,40); or
              >> isignal(x,y,180,40);
 
EXAMPLE 4: As above, but additionally specifies initial values of SmoothMode, SmoothWidth, ends, and DerivativeMode in the last four input arguments. 
              >> isignal(DataMatrix,180,40,2,9,0,1);
 
EXAMPLE 5: As above, but additionally specifies initial values of the peak sharpening parameters Sharpen, Sharp1, and Sharp2 in the last three input arguments.  Press the E key to toggle sharpening on and off for comparison.
              >> isignal(DataMatrix,180,40,4,19,0,0,1,51,6000);
 
EXAMPLE 6:  Using the built-in "humps" function:
              >> x=[0:.005:2];y=humps(x);Data=[x;y];

                        4th derivative of the peak at x=0.9:
              >> isignal(Data,0.9,0.5,1,3,1,4); (shown on the right)

                        Peak sharpening applied to the peak at x=0.3:
              >> isignal(Data,0.3,0.5,1,3,1,0,1,220,5400);  (shown on the right)
                        (Press 'E' key to toggle sharpening ON/OFF to compare)
 
 
KEYBOARD CONTROLS
:
  Pan signal left and right...Coarse pan: < and >
                              Fine pan: left and right cursor arrows
                              Nudge one point left or right: [ and ]
  Zoom in and out.............Coarse zoom: / and " 
                              Fine zoom: up and down cursor arrows
  Reset pan and zoom..........ESC (resets to initial default values)
  Adjust smooth width.........A,Z (A=>more smoothing, Z=>less
smoothing)
  Adjust smooth type..........S (None, Rectanglular, Triangle, Gaussian, Savitzky-Golay)
  Toggle smooth ends..........X (0=ends zeroed  1=ends smoothed
  Adjust derivative order.....D (0th to 4th order)
  Toggle peak sharpening......E (0=OFF 1=ON)
  Sharpening for Gaussian.....Y  Set sharpen settings for Gaussians
  Sharpening for Lorentzian...U  Set sharpen settings for Lorentzians
  Adjust sharp1...............F,V  F=>sharper, V=>less sharpening
  Adjust sharp2   ............G,B  G=>sharper, B=>less sharpening
  Toggle peak labeling........P  labels center peak in upper window
  Toggle overlay mode.........L Overlays original signal in upper window
  Toggle log y mode...........H  Display semilog y plot in lower window
  Toggle Autozero OFF/ON......T  Subtracts background from upper window segment
  Restores original signal....Tab key resets to original signal and modes
  Baseline subtraction........Backspace, then click baseline at 8 points
  Restore background..........\  to cancel previous background subtraction
  Invert signal...............-  Invert (negate) the signal (flip + and -)
  Remove offset...............0  (zero) set minimun signal) to zero
  Trim region to zero.........;  sets selected region to zero.
  Print keyboard commands.....K  prints this list
  Print signal report.........Q  prints signal info and current settings
  Print isignal arguments.....W  prints isignal (with current arguments)
  Save output to disk.........O as .mat file containing processed signal


Earlier versions
Earlier versions of iSignal as also available: Version 1, Version 1.5 , Version 1.6Version 1.7,  Version 1.8.

May, 2012
Tom O'Haver
Professor Emeritus
Department of Chemistry and Biochemistry
The University of Maryland at College Park
toh@umd.edu
http://www.wam.umd.edu/~toh


index previous next

Number of unique visits since May 17, 2008:

counter
create hit