Engee documentation

gausswin

The Gaussian window.

Library

EngeeDSP

Syntax

Function call

  • w = gausswin(L) — returns L-a point-based Gaussian window.

  • w = gausswin(L,alpha) — returns L-a point Gaussian window with a width coefficient alpha.

    If the window appears to be cropped, increase the number of dots. L.

Arguments

Input arguments

# L — window length

+ a positive integer

Details

The window length, set as a positive integer.

If you ask L as a non-integer number, the function will round it to the nearest integer value.
Типы данных

Float32, Float64, Int8, Int16, Int32, Int64, UInt8, UInt16, UInt32, UInt64

# alpha — width coefficient

+ 2.5 (by default) | positive real scalar

Details

The width coefficient, set as a positive real scalar. Argument alpha inversely proportional to the width of the window.

Типы данных

Float32, Float64

Output arguments

# w — Gaussian window

+ column vector

Details

A Gaussian window returned as a column vector.

Examples

The Gaussian window

Details

Let’s form a Gaussian window with 64 dots. Let’s display the result using plot.

import EngeeDSP.Functions: gausswin
using Plots

L = 64
w = gausswin(L)

plot(w,
     title = "Time domain",
     xlabel = "Samples",
     ylabel = "Amplitude",
     linewidth = 2,
     color = :blue,
     grid = true)

gausswin 1

import EngeeDSP.Functions: gausswin, fft, fftshift
using Plots

L = 64
w = gausswin(L)
N_fft = 1024

window_fft = fft([w; zeros(N_fft - L)])
freq_response = 20 * log10.(abs.(fftshift(window_fft)) .+ eps())

freq_axis = range(-π, π, length=N_fft)

plot(freq_axis, freq_response,
     title = "Frequency domain",
     xlabel = "Normalized Frequency (×π rad/sample)",
     ylabel = "Magnitude (dB)",
     xlims = (0, π),
     ylims = (-80, 40),
     linewidth = 2,
     color = :blue,
     grid = true)

gausswin 1 1

Gaussian window and Fourier transform

Details

This example shows that the Fourier transform of a Gaussian window is also a Gaussian with an inverse standard deviation. This illustrates the principle of uncertainty of time and frequency.

Let’s form a Gaussian window of length using the function gausswin and the defining equation. Install , this will give the standard deviation . The Gaussian window is, in fact, limited to the average value of plus or minus 3 standard deviations, or an approximate carrier [-12,12].

import EngeeDSP.Functions: gausswin
using Plots

N = 64
n = range(-(N-1)/2, (N-1)/2, length=N)
alpha = 8

w = exp.(-(0.5) * (alpha * n ./ ((N-1)/2)).^2)

stdev = (N-1)/(2*alpha)
y = exp.(-1/2 * (n/stdev).^2)

plot(n, w, label="gausswin", linewidth=2)
plot!(n, y, label="Definition", markershape=:circle, markersize=4, linealpha=0)

xlabel!("Samples")
title!("Gaussian Window, N = $N")
plot!(legend=true)

gausswin 2

We obtain the Fourier transform of the Gaussian window by points. Using the function fftshift to center the Fourier transform at zero frequency (DC).

import EngeeDSP.Functions: fft, fftshift

nfft = 4*N
freq = range(-π, π - π/nfft, length=nfft)

wdft = fftshift(fft(w, nfft))

The Fourier transform of a Gaussian window is also Gaussian with a standard deviation that is the inverse of the standard deviation in the time domain. Consider the Gaussian normalization factor in your calculations.

ydft = exp.(-1/2*(freq/(1/stdev)).^2) * (stdev * sqrt(2*π))

plot(freq/π, abs.(wdft), label="fft", linewidth=2)
plot!(freq/π, abs.(ydft), label="Definition", markershape=:circle, markersize=4, linealpha=0)

xlabel!("Normalized frequency (×π rad/sample)")
title!("Fourier Transform of Gaussian Window")
plot!(legend=true)

gausswin 2 1

Algorithms

The coefficients of the Gaussian window are calculated from the following equation:

where , and inversely proportional to the standard deviation a Gaussian random variable. Exact correspondence to the standard deviation of the Gaussian probability density function: .

Literature

  1. Hansen, Eric W. Fourier Transforms: Principles and Applications. New York: John Wiley & Sons, 2014.

  2. Oppenheim, Alan V., Ronald W. Schafer, and John R. Buck. Discrete-Time Signal Processing. Upper Saddle River, NJ: Prentice Hall, 1999.