function function [pY,SpectrumOut]=isignal(DataMatrix,xcenter,xrange,sm,sw,em,dm,rm,s1,s2,sr,mw)
Version 5.7 adds Shift-L to replace signal with processed version, and Shift-V for Fourier convolution/deconvolution function menu.
An interactive function that performs smoothing, differentiation, peak sharpening, and power spectrum analysis of a time-series signal, which 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. Returns the processed independent axis (Y) vector as the output argument. The lower half of the figure window shows a plot of the entire signal, and the upper half shows a selected portion controlled by the pan and zoom keystrokes or by optional input arguments 'xcenter' and 'xrange', respectively. Other keystrokes also allow you to control the smooth type, width, and ends treatment, the derivative order (0th through 5th), and peak sharpening. (Alternatively, the initial values of these parameters can be passed to the function via the optional input arguments sm, sw, em, dm, rm, s1, s2, sr, and mw).
The S key (or optional argument "sm") determines the smooth mode:
If sm=0, the signal is not smoothed.
If sm=1, rectangular (sliding-average or boxcar)
If sm=2, triangular (2 passes of sliding-average)
If sm=3, pseudo-Gaussian (3 passes of sliding-average)
If sm=4, Savitzky-Golay smooth
The A and Z keys (or optional argument sw) control the smooth width.
The X key (or argument "em") controls how the "ends" of the signal (the first w/2 points and the last w/2 points) are handled.
If ends=0, the ends are zero.
If ends=1, the ends are smoothed with progressively smaller smooths the closer to the end.
The D key (or optional input argument "dm") determines the derivative
order (O, 1, 2, 3, 4, or 5). See
The E key (or optional argument "rm") turns off and on peak
sharpening (resolution enhancement). The sharpening strength is
controled by the F and V keys (optional argument "s1") and B and G
keys (optional argument "s2"). The optimum values depend on the peak shape and width; For details, see http://terpconnect.umd.edu/~toh/spectrum/InteractiveResEnhance.htm).
The Backspace key starts background correction mode. The cursor changes to crosshairs; click it at multiple points along the presumed background. When the last point is clicked, the linearly interpolated baseline between those points is subtracted from the signal. To restore the original background (i.e. to correct an error or to try again), press the '\' key (just below the backspace key).
The P key toggles off and on the peak measure mode, which measures and displays the peak position, height, width, and area of the one peak at a time if it is centered and zoomed in; a red "cap" on the peak indicates that portion of the signal that is taken for the measurement. Press the 'R' key to print out the peak measures in the command window. Press the T key to activate the "autozero" mode, which subtracts a quadratic background from the signal segment in the upper window.
The L key toggles off and on the Overlay mode, which overlays the selected portion in the upper plot with the original signal as a dotted line, for comparison.
Press K to see all keyboard commands.
EXAMPLE 1: Data in two columns of a matrix.
>> load data.mat
EXAMPLE 2: Data in separate x and y vectors
>> isignal(x,y); or
EXAMPLE 3: As above, but specifies initial values of pan (xcenter) and
zoom (xrange) in the last two input arguments.
>> isignal(DataMatrix,180,40); or
EXAMPLE 4: As above, but additionally specifies initial values of
SmoothMode, SmoothWidth, ends, and DerivativeMode.
EXAMPLE 5: As above, but additionally specifies initial values of the
peak sharpening parameters Sharpen, Sharp1, and Sharp2.
EXAMPLE 6: >> x=[0:.005:2];y=humps(x);Data=[x;y];
4th derivative of the peak at x=0.9:
Peak sharpening applied to the peak at x=0.3:
(Press 'E' key to toggle sharpening ON/OFF)
Shift-F does it. In iPeak, it the 'N' key.
how about adding a keyboard shortcut that gives a list of the peak shapes? Same proposal applies to your other functions like iPeak.
Tom, this is a great tool!! Thanks very much for sharing it!!!
Hmmmm, "range" is a built-in Matlab function, or at least it has been in several recent versions. Here's the definition; you can copy and paste this into the editor and save it in your path.
function y = range(x,dim)
%RANGE Sample range.
% Y = RANGE(X) returns the range of the values in X. For a vector input,
% Y is the difference between the maximum and minimum values. For a
% matrix input, Y is a vector containing the range for each column. For
% N-D arrays, RANGE operates along the first non-singleton dimension.
% RANGE treats NaNs as missing values, and ignores them.
% Y = RANGE(X,DIM) operates along the dimension DIM.
% See also IQR, MAD, MAX, MIN, STD.
% Copyright 1993-2004 The MathWorks, Inc.
% $Revision: 126.96.36.199 $ $Date: 2004/07/05 17:03:18 $
if nargin < 2
y = max(x) - min(x);
y = max(x,,dim) - min(x,,dim);
I tried to run the sunspots data (from your website) through the iSignal's frequency spectrum function but MATLAB returned the following error:
Undefined function 'range' for input arguments of type 'double'.
Error in isignal>PlotFrequencySpectrum (line 1805)
Error in isignal>ReadKey (line 1110)
Error while evaluating figure KeyPressFcn
Why is it so and how do I fix it?
You help will be much appreciated, thank you!
Tom, thanks for the update! It works now.
Sorry about that; I'll fix it presently. In the meantime, here's that gaussian.m function:
function g = gaussian(x,pos,wid)
% gaussian(x,pos,wid) = gaussian peak centered on pos, half-width=wid
% x may be scalar, vector, or matrix, pos and wid both scalar
% T. C. O'Haver, 1988
% Example: gaussian([1 2 3],1,2) gives result [0.5000 1.0000 0.5000]
g = exp(-((x-pos)./(0.6005612.*wid)) .^2);
The isignaldemo fails to run. I have an undefined function 'gaussian' at line 37. As far I can tell from the MATLAB help, this is not a built in function in any of the toolboxes. What function are you using? And where did you get 'gaussian' so that I can try the demo?
Version 2.8 has an improved frequency Spectrum function that remains active when changing the smoothing, differentiation, and other functions, allowing you to see the effect on the frequency spectrum immediately. Press Shift-S again to return to the normal mode.
Version 2.2 adds a slew rate limit (~ key) and median filter (M key) for removing sharp spike artifacts from the signal.
In version 2.0, the C key condenses oversampled signals by the specified factor N, replacing each group of N points with their average. The I key replaces the signal with a linearily interploated version containing a specified number of data points.
Version 1.95, submitted May 15, 2012, has bug fixes in background correction and peak measurememnt modes.
Adds Shift-L to replace signal with processed version; Shift-V for Fourier convolution/Deconvolution function menu. Some bug fixes.
Version 5.5, April, 2016, adds Shift-T command to replace signal with its frequency spectrum; adds measurement of full width at half maximum (FWHM) .
Version 4.4 has several small additions and corrections.
Version 4 adds Shift-o to perform pOlynomial least-squares of the selected segment.
Version 3.4: In spectrum mode, Shift-Z toggles on and off frequency/time
Version 3. Adds Shift-W, display Waterfall spectrum in Figure 2.
Version 2.95, March, 2014. Adds ability to save frequency spectrum as a variable.
Corrects "missing function" error in isignaldemo.m
Version 2.9: Includes version 4.2 of peakfit.m, which adds a Voigt profile peak shape and flat baseline mode for iterative least-squares fits.
Version 2.8: Improved frequency Spectrum function
Version 2.7: Added peakfit function (Shift-F); Added frequency Spectrum function (Shift-S)
Adds slew rate limit (~ key) and spike filter (M key). Measures peak area two ways. Fixes several bugs related to input arguments. Computes signal-to-noise ratio (SNR) in Peak mode.
Version 2.1: Added slew rate limit (~ key) and median filter (M key) to reduce spikes.
Version 2.0: adds C key (condense signal), I key (interpolate signal); O key now saves processed signal to disc as a matrix in a .mat file.
Version 1.95: Bug fixes in backgrouond correction and peak measurememnt modes.
Version 1.9: Derivatives computed with respect to x, corrected for non-uniform x axis intervals. Minor bug fixes and display improvements.
Added Savitzky-Golay smooth (thanks to Diederick)
Version 1.7 adds a quadratic background subtraction mode, other small additions and bug fixes.
Corrected error in description
Version 1.6 can accept single vector inputs as well as matrix and x,y and adds semilog plot mode for overall signal (press H key).
Version 1.4 adds area to signal info (Q); green center cursor, bug fixes.
Version 1.2 adds several new functions.
Download apps, toolboxes, and other File Exchange content using Add-On Explorer in MATLAB.