gausswin
The Gaussian window.
| Library |
|
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.
|
| Типы данных |
|
# 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.
| Типы данных |
|
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)
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)
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)
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)