enhancing the noise reduction using hamming window compared with blackman-harris window .
Show older comments
import numpy as np
import matplotlib.pyplot as plt
from scipy.signal import hamming, blackmanharris, convolve
from scipy.io import wavfile
# Load an example noisy audio signal (replace with your own .wav file)
# sample_rate, noisy_signal = wavfile.read('noisy_audio.wav')
# Generate a noisy signal as an example
fs = 1000 # Sample rate (Hz)
t = np.linspace(0, 1, fs) # Time vector (1 second)
clean_signal = np.sin(2 * np.pi * 50 * t) # Clean signal (sine wave of 50 Hz)
noise = np.random.normal(0, 0.5, fs) # Additive Gaussian noise
noisy_signal = clean_signal + noise # Noisy signal
# Apply Hamming Window
hamming_window = hamming(len(noisy_signal))
hamming_filtered_signal = convolve(noisy_signal, hamming_window, mode='same')
# Apply Blackman-Harris Window
blackmanharris_window = blackmanharris(len(noisy_signal))
blackmanharris_filtered_signal = convolve(noisy_signal, blackmanharris_window, mode='same')
# Plot the signals for comparison
plt.figure(figsize=(12, 8))
# Original noisy signal
plt.subplot(3, 1, 1)
plt.plot(t, noisy_signal, label='Noisy Signal', color='r')
plt.title('Noisy Signal')
plt.xlabel('Time [s]')
plt.ylabel('Amplitude')
plt.grid(True)
# Hamming window filtered signal
plt.subplot(3, 1, 2)
plt.plot(t, hamming_filtered_signal, label='Hamming Window Filtered', color='b')
plt.title('Hamming Window Filtered Signal')
plt.xlabel('Time [s]')
plt.ylabel('Amplitude')
plt.grid(True)
# Blackman-Harris window filtered signal
plt.subplot(3, 1, 3)
plt.plot(t, blackmanharris_filtered_signal, label='Blackman-Harris Window Filtered', color='g')
plt.title('Blackman-Harris Window Filtered Signal')
plt.xlabel('Time [s]')
plt.ylabel('Amplitude')
plt.grid(True)
# Show the plots
plt.tight_layout()
plt.show()
1 Comment
William Rose
on 5 Mar 2025
What is the question? Convert python code to matlab?
Answers (0)
Categories
Find more on Hamming in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!