Matlab Audio SNR MSE
Matlab Audio SNR MSE
1. Referring to the plots in Section 1-B, the passband edge frequency, fp and the stopband edge
frequency, fs are determined as follows:
fp = 1900Hz
fs = 2000Hz
2. To achieve a passband gain of |Gp| < 3 dB and a stopband attenuation of |Gs| > 20 dB, the
minimum N (length of the lowpass filter) was found to be N = 142.
3. Using the fir1 MATLAB function, the designed filter frequency responses (magnitude and
phase) are plotted. Below is the MATLAB code used to design the FIR filter and to plot the
designed filter's frequency response:
MATLAB code for designing the FIR filter using fir1 MATLAB function and to plot it's
frequency response,
%wavwrite(y,'filtered_fir.wav');
%soundsc(y,8000);
The designed FIR filter's frequency response (both magnitude and phase):
The filter coefficients are saved in a Notepad text file: FIR Filter Coefficients
The impulse response of the filter is plotted using the following MATLAB code:
%[noisy1,freq]=wavread('noisy1.wav');
%[orig1,freq]=wavread('orig1.wav');
%y=filter(B,1,noisy1);
%wavwrite(y,'filtered_fir.wav');
%soundsc(y,8000);
Please Note: The above graph is not very clear after being exported into jpeg format. For
verification purposes, use the M-file provided above.
4. The noise is filtered out from the signal using the following MATLAB code:
wavwrite(y,'filtered_fir.wav');
soundsc(y,8000);
*Here is the filtered signal in ".wav" format for evaluation purposes: filtered_fir.wav
MATLAB code for plotting the original and the filtered signal on the same figure for time
domain:
subplot(211);
plot((1:n/2)/n*freq,unwrap(angle(fsignal(1:n/2))));
%unwrap(P) corrects the radian phase angles in array P by adding
%multiples of ±2*pi when absolute jumps between consecutive array
%elements are greater than pi radians.
%If P is a matrix, unwrap operates columnwise. If P is a
%multidimensional array, unwrap operates on the first
%non-singleton dimension.
%P can be a scalar, vector, matrix, or N-D array.
title('Original Signal in Frequency Domain');
xlabel('Hz');
ylabel('Phase');
grid;
subplot(212);
plot((1:n/2)/n*freq,unwrap(angle(fsignal(1:n/2))));
%unwrap(P) corrects the radian phase angles in array P by adding
%multiples of ±2*pi when absolute jumps between consecutive array
%elements are greater than pi radians.
%If P is a matrix, unwrap operates columnwise. If P is a
%multidimensional array, unwrap operates on the first
%non-singleton dimension.
%P can be a scalar, vector, matrix, or N-D array.
title('Filtered Signal in Frequency Domain');
xlabel('Hz');
ylabel('Phase');
grid;
The filtered signal sound almost as if it was the original signal. Upon hearing the filtered
signal, no
major difference could be distinguished.
6. MATLAB program written to quantize the coefficients of the designed filter into:
(i) 4-bit.
(ii) 8-bit.
(iii) 12-bit.
(iv) 16-bit.
After measuring the frequency responses of the filters with quantized coefficients, the
smallest
number of bits required for the FIR filter that can satisfy the specifications (without the need
to
redesign the filter) was found to be 12-bits. Here is the MATLAB code to quantize the
coefficients of the desined filter into 12-bits:
b=fir1(142,0.4875);
N=12;
B=(b*(2^(N-1))+0.5)/2^(N-1);
freqz(B,1,142,8000);
[noisy1,freq]=wavread('noisy1.wav');
[orig1,freq]=wavread('orig1.wav');
y=filter(B,1,noisy1);
wavwrite(y,'fir_12bits.wav');
soundsc(y,8000);
Frequency Response of designed filter (with its coefficients represented using 12-bits):
MSE=(sum((y-orig1).^2)/65536)
SNR=10*log10((sum(orig1.^2))/65536/MSE)
For filtered signal (quantized),
Mean Squared Error, MSE = 0.0578
Plotting both the original signal and filtered signal (12-bits) on the same figure (using the
MATLAB code given in the lab sheet) for:
(a) Time domain.
(b) Frequency domain (Magnitude).
(c) Frequency domain (Phase).
*Here is the filtered signal in ".wav" format for evaluation purposes: fir_12bits.wav
*The filter coefficients (represented by 12-bits) are saved in a Notepad text file: filtered.txt
Once again, the filtered version sound similar to the original signal. We cannot distinguish
any differences based on hearing alone. However, we can distinguish any differences between
the two signals by comparing the signals in time and frequency domain. Yet, it is also quite
impossible to differentiate between the original signal and the filtered signal in the time domain.
Through the frequency response, we observed that the noises (signals above 3400Hz and the two
spikes) has been eliminated, hence the magnitude response of the filtered signal showed that
attenuation occurred.
It is also observed that the magnitude of the filtered signal is on average, smaller than the
original signal. This is why the SNR found is negative where actually it should be the opposite
showing that the filtered signal is very close to the original signal.