0% found this document useful (0 votes)
10 views3 pages

Audio Noise Reduction with FIR Filter

The document describes a MATLAB script for processing an audio file by loading it, converting it to mono, and adding random noise. It then designs and applies a low-pass FIR filter to the noisy signal, allowing for playback of the original, noisy, and filtered audio. Additionally, it includes plotting of the original, noisy, and filtered signals for visual comparison.

Uploaded by

bsee23f33
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
10 views3 pages

Audio Noise Reduction with FIR Filter

The document describes a MATLAB script for processing an audio file by loading it, converting it to mono, and adding random noise. It then designs and applies a low-pass FIR filter to the noisy signal, allowing for playback of the original, noisy, and filtered audio. Additionally, it includes plotting of the original, noisy, and filtered signals for visual comparison.

Uploaded by

bsee23f33
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

Load audio

clc;
clear;
close all;

% Load audio file


[x, fs] = audioread('[Link]'); % File ko current folder me
rakhein
x = mean(x, 2); % Stereo ko mono me convert karein

% Play the audio


sound(x, fs); % ya soundsc(x, fs) - ye automatically volume adjust kar deta
hai

add noise
clc;

clear;
close all;

% 1. Load audio file


[x, fs] = audioread('[Link]'); % Correct file name, remove
double .wav if any
x = mean(x, 2); % Stereo ko mono me convert karein

% 2. Play original audio


disp('Playing original audio...');
soundsc(x, fs); % soundsc auto-scales volume
pause(length(x)/fs + 1); % Wait until audio finishes

% 3. Add random noise


noise_level = 0.02; % Noise ka level adjust karen (0.01-
0.05)
noise = noise_level * randn(size(x)); % Random noise generate karein
noisy_signal = x + noise; % Original signal me noise add
karein

% 4. Play noisy audio


disp('Playing noisy audio...');
soundsc(noisy_signal, fs); % Play noisy audio
pause(length(noisy_signal)/fs + 1); % Wait until audio finishes

% 5. Optional: Plot original and noisy signals


t = (0:length(x)-1)/fs;
figure;
subplot(2,1,1);
plot(t, x);
title('Original Audio');
xlabel('Time (s)'); ylabel('Amplitude');

subplot(2,1,2);
plot(t, noisy_signal);
title('Noisy Audio');
xlabel('Time (s)'); ylabel('Amplitude');

design a low pass filter


clc;
clear;
close all;

%% 1. Load audio
[x, fs] = audioread('[Link]');
x = mean(x, 2); % Stereo to mono

%% 2. Add random noise


noise_level = 0.02;
noise = noise_level * randn(size(x));
noisy_signal = x + noise;

%% 3. Design FIR Low-Pass Filter


% Filter specifications
Fc = 3000; % Cutoff frequency in Hz (adjust as needed)
N = 50; % Filter order (adjust for smoother response)

% Normalized cutoff frequency (0 to 1, 1 = Nyquist freq)


Wn = Fc/(fs/2);

% Design filter using window method


b = fir1(N, Wn, 'low'); % Low-pass FIR filter coefficients

%% 4. Apply filter to noisy signal


filtered_signal = filter(b, 1, noisy_signal);

%% 5. Play signals
disp('Playing original audio...');
soundsc(x, fs);
pause(length(x)/fs + 1);

disp('Playing noisy audio...');


soundsc(noisy_signal, fs);
pause(length(noisy_signal)/fs + 1);

disp('Playing filtered audio...');


soundsc(filtered_signal, fs);
pause(length(filtered_signal)/fs + 1);

%% 6. Plot signals
t = (0:length(x)-1)/fs;

figure;
subplot(3,1,1);
plot(t, x);
title('Original Audio'); xlabel('Time (s)'); ylabel('Amplitude');

subplot(3,1,2);
plot(t, noisy_signal);
title('Noisy Audio'); xlabel('Time (s)'); ylabel('Amplitude');
subplot(3,1,3);
plot(t, filtered_signal);
title('Filtered Audio (FIR Low-Pass)'); xlabel('Time (s)');
ylabel('Amplitude');

with low pass filter


clc;
clear;
close all;

%% Load audio
[x, fs] = audioread('[Link]');
x = mean(x, 2); % Stereo to mono

%% Add noise
noise_level = 0.02;
noise = noise_level * randn(size(x));
noisy_signal = x + noise;

%% Design stronger FIR low-pass filter


Fc = 2500; % Lower cutoff frequency for more noise removal
N = 150; % Higher filter order = better attenuation

Wn = Fc/(fs/2);
b = fir1(N, Wn, 'low'); % Low-pass FIR

%% Filter noisy signal


filtered_signal = filter(b, 1, noisy_signal);

%% Play audio
disp('Playing original audio...');
soundsc(x, fs); pause(length(x)/fs + 1);

disp('Playing noisy audio...');


soundsc(noisy_signal, fs); pause(length(noisy_signal)/fs + 1);

disp('Playing filtered audio...');


soundsc(filtered_signal, fs); pause(length(filtered_signal)/fs + 1);

%% Plot signals
t = (0:length(x)-1)/fs;
figure;
subplot(3,1,1); plot(t,x); title('Original'); xlabel('Time');
ylabel('Amplitude');
subplot(3,1,2); plot(t,noisy_signal); title('Noisy'); xlabel('Time');
ylabel('Amplitude');
subplot(3,1,3); plot(t,filtered_signal); title('Filtered'); xlabel('Time');
ylabel('Amplitude');

You might also like