1.12.4 Signal Processing


Origin C provides a collection of global functions and NAG functions for signal processing, ranging from smoothing noisy data to Fourier Transform (FFT), Short-time FFT(STFT), Convolution and Correlation, FFT Filtering, and Wavelet analysis.

The Origin C functions are under the Origin C help -> Origin C Reference -> Global Functions -> Signal Processing category.

Smoothing

The ocmath_smooth function support 3 methods: median filter, Savitzky-Golay smoothing and adjacent averaging smoothing.

vector vSmooth; // output
vSmooth.SetSize(vSource.GetSize());

//do Savitzky-Golay smoothing, Left=Right=7, quadratic
int nLeftpts = nRightpts = 3;
int nPolydeg = 2;
int nRet = ocmath_smooth(vSource.GetSize(), vSource, vSmooth, nLeftpts, SMOOTH_SG, 
	EDGEPAD_NONE, nRightpts, nPolydeg);

FFT

Before using fft_* functions, you need to include fft_utils.h.

#include <fft_utils.h>

FFT

fft_real performs a discrete Fourier transform(FFT_FORWARD) or inverse Fourier transform(FFT_BACKWARD).

fft_real(vSig.GetSize(), vSig, FFT_FORWARD); // return 0 for no error

Frequency Spectrum

fft_one_side_spectrum is used to compute the one side spectrum of FFT Result.

fft_one_side_spectrum(vSig.GetSize(), vSig); // return 0 for no error

IFFT

fft_real(vSig.GetSize(), vSig, FFT_BACKWARD); // return 0 for no error

STFT

The stft_real function is used to perform a Short-Time-Fourier-Transform on 1d signal real data. The stft_complex function is used to perform a Short-Time-Fourier-Transform on 1d signal complex data. The following is an example for real data.

int nWinSize = 4;
vector win(nWinSize);
get_window_data(RECTANGLE_WIN, nWinSize, win);

matrix stft;
double stime, sfreq;
vector sig = {0, 0, 0, 1, 1, 0, 0, 0};
stft_real(sig, win, 0.1, 1, 4, stft, stime, sfreq);

for (int ii = 0; ii < stft.GetNumRows(); ii++)
{
    for (int jj = 0; jj < stft.GetNumCols(); jj++)
        printf ("%f\t", stft[ii][jj]);
    printf ("\n");
}

FFT Filtering

Origin C supports multiple filter types for performing FFT Filtering, including: low pass, high pass, band pass, band block, threshold, and low pass parabolic. For example:

double dFc = 6.5;    
int iRet = fft_lowpass(vecSignal, dFc, &vecTime);

Wavelet Analysis

In Origin C, you can call a NAG function to do Wavelet analysis. To see all wavelet functions, go to the Origin C Help -> Origin C Reference -> Global Function -> NAG Functions -> Accessing NAG Functions Category and Help -> Wavelet category. It is necessary to include the related header.

#include <..\OriginLab\wavelet_utils.h>

The following is an example of a real type, one-dimensional, continuous wavelet transform.

int n = vX.GetSize();
int ns = vScales.GetSize();
matrix mCoefs(ns, n);

NagError fail;
nag_cwt_real(Nag_Morlet, 5, n, vX, ns, vScales, mCoefs, &fail);