advertisement

Design of an M-Band Graphic Equalizer for Audio Signals Design an M-band graphic equalizer for modifying (mono or stereo) audio signals. Implementation where x is the vector of input audio samples, y is the vector of output audio samples, M is the number of sub-bands, fs is the audio sampling rate, gain is a vector of length M consisting of design in Matlab as a function of the form y = graphic(x, M , fs , gain, parameters), the scaling gains of the sub-bands, ordered from lowest to highest frequency band, and expressed in units of decibels with each gain in the range [-20, +20] dB Abstract : This project describes the design and implementation of an M-band-Graphic Equalizer using filter banks. Filter banks are a group of band-Pas filters that are connected in parallel. Each Parallel connection form a channel to isolate a certain frequency-band from the input signal. By doing so we can post or attenuate any band without affecting the other bands , this is done since band are isolated buy individual channels. There are many methods to realize a filter bank , in this project uses the cosine Modulated Filter Bank by modulate a low-pas filter , it shifts the Bas-band of a Law-Pas filter to a higher frequencies to cover the entire band of frequencies of the input signal. Filter bank structure : If the bandwidths of each filter in the filter bank are equals then it’s called uniform filter bank , and if not then it’s a non-uniform filter banks . in this paper the filter bank uses an octave structure where the bandwidth of the current filter is twice the size of the size of the filter below as follow : If ℎ0, ℎ1, ℎ2 ℎ3 are analysis filters then bandwithe of ℎ2 is twice the size of that of ℎ1 and ℎ3 is twice the size of ℎ2 , while ℎ ℎ1 have the same bandwidth. The Octave bands can be formed by merging the uniform bandwidth, so if is the number of uniformed bands ,then the number of nonuniformed octave bands = 1 + log(2) . If 0, 1, 2 3 are the sup-uniform bands , then a 3 band sup-bands can be formed as : 0 = 0, 1 = 1, 2 = 2 3. The uniform filter-bank consists of a parallel connection of the sup-band filter, the impulse responses, merging bands is accomplished by adding the respective impulse responses . Analysis Filters : Filters formed using a cosine modulated low pass filter, designed using dolph windowfunction. Multiplying the filter coefficients with the cosine function described previously, decided the shift of the pass band of the low pass filter. This can be performed in Matlab by multiplying the low pass filtersequence with the sequence formed by the cosine function. The bandwidth of each analysis filter is formed using the octave structuring . In Matlab, octave bands are formed by according adding the impulse responses or2−1 filters of the 2−1 band uniform filter bank. The synthesis filters have impulse response that are matched with the respective analysis filters, but of opposite phase, so that we can get a perfect reconstruction of the input signal. In Matlab, the order of the filter coefficients of each analysis filter is reversed and then assigned to the respective synthesis filters. The output sequence from each of the synthesis filters is multiplied with a scalar, which specifies the gain. In Matlab, The values of the gain for respective channels is entered in to a gain vector during the execution of the program. The function should do the following. : 1. Check that each gain is in the correct range, and adjust any out-of-range input values to the closest in-range value: The user gain input is of an 8 elements since we have 8 channels , every channel have a unique gain , this matlab code supports the first part : file = input('\nPlease Enter the audio file name for 8 band graphic equalizer: \n','s'); [xi, Fs] = audioread(file); %% her the user will inbut the wav file of choice and this function will a signed FS sampling frequency(Fs) , and the data(xi) tyo be processed , her the range of data and Fs is computed using this function instead of interring a direct Fs or xi values. ------------------------------------------------------- This part of the code will give the user 2 options , a defult gain adjustment or a an input by the user for a gain of 8 frequancies between [0,1 :10] as spesefied at the project choice = 100; k = 0; val = 0; while val == 0 if k > 0 fprintf('\nInvalid input') end choice = str2double(input('\nPlease press "0" to use the default gains or press "1" to enter user defined gains: ','s')); if choice == 0 || choice == 1 val = 1; end k = k +1; end ------------------------------------------------------------------1: this will allow the user to use a 4 defaults gain adjustments based on 4 cases as: %// the defult agustments a user can input // fprintf(' Availabl_Adjustments : A.treble B.bass C.full treble D.full bass\n '); preset = input('Input an Adjustment: ','s'); switch preset case 'A' sgain = [0.5, 0.5, 0.5, 0.5, 0.5, 1.5, 2,3]; case 'B' sgain = [ 3,2, 1.5, 0.5, 0.5, 0.5, 0.5, 0.5]; case 'C' sgain = [0.1, 0.1, 0.1, 0.1, 0.5, 0.5, 2,3]; case 'D' sgain = [3, 2, 0.5, 0.5, 0.1, 0.1, 0.1, 0.1]; end ----------------------------------------------------------------------2: if the user desided to inter his 8 elements gain , this is the part that support it : flag = 0; k = 0; sgain = 0; if choice == 1 % this part will suport choice number 1, user will input 8 elemnts of gains between [0.1 :10]. while length(sgain) ~= 8 || flag == 0 if k > 0 fprintf('\nInvalid input') end sgain = input('\nPlease Enter gain as a 8 element array[# # # # # # # #] with values between 0.1 - 10: '); minimum = min(sgain); maximum = max(sgain); if minimum >= 0.1 && maximum <= 10 flag = 1; end k = k+1; end the reference I used to understand the equalizer design uses a window function called Dolph – Chebyshev window to control the attenuation . Its equation is given as below: () = ((−1) cos [ −1 [ cos ( )]) /(cosh[ℎ−1 ()])) . 1 Β= = cos[ℎ−1 (10 )], and her is the length of the sequence. the level of the side lobes can be controlled by the parameter α. If α = 5, then there will be an attenuation of 100dB on the side lobes. There is a tradeoff between the size of the main lobe and the attenuation of side lobes. If the attenuation of the side lobe is very large, then there will be an increase in the main lobe, and thus deviating from the ideal characteristics. The length of the filter also has an effect on the widow characteristics. If the length is small, then the side lobe would be large enough, deviating hugely from the ideal characteristics . --------------------------------------------------------------------------- 2. Using the M octave-structured sub-bands, so that, for example, if M = 5, then sub-bands S1 , S2 .S3 , S4 , S5 have respective bandwidths B, B, 2B, 4B, and 8B, where the total number of bands satisfies f s 2 = B ×2M −1 . However, it is also permissible to use a different (user-defined), more general selection of bandwidths for the M sub-bands, provided that the octave-structured configuration is among the user options. Filter Bank: Filter bank separates the input-signal in to different components . each component caries signal frequency sup-component of the input signal. These different components are divided in to 2 groupsAnalysis filters and syntheses filters . where at the analysis side down-sampling is done and at the synthesis side up sampling is done. It is very important to add a signal processing unit between the 2 filters to avoid aliasing . the figure below illustrate the filter bank components. Figer 1: Structure of a filter bank. The octave filter I designed have an M=8 to meet the specifications The cosine modulation : Each filter of the analysis part has an impulse response of a cosine modulated version of a prototype a low-pas filter with a cutoff frequency of a 2 where is the number of Bannds in the filter bank and the and is the sampling frequency of the signal .The length of the impulse-response of each filter is = 2 . The impulse-response of each analysis filter is given by : ℎ, () = 2ℎ1 cos((2 + 1) /(4(2 + 1 − )) , where ℎ1 is the prototype of a law pasfilter and = (1,2,3, … . . − 1) , the synthesis filter response are matched to that of the Analysis filter by this equation : () = ℎ( − 1 − ) , where = (1,2,3, , , , − 1). Because of this matching using the cosine modulation, the total frequency bandwidth of the input signal is covered by all the bandwidths of all the analysis filters , each filter have a bandwidth of 1/ of the total bandwidth of the input signal . Graphic equalizer : The main idea of a graphic equalizing is to to attenuate different bands of frequancies based on the user input. The graphic equalizers used in music industry or recording companies are the M-band octave equalizer. The user can either boosts the gain or attenuate the selected band . Design of M-Band Octave Structured : The filters are designed using an FIR Low Pass filters, which are cosine modulated. This FIR Low Pass filters are linearly phased , the filter coefficients are usually symmetrical. The ideal Low Pass filter with cutoff frequency Hz has the following impulse response. −1 )) , where 2 ℎ() = 2(2( − ( −1 ) Samples 2 the filter is delayed by ( , where is the length of the filter and is the sampling period. This impulse response is non-causal and infinite in duration. Therefore we multiply this one with a rectangular window function to restrict the number of samples to the length of the window : W= () = { 1, = 1,2,3, … . − 1 0 , = ℎ we need to use windows whose values gradually change from 1 to 0, from both sides. There are several windows and each have their merits and demerits. I found a window function called Dolph –Chebyshev window . The attenuation factor R is a multiple of the length L and thereby making it dynamic. The scalar that is multiplied is decided by opservation . This part of the code will support the FIR filter design and the 8M-pand Octav filter With the requaiared bandwidth and the total number of bands satisfy the nedded Fs value : function Y = graphic(x,Fs, M, sgain) fprintf('Computing ...'); %Read the input WAV file lx = length(x); %//////////////////////////FIR filter design////////////////////////// K = 2^(M-1); % ad to support part2 of the project also add the graph for part 2 L = 2*K; %Cutoff frequency B = Fs/(2*K); %Normalized cutoff frequencies fcn = B/(Fs/2); if L > 100 slripple = 100; else slripple = 2*L; end bhlp = fir1(L-1, fcn, chebwin(L, slripple)); %Cosine modulated Octave filter bank have 2 componants : %Analysis filters : down-sampling for p = 1:K for kb = 1:L b(p, kb) = 2*bhlp(kb)*cos(((2*(p-1) + 1)/(4*K))*(2*(kb-1) + 1 - K)*pi); end end i1 = 3; for ka = if ka < h(ka+1, else i2 = i1 h(ka+1, i1 = i2 end end 0:M-1 2 1:L) = b(ka+1, 1:L); + 2^(ka-1) - 1; 1:L) = sum(b(i1:i2, 1:L)); + 1; %Synthesis filters : up-sampling for ks = 1:M g(ks, 1:L) = h(ks, L:-1:1); end %DC gain estimation sumc = [zeros(1, 2*L - 1)]; %Initial for kd = 1:M sumc = sumc + conv(h(kd, 1:L), g(kd, 1:L)); end a = sum(sumc); %Output of the analysis filters for kw = 1:M w(kw, 1:(lx + L - 1)) = conv(x, h(kw, 1:L)); end %Output of the synthesis filters for kv = 1:M v(kv, 1:(lx + 2*L - 2)) = conv(w(kv, 1:(lx + L - 1)), g(kv, 1:L)); end %Gain adjustment for ky = 1:M y(ky, 1:length(v(ky, 1:(lx + 2*L - 2)))) = sgain(ky)*v(ky, 1:(lx + 2*L 2)); end %/////////////////////////////////////////////////////////////////////// %//////////////////////////////////Output////////////////////////////// Y = sum(y); %Removing DC gain Y = Y/a; %/////////////////////////////////////////////////////////////////////// fprintf('Done\n'); %///////////////////PLOTTING: 8 Bands Filter Bank if M == 8 H1 = freqz(h(1, 1:L), 1); mag1 = 20*log10(abs(H1)); H2 = freqz(h(2, 1:L), 1); mag2 = 20*log10(abs(H2)); H3 = freqz(h(3, 1:L), 1); mag3 = 20*log10(abs(H3)); H4 = freqz(h(4, 1:L), 1); mag4 = 20*log10(abs(H4)); H5 = freqz(h(5, 1:L), 1); mag5 = 20*log10(abs(H5)); H6 = freqz(h(6, 1:L), 1); mag6 = 20*log10(abs(H6)); H7 = freqz(h(7, 1:L), 1); mag7 = 20*log10(abs(H7)); H8 = freqz(h(8, 1:L), 1); mag8 = 20*log10(abs(H8)); q = 0:1/length(mag1):1 - 1/length(mag1); plot(q, mag1, q, mag2, q, mag3, q, mag4, q, mag5,q,mag6,q,mag7,q,mag8), grid on; xlabel('Frequency:(Hz)'); ylabel('Magnitud_ Response:(dB)'); end 3. Play the original audio signal, followed by the graphic equalizer audio output. As demonstrated in the matlab function the function first will play the input file , then it will play the computed output file for 2 cases Stereo or Mono , The part of the code to support task 3 : is %///////////////////////////Playing Input////////////////////////////// fprintf('Playing Input Audio file...'); wavplay(xi, Fs); fprintf('Done\n'); then playing the computed output : %///////////////////////////Playing Output////////////////////////////// fprintf('Playing Output...'); wavplay(Y', Fs); fprintf('Done\n'); , notice that Y is the processed output . incased of the Monofile , we have on input Vs one output . incase of the sterio we have 2 inputs Vs 2 outputs ----------------------------------------------------------------------------- comments to document the Matlab code. The matlab program is well commented and easy to follow . For example : in the matlab code , the part that deal with the Octav filter design is commented , and the tow combonants of the filter , the analysis filter where down-sampling is computed is comented and the 2nd part where the Synthesis filter where up-sampling is computed is also commented , the down code will give this part as follows : %Cosine modulated Octave filter bank have 2 componants : And the code is : %Analysis filters : down-sampling for p = 1:K for kb = 1:L b(p, kb) = 2*bhlp(kb)*cos(((2*(p-1) + 1)/(4*K))*(2*(kb-1) + 1 - K)*pi); end end i1 = 3; for ka = 0:M-1 if ka < 2 h(ka+1, 1:L) = b(ka+1, 1:L); else i2 = i1 + 2^(ka-1) - 1; h(ka+1, 1:L) = sum(b(i1:i2, 1:L)); i1 = i2 + 1; end end %Synthesis filters : up-sampling for ks = 1:M g(ks, 1:L) = h(ks, L:-1:1); end %DC gain estimation sumc = [zeros(1, 2*L - 1)]; %Initial for kd = 1:M sumc = sumc + conv(h(kd, 1:L), g(kd, 1:L)); end a = sum(sumc); %Output of the analysis filters for kw = 1:M w(kw, 1:(lx + L - 1)) = conv(x, h(kw, 1:L)); end %Output of the synthesis filters for kv = 1:M v(kv, 1:(lx + 2*L - 2)) = conv(w(kv, 1:(lx + L - 1)), g(kv, 1:L)); end %Gain adjustment for ky = 1:M y(ky, 1:length(v(ky, 1:(lx + 2*L - 2)))) = sgain(ky)*v(ky, 1:(lx + 2*L 2)); end 4. Modifying the design to handle a stereo input signal. Automatically determine if the input signal, x, is mono or stereo, and process accordingly. (Uses the .wav audio file format, so that the signal is a column vector if mono, and a n by 2 array if stereo.) This part of the project was challenging and took some time and some intuition to implement , it was easy to read the Mono file and play it using the wave play function and compute it as a single input VS a single output , but the Stereo wav file was computed by considering tow inputs VS 2 outputs since the file have 2 sets of data to be computed . I managed to do the function in a way that will identify the user input as a mono or stereo t. I used the fft function to plot the result of the computing as follow : A: the mono file : switch type % to suport the extra points , defininf if its Mono or Sterio and plot input vs output -------------------------------------------case 'mono' Y = graphic(x,Fs,M,sgain); figure(2) Lx = length(x); NFETx = 2^nextpow2(Lx); wx = fft(x,NFETx)./Lx; fx = Fs/2*linspace(0,1,NFETx/2 + 1); plot(fx,2*abs(wx(1:NFETx/2+1))) hold on Ly = length(Y); NFETy = 2^nextpow2(Ly); wy = fft(Y,NFETy)./Ly; fy = Fs/2*linspace(0,1,NFETy/2 + 1); plot(fy,2*abs(wy(1:NFETy/2+1)),'k') hold off title('Mono FFT of input Vs FFT of output,,plue is the input black is the output ') xlabel('Frequency (Hz)') ylabel('Magnitude') this is the plot for the mono case using the default gain by the user : B : the sterioe case : The sterio case was computed by reading the wav file in to 2 inputs as : x(1:0) and x(2:0) and the output Y [ Y1:Y2] , the n using the nfft function to to plot the output vs the input , this is the code I used with the plots for a default gain : case 'stereo' Y1 = graphic(x(1,:),Fs,M,sgain); Y2 = graphic(x(2,:),Fs,M,sgain); Y = [Y1 ; Y2]; figure(2) Lx1 = length(x(1,:)); NFETx1 = 2^nextpow2(Lx1); wx1 = fft(x(1,:),NFETx1)./Lx1; fx1 = Fs/2*linspace(0,1,NFETx1/2 + 1); plot(fx1,2*abs(wx1(1:NFETx1/2+1))) hold on Ly1 = length(Y1); NFETy1 = 2^nextpow2(Ly1); wy1 = fft(Y1,NFETy1)./Ly1; fy1 = Fs/2*linspace(0,1,NFETy1/2 + 1); plot(fy1,2*abs(wy1(1:NFETy1/2+1)),'k') hold off title('Stereo FFT of channel 1 input Vs FFT of channel 1 output,, plue is the input black is the output') xlabel('Frequency (Hz)') ylabel('Magnitude') figure(3) Lx2= length(x(2,:)); NFETx2 = 2^nextpow2(Lx2); wx2 = fft(x(2,:),NFETx2)./Lx2; fx2 = Fs/2*linspace(0,1,NFETx2/2 + 1); plot(fx2,2*abs(wx2(1:NFETx2/2+1))) hold on Ly2 = length(Y2); NFETy2 = 2^nextpow2(Ly2); wy2 = fft(Y2,NFETy2)./Ly2; fy2 = Fs/2*linspace(0,1,NFETy2/2 + 1); plot(fy2,2*abs(wy2(1:NFETy2/2+1)),'k') hold off title('Stereo FFT of channel 2 input Vs FFT of channel 2 output,,plue is the input black is the output ') xlabel('Frequency (Hz)') ylabel('Magnitude') end (Y1 = graphic(x(1,:),Fs,M,sgain);) (Y2 = graphic(x(2,:),Fs,M,sgain);) 5. Conclusion : This project helped to understand the basic concepts of filter banks in this project I used the(8M- pandas). There are several ways of realizing a filter bank and one way is to use the Cosine Modulated filter bank. I observed the following points. Instead of designing band-pass filters for different bands, the cosine modulated filter banks, modulates a low-pass filter. By using the suitable parameters and the right frequency In simple words, it simply shifts the pass band of the low pass filter towards higher frequencies, and covering the entire band of frequencies of the input signal. Filter banks have many applications in signal processing. one of the applications is Graphic Equalizer, the user can ‘graphically’ modify different bands by intering the wanted frequencies for different channels . References : Ch.Srinivasa Kumar et al. / International Journal on Computer Science and Engineering (IJCSE) http://www.enggjournals.com/ijcse/doc/IJCSE11-03-08-116.pdf