Audio equalization helps adjust sound to make it clearer or more pleasant. It changes the balance of different sound frequencies.
Audio equalization in Signal Processing
equalized_audio = apply_equalizer(audio_signal, frequency_bands, gain_values)
audio_signal is the input sound data.
frequency_bands are the ranges of sound frequencies to adjust.
equalized_audio = apply_equalizer(my_audio, [100, 1000, 5000], [5, -3, 2])
equalized_audio = apply_equalizer(my_audio, [60, 250, 4000], [0, 0, 0])
This program creates a simple audio signal with bass, mid, and treble tones. It then applies an equalizer that boosts bass and treble frequencies and reduces mid frequencies. Finally, it plots the original and equalized signals to see the effect.
import numpy as np import matplotlib.pyplot as plt from scipy.signal import butter, lfilter def butter_bandpass(lowcut, highcut, fs, order=4): nyq = 0.5 * fs low = lowcut / nyq high = highcut / nyq b, a = butter(order, [low, high], btype='band') return b, a def apply_bandpass_filter(data, lowcut, highcut, fs, order=4): b, a = butter_bandpass(lowcut, highcut, fs, order=order) y = lfilter(b, a, data) return y def apply_equalizer(audio, fs, bands, gains): equalized = np.zeros_like(audio) for (lowcut, highcut), gain in zip(bands, gains): filtered = apply_bandpass_filter(audio, lowcut, highcut, fs) equalized += filtered * (10 ** (gain / 20)) return equalized # Create a sample audio signal: mix of 3 sine waves fs = 44100 # sample rate T = 1.0 # seconds t = np.linspace(0, T, int(fs*T), endpoint=False) # Frequencies: bass=100Hz, mid=1000Hz, treble=5000Hz audio = 0.5*np.sin(2*np.pi*100*t) + 0.3*np.sin(2*np.pi*1000*t) + 0.2*np.sin(2*np.pi*5000*t) # Define bands and gains (in dB) bands = [(80, 120), (900, 1100), (4800, 5200)] gains = [6, -3, 4] # boost bass and treble, reduce mid # Apply equalizer equalized_audio = apply_equalizer(audio, fs, bands, gains) # Plot original and equalized signals (first 0.01 seconds) plt.figure(figsize=(10,4)) plt.plot(t[:441], audio[:441], label='Original') plt.plot(t[:441], equalized_audio[:441], label='Equalized') plt.legend() plt.title('Audio Signal Before and After Equalization') plt.xlabel('Time [seconds]') plt.ylabel('Amplitude') plt.show()
Equalization changes volume of specific frequency ranges, not the whole sound.
Boosting frequencies too much can cause distortion or noise.
Use plots or listening tests to check if equalization sounds good.
Audio equalization adjusts sound by changing frequency levels.
It helps improve clarity, reduce noise, or customize sound.
Simple filters can boost or cut bass, mid, and treble frequencies.
Practice
Solution
Step 1: Understand audio equalization
Audio equalization changes the levels of different frequency parts of sound to improve or customize it.Step 2: Identify the main function
It adjusts bass, mid, and treble frequencies, not just volume or noise removal.Final Answer:
To adjust the balance of frequency components in an audio signal -> Option CQuick Check:
Audio equalization = frequency adjustment [OK]
- Confusing equalization with volume control
- Assuming it converts audio to text
- Believing it removes all noise
Solution
Step 1: Understand gain values in filters
Positive gain values increase (boost) frequency levels; negative values reduce (cut) them.Step 2: Identify correct gain for bass boost
Gain of 1.5 means 50% increase, which is a boost; negative or zero values do not boost.Final Answer:
gain = 1.5 # Boost bass frequencies by 50% -> Option AQuick Check:
Positive gain boosts frequencies [OK]
- Using negative gain to boost frequencies
- Setting gain to zero expecting boost
- Using non-numeric gain values
frequencies = {'bass': 100, 'mid': 500, 'treble': 10000}
gain = {'bass': 1.2, 'mid': 1.0, 'treble': 0.8}
equalized = {k: frequencies[k] * gain[k] for k in frequencies}
print(equalized)Solution
Step 1: Multiply each frequency by its gain
bass: 100 * 1.2 = 120.0, mid: 500 * 1.0 = 500.0, treble: 10000 * 0.8 = 8000.0Step 2: Construct the equalized dictionary
Result is {'bass': 120.0, 'mid': 500.0, 'treble': 8000.0}Final Answer:
{'bass': 120.0, 'mid': 500.0, 'treble': 8000.0} -> Option AQuick Check:
frequency * gain = equalized value [OK]
- Confusing keys and values in comprehension
- Expecting original frequencies without gain
- Thinking dictionary comprehension causes syntax error
frequencies = {'bass': 100, 'mid': 500, 'treble': 10000}
gain = {'bass': 1.0, 'mid': 1.0, 'treble': 0.5}
for freq in frequencies:
frequencies[freq] = frequencies[freq] * gain['freq']
print(frequencies)Solution
Step 1: Check dictionary key usage in loop
The code uses gain['freq'], which looks for key 'freq' literally, not the variable freq.Step 2: Correct key access
It should be gain[freq] without quotes to use the variable's value as key.Final Answer:
Using 'freq' as a string key instead of variable freq in gain dictionary -> Option DQuick Check:
Variable keys need no quotes [OK]
- Using string keys instead of variables
- Thinking multiplication is wrong
- Confusing loop iteration variable
Solution
Step 1: Calculate gain values for each band
Reduce bass by 20% means multiply by 0.8; mid unchanged means 1.0; boost treble by 30% means multiply by 1.3.Step 2: Match gains to options
{'bass': 0.8, 'mid': 1.0, 'treble': 1.3} matches these values exactly; others do not.Final Answer:
{'bass': 0.8, 'mid': 1.0, 'treble': 1.3} -> Option BQuick Check:
Gain = 1 ± percentage change [OK]
- Mixing boost and cut values
- Applying wrong percentages
- Changing mid frequency unintentionally
Ready to prove it?
Pass the test and this pattern moves unknown
