In: Electrical Engineering
Assume you have a WAV file containing an audio with noise. The audio was sampled with a sampling frequency of 8ksamples/second. If you play the audio file, you will be able to notice that there is a small tune along with a strong noise. Design a digital filter using Matlab or Octave to remove the noise. Write the code showing all steps of designing a digital filter? Need help please
Hello,
Please find
the answer attached as under. Please give a thumbs up
rating if you find the answer useful! Have a rocking day
ahead!
NOTE: I have designed a digital butterworth filter with cut off of 1000 Hz. The results are clearly visible in the spectrum pots attached:
****** Matlab Code *******
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% filtering audio signal
load handel.mat
filename = 'handel.wav';
audiowrite(filename,y,Fs);
samples = [1,2*Fs];
clear y Fs
% Read the 1st 2 seconds of data back into MATLAB using
audioread.
[y,Fs] = audioread('handel.wav',samples);
t = 0:1/Fs:2-(1/Fs);
L = length(y);
%%%%%%%%%%%fft of original sound
Y = fft(y);
%Compute the two-sided spectrum P2.
%Then compute the single-sided spectrum P1 based on P2 and the
even-valued signal length L.
P2 = abs(Y/L);
P1 = P2(1:L/2+1);
P1(2:end-1) = 2*P1(2:end-1);
f = Fs*(0:(L/2))/L;
plot(f,P1)
title('Single-Sided Amplitude Spectrum of original audio')
xlabel('f (Hz)')
ylabel('|P1(f)|')
%%%%%%%%% Designing digital filter
fc =
1000;
% cut off freq
fs = Fs;
[b,a] = butter(6,fc/(fs/2));
dataIn = y;
dataOut = filter(b,a,dataIn);
%%%%%%%%%%%fft of original sound
Y = fft(dataOut);
%Compute the two-sided spectrum P2.
%Then compute the single-sided spectrum P1 based on P2 and the
even-valued signal length L.
P2 = abs(Y/L);
P1 = P2(1:L/2+1);
P1(2:end-1) = 2*P1(2:end-1);
f = Fs*(0:(L/2))/L;
figure;
plot(f,P1)
title('Single-Sided Amplitude Spectrum of filtered audio')
xlabel('f (Hz)')
ylabel('|P1(f)|')
******* Output ********