Code covered by the BSD License  

Highlights from
fSGolayFilt

5.0

5.0 | 3 ratings Rate this file 21 Downloads (last 30 days) File Size: 20 KB File ID: #5661
image thumbnail

fSGolayFilt

by Jan Simon

 

09 Aug 2004 (Updated 09 Jun 2010)

Fast Savitzky Golay filter as multi-threaded C-Mex

| Watch this File

File Information
Description

fSGolayFilt is a fast polynomial smoothing filter for uniformly spaced signals. This implementation offers less flexibility than other versions found in the MATLAB Central (eg. from Jianwen Luo, YangQuan Chen or Vassili Pastushenko), but it is optimized for speed by using a C-Mex function for the calculations.

Y = fSGolayFilt(X, K, F, [W], [Dim])
INPUT:
  X: Noisy data, real DOUBLE or SINGLE vector or array.
  K: Polynomial order.
  F: Length of the moving window.
  W: Weighting factors, optional.
  Dim: Dimension to operate on, optional.
OUTPUT:
  Y: Smoothed data, same size and type as X.

Compared to SGOLAYFILT of the Signal Processing Toolbox of Matlab 2009a, this implementation is 70% to 85% faster for short [100 x 1] and large [1E7 x 1] vectors (see screenshot taken on a single threaded machine). Multi-threading can increase the speed remarkably, but Matlab's filter method benefits from multiple cores also.

The C-mex have to be compiled as usual: mex -O fSGolayCore.c
Unfortunately multi-threading is implemented for Windows only. For OS-X and Linux a single-thread version is included. For futher help see fSGolayCore.c, e.g.: how to set the maximum number of threads at compile time and limit the number of used threads at run time.
After compiling run the unit-test TestfSGolayFilt to test validity and speed on your machine. The test does not need the Signal-Processing-Toolbox anymore.

Mar-2009: This new version is compatible with 32 and 64 bit addressing. Now the initial and final phases are computed in the Mex also to improve the performance by about 10%.
Jun-2010: Optimized for MSVC 2008 (30% faster). Multi-threading increases the speed in addition. Input [Dim]. Computes DOUBLE and SINGLE arrays.

I'd appreciate suggestions for improvements and bug reports sent through email - thanks.

Acknowledgements

The author wishes to acknowledge the following in the creation of this submission:
Savitzky-Golay Smoothing Filter, Savitzky-Golay Smoothing and Differentiation Filter, 2-D Savitzky-Golay Smoothing Filter, SAVFILT
This submission has inspired the following:
z-transform of 1D & 2D Savitzky-Golay Smoothing and Differentiation Filter

MATLAB release MATLAB 7.8 (R2009a)
Other requirements Tested: Matlab 6.5, 7.7, 7.8, Compiler: LCC2.4/3.8, BCC5.5, Open Watcom 1.8, MSVC 2008 (preferred) Pre-compiled Mex: http://n-simon.de/mex
Tags for This File  
Everyone's Tags
Tags I've Applied
Add New Tags Please login to tag files.
Comments and Ratings (3)
14 Aug 2004 Jianwen Luo

Excellent! The speedup is really dramatic.

01 Dec 2005 Olivier Berné

Fast, Simple, and accurate ! (Works fine on matlab 7.1)

06 May 2011 Rhys

Fantastic! Works ~80x times faster than the script I was using previously. (Matlab 2010a Windows XP 32bit Intel C2D)

Please login to add a comment or rating.
Updates
09 Jun 2009

Inserted a notes for compatibility with Matlab 2009a.

05 Mar 2010

32 and 64 bit addressing, improved performance

09 Jun 2010

SINGLE support, multi-threading, faster execution, Dim can be specified, unit-test does not need SPT anymore.

Tag Activity for this File
Tag Applied By Date/Time
filter design Jan Simon 22 Oct 2008 07:29:34
filter analysis Jan Simon 22 Oct 2008 07:29:34
smoothing Jan Simon 22 Oct 2008 07:29:34
analysis Jan Simon 22 Oct 2008 07:29:34
signal processing Jan Simon 22 Oct 2008 07:29:34
savitzky golay Jan Simon 08 Mar 2010 12:28:29
filter Jan Simon 08 Mar 2010 12:28:29
filter Juan Perez 26 Mar 2010 02:28:14
cmex Jan Simon 09 Jun 2010 12:12:03
multi thread Jan Simon 09 Jun 2010 12:12:03

Contact us at files@mathworks.com