Lab Filter Noise Music
Lab Filter Noise Music
Task 2
WRITE code to import the audio and plot its FFT as the 1st of three
subplots, see fft_star_wars.m for an example
[x,fs] = audioread('music_with_noise.wav')
x = 786432×2
0 0
0.0000 -0.0001
0.0001 -0.0000
-0.0000 0.0001
-0.0001 0.0001
-0.0000 0
0 -0.0001
0.0000 -0.0001
-0.0001 -0.0001
-0.0001 -0.0002
fs =
44100
1
% (-fs/2, fs/2)
f = fs*linspace(0,1, N) - fs/2; % generate frequency vector (-fs/2, fs/2)
% for plotting
figure
subplot(3, 1, 1)
plot(f,X1);ylabel('|X(f)|'); xlabel('Frequency (Hz)')
title('Frequency Content of Input Signal')
xlim([-600 600])
build filter
The code below shows an example on how to build and use a digital filter. CHANGE the cutoff frequency below
to properly filter the noise
2
%
% In the command below, 5 is the order of the filter, the second parameter
% specify the cutoff frequency (with value between 0 and 1), which is
% normalized to half the sample rate, 'low' denotes the type of the filter,
% i.e., low pass filter
subplot(3, 1, 2)
plot(f, abs(H)) % plot frequency response (magnitude) of filter
ylabel('|H(f)|'); xlabel('Frequency (Hz)')
title('Filter Characteristics')
% % Method 2: y[n]=x[n]*h[n]
3
% h = impz(b,a); % get impulse response
% y(:,1) = conv(x(:,1),h); % time domain convolution
% y(:,2) = conv(x(:,2),h);
% % Method 3: Y(e^jw)=X(e^jw)H(e^jw)
% f = 0 : fs/(N-1) : fs;
% H = freqz(b, a, f, fs); % freq response
% Y(:,1) = X(:,1).*H'; % freq domain multiplication
% Y(:,2) = X(:,2).*H';
% y = real(ifft(Y)); % inverse Fourier transform
subplot(3, 1, 3)
plot(f,Y1);
% uncomment the following line to zoom in to a particular freq range
% xlim([0 1000])
ylabel('|Y(f)|'); xlabel('Frequency (Hz)')
title('Frequency Content of Filtered Output Signal')
4
5