How to add gain to an audio signal?

Illustration
Giggs - 2024-02-20T20:35:34+00:00
Question: How to add gain to an audio signal?

Hi,   I wanted to ask if there is a way to add gain to an audio signal using MATLAB?   For ex., I have an audio file, and I want to add ~30dB gain to the signal. How can I do that?

Expert Answer

Profile picture of Prashant Kumar Prashant Kumar answered . 2025-11-20

Sure, adding gain to an audio signal in MATLAB is a straightforward process. Here's how you can do it:

  1. Read the Audio File: Use the audioread function to read the audio file.

  2. Convert dB to Linear Scale: Gain in dB needs to be converted to a linear scale.

  3. Apply the Gain: Multiply the audio signal by the gain factor.

  4. Write the Modified Audio File: Use the audiowrite function to save the modified audio signal.

Here's a step-by-step example:

matlab
% Step 1: Read the audio file
[audioIn, fs] = audioread('your_audio_file.wav');

% Step 2: Convert dB gain to linear scale
gain_dB = 30; % Gain in dB
gain_factor = 10^(gain_dB / 20);

% Step 3: Apply the gain
audioOut = audioIn * gain_factor;

% Step 4: Write the modified audio file
audiowrite('output_audio_file.wav', audioOut, fs);

% Display message
disp('Gain applied successfully.');

Explanation:

  1. Read the Audio File: audioread reads the audio file into the variable audioIn and returns the sampling frequency fs.

  2. Convert dB to Linear Scale: The gain_factor is calculated using the formula 10^(gain_dB / 20), which converts the gain in decibels (dB) to a linear scale factor.

  3. Apply the Gain: The audio signal is multiplied by the gain_factor to apply the gain.

  4. Write the Modified Audio File: The modified audio signal audioOut is saved to a new file using audiowrite.

Make sure to replace 'your_audio_file.wav' with the actual name of your audio file. This script will increase the volume of the audio signal by approximately 30 dB.


Not satisfied with the answer ?? ASK NOW

Get a Free Consultation or a Sample Assignment Review!