Remove noise using FFT-based (frequency domain) filtering method

134 vues (au cours des 30 derniers jours)
Seow Yen Yew
Seow Yen Yew le 19 Juin 2021
Dear friend I am currently research on how to remove noise using FFT-based (frequency domain) filtering method. But I am not sure if i have done it correctly. I am just a beginner to DSP and this is not a homework problem. Can you help me to clarify my code? I have also attached my audio for your reference.
%%1) Load the 'audio_sample.wav' file in MATLAB
[sample_data, sample_rate] = audioread('Audio24.wav');
%% Plot the original signal in time domain
% components using the FFT.
sample_period = 1/sample_rate;
t = (0:sample_period:(length(sample_data)-1)/sample_rate);
subplot(2,2,1)
plot(t,sample_data)
title('Time Domain Representation - Unfiltered Sound')
xlabel('Time (seconds)')
ylabel('Amplitude')
xlim([0 t(end)])
m = length(sample_data); % Original sample length.
n = pow2(nextpow2(m)); % Transforming the length so that the number of
% samples is a power of 2. This can make the transform computation
% significantly faster, particularly for sample sizes with large prime
% factors.
%% Plot the original signal in frequency domain
y = fft(sample_data, n);
f = (0:n-1)*(sample_rate/n);
amplitude = abs(y)/n;
subplot(2,2,2)
plot(f(1:floor(n/2)),amplitude(1:floor(n/2)))
title('Frequency Domain Representation - Unfiltered Sound')
xlabel('Frequency')
ylabel('Amplitude')
%% Filter the audio file with low pass butterworth filter and listen it
% sound(sample_data, sample_rate)
%%2) Filter the audio sample data to remove noise from the signal.
order = 7;
[b,a] = butter(order,900/(sample_rate/2),'low');
filtered_sound = filter(b,a,sample_data);
sound(filtered_sound, sample_rate)
%% Plot the filtered audio file in time domain
t1 = (0:sample_period:(length(filtered_sound)-1)/sample_rate);
subplot(2,2,3)
plot(t1,filtered_sound)
title('Time Domain Representation - Filtered Sound')
xlabel('Time (seconds)')
ylabel('Amplitude')
xlim([0 t1(end)])
m1 = length(sample_data); % Original sample length.
n1 = pow2(nextpow2(m1)); % Transforming the length so that the number of
% samples is a power of 2. This can make the transform computation
% significantly faster, particularly for sample sizes with large prime
% factors.
%% Plot the filtered audio file in frequency domain
y1 = fft(filtered_sound, n1);
f = (0:n1-1)*(sample_rate/n1);
amplitude = abs(y1)/n1;
subplot(2,2,4)
plot(f(1:floor(n1/2)),amplitude(1:floor(n1/2)))
title('Frequency Domain Representation - Filtered Sound')
xlabel('Frequency')
ylabel('Amplitude')

Réponses (1)

Kiran Felix Robert
Kiran Felix Robert le 23 Juin 2021
Hi Seow,
Refer the answer in the following link for designing different filters for frequency domain filtering.

Catégories

En savoir plus sur Audio I/O and Waveform Generation dans Help Center et File Exchange

Produits


Version

R2021a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by