GAUSSIAN_FILTER1D

The 1-D Gaussian filter is a linear filter that smoothes a signal by convolving it with a Gaussian function. This process effectively removes high-frequency noise from the signal while preserving its overall shape and characteristics.

The Gaussian kernel is defined as:

G(x) = \frac{1}{\sqrt{2\pi}\sigma} e^{-\frac{x^2}{2\sigma^2}}

where \sigma is the standard deviation that determines the width of the filter. Larger \sigma values result in more smoothing.

Excel Usage

=GAUSSIAN_FILTER1D(input_data, sigma, axis, order, gaussian_mode, cval, truncate)
  • input_data (list[list], required): The input array (Excel range).
  • sigma (float, required): Standard deviation for Gaussian kernel (determines smoothing width).
  • axis (int, optional, default: -1): The axis along which to calculate.
  • order (int, optional, default: 0): Order of the derivative (0 for smoothing).
  • gaussian_mode (str, optional, default: “reflect”): Extension mode for padded signal.
  • cval (float, optional, default: 0): Value to fill past edges if mode is ‘constant’.
  • truncate (float, optional, default: 4): Truncate the filter at this many standard deviations.

Returns (list[list]): The smoothed signal as a 2D array.

Example 1: Simple smoothing

Inputs:

input_data sigma
1 2 3 4 5 1

Excel formula:

=GAUSSIAN_FILTER1D({1,2,3,4,5}, 1)

Expected output:

Result
1.42704 2.06782 3 3.93218 4.57296
Example 2: Higher sigma smoothing

Inputs:

input_data sigma
1 2 3 4 5 4

Excel formula:

=GAUSSIAN_FILTER1D({1,2,3,4,5}, 4)

Expected output:

Result
2.91948 2.95024 3 3.04976 3.08052

Python Code

Show Code
import numpy as np
from scipy.ndimage import gaussian_filter1d as scipy_gaussian

def gaussian_filter1d(input_data, sigma, axis=-1, order=0, gaussian_mode='reflect', cval=0, truncate=4):
    """
    1-D Gaussian filter for signal denoising and smoothing.

    See: https://docs.scipy.org/doc/scipy/reference/generated/scipy.ndimage.gaussian_filter1d.html

    This example function is provided as-is without any representation of accuracy.

    Args:
        input_data (list[list]): The input array (Excel range).
        sigma (float): Standard deviation for Gaussian kernel (determines smoothing width).
        axis (int, optional): The axis along which to calculate. Default is -1.
        order (int, optional): Order of the derivative (0 for smoothing). Default is 0.
        gaussian_mode (str, optional): Extension mode for padded signal. Valid options: Reflect, Constant, Nearest, Mirror, Wrap. Default is 'reflect'.
        cval (float, optional): Value to fill past edges if mode is 'constant'. Default is 0.
        truncate (float, optional): Truncate the filter at this many standard deviations. Default is 4.

    Returns:
        list[list]: The smoothed signal as a 2D array.
    """
    try:
        def to2d(x):
            return [[x]] if not isinstance(x, list) else x

        data = np.array(to2d(input_data), dtype=float)

        result = scipy_gaussian(
            data, 
            sigma=float(sigma), 
            axis=int(axis), 
            order=int(order), 
            mode=gaussian_mode, 
            cval=float(cval), 
            truncate=float(truncate)
        )

        return result.tolist()
    except Exception as e:
        return f"Error: {str(e)}"

Online Calculator

The input array (Excel range).
Standard deviation for Gaussian kernel (determines smoothing width).
The axis along which to calculate.
Order of the derivative (0 for smoothing).
Extension mode for padded signal.
Value to fill past edges if mode is 'constant'.
Truncate the filter at this many standard deviations.