Building An Equalizer: Semester Project
Building An Equalizer: Semester Project
Building An Equalizer: Semester Project
Building an Equalizer
EE 262 Lab Section A2 Department of Electrical Engineering University of Missouri-Rolla
EE262 A2 Eddie Brown Randy Dimmett Almir Mutapcic December 07, 1998
Abstract:
Equalization is a signal processing technique that cancels out distortions caused by noise sources and imperfections in mediums. This report describes the procedure and results of simulating an equalizer using MATLAB. The equalization process has many real-world applications such as removing distortion of audio signals due to poor acoustics in a room. The methods for determining frequency response of a sound distorting room are also discussed.
-i-
Table of Contents:
Page Introduction Background and Theory Procedure, Results, and Analysis Conclusion Appendix I MATLAB code Appendix II Plots and Graphs 1 1 3 5 6 9
- ii -
Introduction:
High-fidelity audio systems are present in nearly every household around the world. Today great sounding music is produced by a multitude of electronic gadgets such as digital CD players, minidisc players, DVD systems, and even computers implementing new technologies such as mpeg-layer3 and realaudio encoding. Most people are satisfied with the quality of produced music; however, many do not know that this quality could be improved. Equalization, a method that cancels out sound distortion due to imperfections in the speaker or due to poor acoustic features of a room, can greatly improve output of audio systems. The concept of equalization is not limited to sound and acoustic applications. It has been successfully implemented in applications such as removing distortion in a telephone line, radio frequency link, and digital communication channels. This report describes the design process for an equalizer utilizing MATLAB. The methods for determining the frequency response of an arbitrary room are discussed in Background and Theory.
-1-
To design an equalizer, the frequency response of the room must be measured. The most commonly used method for frequency response measurement is to place a microphone at the location of listener's ear. Then, the frequency response of the room can be obtained by comparing the voltage coming out of the CD player and the voltage recorded by the microphone, using the following relationship:
Hroom = (frequency response) = (frequency response of Vout) / (frequency response of Vin)
If an impulse signal is used as input for testing purposes, the frequency response of the voltage input is one. Therefore, if an impulse is used as the input, Hroom = (frequency response of output) MATLABs function fft() can be used to determine the frequency response of a signal, so that in MATLAB, Hroom = fft(y), where y is the output of the room (what the ear hears). The equalizer filter then should be defined as the inverse of the rooms response so the rooms response is cancelled and the final output signal is the same as the CD output (these relationships work only in frequency domain):
Ear_In = (CD_Out) * (Hequal) * (Hroom)
If Hequal (the response of the equalizer filter) is defined to be the inverse of Hroom (the response of the room) the resulting output (Ear_In) is very similar to the original CD source.
Ear_In = (CD_out) * (1/Hroom) * (Hroom) = CD_out
The above method works well because the impulse signal has the optimal frequency response for equalizer application (its uniform for all frequencies). However, the impulse is an ideal theoretical signal that is very hard to produce in practice. Therefore, different test signals such as chirp and step could be used instead of the impulse signal, even though they give only an approximate frequency response of the room.
-2-
-3-
Room2.m filter: The third filter tested was a Chebychev filter. The equalizer did not work well with this filter until 20-30 dB was added to the Chebychev response to remove the zeroes in frequency response. By adding the uniform noise, the equalizers poles were moved inside the stability region of the z-plane unit circle. See appendix II for various plots from each test of these filters. Notes about wavread() and wavwrite() functions The MATLAB functions wavread() and wavwrite() had to be used carefully or else various problems would arise. Wavwrite() writes signals with maximum amplitudes of 1 volts. Therefore, before writing any signal to a wav file, it had to be normalized or else any amplitude above 1 volts would be clipped. However, because of normalizing, another problem occurred. The original CD output volume was not preserved. Hence the volume level of the final output signal was not the same as the input volume, and in some cases, had to be greatly adjusted, which was implemented with volume.m.
-4-
Conclusion:
This project involved constructing an equalizer that reversed the distorting effects caused by a given room. This procedure was accomplished by first measuring the frequency response of the room. Then, the equalizing filter was designed by inverting the rooms frequency response utilizing MATLAB. Certain amount of uniform noise was added to the rooms frequency response in order to prevent division by zero when calculating the equalizers response. However, this design tradeoff does not greatly effect the quality of the produced time-domain signal. The quality of the signals was verified by visual comparisons of the frequency response and spectrograms, as well as by comparing audio outputs. The performance of the equalizer was tested in opposition of three different filters. The obtained results were independent of the used filter type, verifying that the equalizer design should work for any reasonable situation.
-5-
-6-
'Frequency Response of Room',... 'Frequency Response of Equalizer',... 'DB Plot of Room and Equalizer',... 'Spectagram Plot of CD ouput',... 'Spectagram Plot of Equal output',... 'Process the room fiter',... 'Quit'); switch pick case 1 figure plot(freq, fftshift(abs(roomf))); title('Frequency response of the room') ylabel('Magnitude'); xlabel('Frequency (Hz)'); zoom on; grid on; case 2 figure plot(freq, fftshift(abs(equalf))); title('Frequency response of the equalizer') ylabel('Magnitude'); xlabel('Frequency (Hz)'); zoom on; grid on; case 3 figure plot(freq, fftshift(20*log10(abs(equalf))),'r--'); hold on; plot(freq, fftshift(20*log10(abs(roomf)))); hold off; title('dB plot of the room and the equalizer') ylabel('Magnitude (dB)'); xlabel('Frequency (Hz)'); legend('Equalizer','Room'); zoom on; grid on; case 4 figure; specgram(cdout) title('Spectrogram of cdout signal') case 5 figure; specgram(ampin) title('Spectrogram of ampin signal') case 6 run(roomfile) spick=0; while(spick < 4) spick=menu('Room filter controls',... 'Volume optimization',... 'Sound CD output',... 'Sound optimized speaker output (earin)',... 'Back to the main menu'); switch spick case 1 volume; disp(' '); disp('Optimized volume is '), V case 2 sound(cdout) case 3 volume; sound(V*y) end end end end
-7-
Script: Volume.m
% VOLUME.M - Volume adjustment for equalizer script % % Eddie Brown % Randy Dimmett % Almir Mutapcic % % Linear Systems II - EE 262 % December 07, 1998 % % This script computes V, the optimal volume adjustment % for speaker output signal produced by script EQUALZ. % Usage: sound(V*y) should be equal to sound(cdout) ywindow=y(ceil(.1*length(y):length(y))); V=abs(max(cdout))/abs(max(ywindow));
Script: room1.m
[x,fs]=wavread('AMPIN.WAV'); [b,a]=yulewalk(5,[0 1000/(fs/2) 3000/(fs/2) 1],[1 1 .1 .1]); y=filter(b,a,x); wavwrite(y,fs,16,'EARIN.WAV');
Script: room2.m
[x,fs]=wavread('AMPIN.WAV'); [b,a]=cheby2(7,50,.3); y=filter(b,a,x); wavwrite(y,fs,16,'EARIN.WAV')
-8-
-9-
- 10 -
Hroom = cheby2(7,50,.3)
- 11 -
- 12 -