Mixing of audio signals- Pure tone +noise tone | Lecture- 2

แชร์
ฝัง
  • เผยแพร่เมื่อ 10 ก.ย. 2024
  • Adding Noise to a Sine Wave and Normalizing the Result
    In this video, we explore the process of generating a sine wave and adding noise to it using Python. We then normalize the resulting mixed signal and visualize a portion of it.
    Code Breakdown:
    Generate Sine Wave and Noise Tone:
    We generate a 500 Hz sine wave.
    We generate a 25,000 Hz noise tone and scale it down by multiplying it by 0.3 to reduce its amplitude.
    Mix the Tones:
    We combine the sine wave and the noise tone to create a mixed signal.
    Normalization:
    We normalize the mixed signal to ensure the values fit within the range of 16-bit integers.
    Visualization:
    We plot the first 1,000 samples of the normalized mixed signal to visualize the impact of the added noise.
    code
    import numpy as np
    import matplotlib.pyplot as plt
    Function to generate a sine wave
    def generate_sine_wave(freq, sample_rate, duration):
    x = np.linspace(0, duration, sample_rate * duration, endpoint=False)
    frequencies = x * freq
    y = np.sin((2 * np.pi) * frequencies)
    return x, y
    Define the sample rate (samples per second) and duration (seconds)
    SR = 60000 # Sample rate in Hertz (Hz)
    T = 4 # Duration in seconds
    Generate sine wave and noise tone
    _, signal_tone = generate_sine_wave(500, SR, T) # generate a 500 Hz sine wave
    _, noise_tone = generate_sine_wave(25000, SR, T) # generate a 25000 Hz noise tone
    noise_tone = noise_tone * 0.3
    Mix the tones
    mixed_tone = signal_tone + noise_tone
    Normalization of the results
    normalized_tone = np.int16((mixed_tone / mixed_tone.max()) * 32767)
    Plot the normalized mixed tone
    plt.plot(normalized_tone[:1000])
    plt.xlabel('Sample Number')
    plt.ylabel('Amplitude')
    plt.title('Normalized Mixed Signal (First 1000 Samples)')
    plt.show()

ความคิดเห็น • 1