Table of Contents
Name | Direction | Type | Default | Description |
---|---|---|---|---|
InputWorkspace | Input | MatrixWorkspace | Mandatory | An input workspace. |
WorkspaceIndexList | Input | int list | Workspace indices for spectra to process. If empty smooth all spectra. | |
OutputWorkspace | Output | MatrixWorkspace | Mandatory | An output workspace. |
This algorithm smooths the data in a workspace using the Wiener filter method. The fiter is a function which if convolved with an input minimizes the noise in the output.
For more detail see Wikipedia article http://en.wikipedia.org/wiki/Wiener_filter.
WienerSmooth uses the power spectrum of the input signal to build the filter
First the noise level is estimated from the higher frequencies of the power spectrum. Then the fiter function is constructed out of three pieces. The first piece is at the lower frequencies where the power spectrum is well above the noise. At this region the the filter function is calculated with the formula:
where is the power spectrum and is the noise. The higher the power spectrum the closer the filter function to 1.
At the medium frequency range where the power spectrum is getting closer to the noise the filter is described with a piece of a sigmoid decreasing to about the noise level. After that all values are set to zero.
In this example the black curve is the input data and the red one is the result of smoothing.
The image below shows the Wiener filter function used (red) along with the power spectrum of the data (black).
Example - Smooth noisy data
import random
import math
# Define a function
def fun(x):
return math.sin(x) + x /10
# Create a workspace with noisy data.
# Size of the data set
n = 200
# Define the x-values
interval = (-10.0,10.0)
dx = (interval[1] - interval[0]) / (n - 1)
x = [interval[0] + dx * i for i in range(n)]
# Define the y-values as a function fun(x) + random noise
noise = 0.1
y = [fun(x[i]) + random.normalvariate(0.0,noise) for i in range(n)]
# Create a workspace
ws = CreateWorkspace(x,y)
# Smooth the data using the Wiener filter
smooth = WienerSmooth(ws,0)
Categories: AlgorithmIndex | Arithmetic\FFT | Transforms\Smoothing
C++ source: WienerSmooth.cpp (last modified: 2019-07-17)
C++ header: WienerSmooth.h (last modified: 2018-10-05)