Modal Analysis Part2. Windows

In this article, we'll briefly explore the significance of windows in signal processing and provide a simple Python code example to create a Hanning window.


Understanding Windows in Signal Processing

In the realm of signal processing, windows play a pivotal role in preparing data for analysis in the frequency domain. A windowing function modifies a time-domain signal's properties before transforming it into the frequency domain through techniques like the Fast Fourier Transform (FFT). 


What are Windows in Signal Processing?

Windows, in signal processing, are mathematical functions applied to a dataset to mitigate issues like spectral leakage and artifacts during frequency analysis. These issues often arise due to abrupt signal endings, causing unwanted effects in the frequency domain. Windows act as a weighting function, tapering the signal's edges to minimize these problems.


1. Rectangular Window

The Rectangular window, sometimes referred to as the boxcar or Dirichlet window, is the simplest window function. It essentially involves multiplying the original signal by a rectangular pulse, with the window being one for the entire duration of the signal and zero elsewhere.

Mathematically, the Rectangular window can be represented as:


Where �n is the index of the sample within the window.

2. Triangular Window

The Triangular window, also known as the Bartlett window, resembles a triangular shape with tapering ends. This window function smoothly decreases from the center towards both ends, exhibiting a linearly decreasing amplitude.

Mathematically, the Triangular window can be defined as:

Where:

  • n is the index of the sample within the window.
  • N is the total number of samples in the window.

3. Hanning Window

The Hanning window, also known as the Hann window, is a type of tapering function frequently used due to its desirable characteristics. It smoothly reduces signal amplitudes at both ends, providing better frequency resolution and less spectral leakage compared to other window functions.

Mathematically, the Hanning window can be defined as:


Where:

  • n is the index of the sample within the window.
  • N is the total number of samples in the window.


Applications of Different Windows

  • Rectangular Window: Despite its simplicity, the Rectangular window finds applications in scenarios where spectral leakage is not a concern. It's commonly used in situations where the main objective is to retain the original signal's characteristics without any modification.

  • Triangular Window: The Triangular window, with its tapering edges, provides a compromise between the Rectangular and Hanning windows. It's useful in applications requiring moderate reduction of spectral leakage while still maintaining good frequency resolution. Audio signal processing often employs the Triangular window due to its balanced performance.

  • Hanning Window: As discussed earlier, the Hanning window smoothly tapers the signal at both ends, minimizing spectral leakage and offering enhanced frequency resolution. Its applications range from vibration analysis in mechanical engineering to speech and audio signal processing.


Experimenting with different windowing functions enables signal processors to tailor their approach based on the specific requirements of the application. The choice of window function often depends on the trade-offs between reducing spectral leakage, preserving frequency information, and minimizing artifacts in the frequency domain analysis.


Implementing the Hanning Window in Python

Let's demonstrate how to generate a Hanning window using Python and apply it to a sample signal. We'll visualize the original signal and the windowed signal using Matplotlib.

import numpy as np
import matplotlib.pyplot as plt

# Generating a sample signal (sine wave)
fs = 1000  # Sampling frequency
f = 50     # Frequency of the sine wave
t = np.linspace(0, 1, fs, endpoint=False)  # Time vector
signal = np.sin(2 * np.pi * f * t)         # Original signal (sine wave)

# Applying the Hanning window
hanning_window = np.hanning(len(signal))   # Generating the Hanning window
windowed_signal = signal * hanning_window  # Applying the window to the signal

# Plotting the original and windowed signals
plt.figure(figsize=(10, 6))

plt.subplot(2, 1, 1)
plt.plot(t, signal)
plt.title('Original Signal (Sine Wave)')
plt.xlabel('Time')
plt.ylabel('Amplitude')

plt.subplot(2, 1, 2)
plt.plot(t, windowed_signal)
plt.title('Signal after Applying Hanning Window')
plt.xlabel('Time')
plt.ylabel('Amplitude')

plt.tight_layout()
plt.show()


This Python code generates a sample sine wave signal and applies the Hanning window to it. The resulting windowed signal demonstrates the tapering effect at both ends compared to the original signal, showcasing how the Hanning window modifies the signal's properties.

In the upcoming blog, we'll implement various windowing functions on the vibration data as a part of our ongoing modal analysis exploration.

Comments

Popular posts from this blog

Why Do We Divide by n-1 for Sample Variance? (The Intuitive & Mathematical Guide)

Averaging and Moving Average Filters