Bass Boost Equation and MATLAB Implementation of a Digital Filter

 1. Consider the audio system in a car. Some people like to hear a lot of bass. Give an equation, in your preference of time or frequency domain, for a bass boost. 

2. Write a MATLAB or Octave program that, given a sequence, f[k], of samples in the time domain, calculates a filtered output y[k], given by the formula y[k]=-a_2[k-1]-a_1y[k-2]-a_0y[k-3]+b_3f[k]+b_2f[k- 1]+b_1f[k-2]+b_0f[k-3]. 

The values y are outputs, k is an index into a sequence, (so if "now"=k, one sample in the past is k-1), there are coefficient vectors a and b, which can be input parameters to the function. Make up a sequence 

f. Plot the input f and that output, y. 

3. Run your program with all of the a coefficients set to 0. Plot the input and output

Bass Boost Equation and MATLAB Implementation of a Digital Filter


The answer


1. Bass Boost Equation (Frequency Domain)

To boost bass (low frequencies), a common approach is to use a shelving filter. The frequency domain equation for a simple bass boost filter is:

H(f)=1+Gfc2f2+fc2H(f) = 1 + \frac{G \cdot f_c^2}{f^2 + f_c^2}

Where:

  • H(f)H(f) is the frequency response

  • GG is the boost gain factor

  • fcf_c is the cutoff frequency

  • ff is the frequency variable

Alternatively, in the time domain, a simple bass boost filter can be achieved with a difference equation such as:

y[n]=x[n]+αx[n1]y[n] = x[n] + \alpha \cdot x[n-1]

Where α\alpha (typically positive, e.g., 0.5) sets the amount of bass boost.


2. MATLAB Program for a General 3rd-Order Filter

We’ll create a function to compute output y[k]y[k] using your provided difference equation, and test it with a made-up sequence:

y[k]=a2y[k1]a1y[k2]a0y[k3]+b3f[k]+b2f[k1]+b1f[k2]+b0f[k3]y[k] = -a_2y[k-1] - a_1y[k-2] - a_0y[k-3] + b_3f[k] + b_2f[k-1] + b_1f[k-2] + b_0f[k-3]

MATLAB/Octave Code:

matlab

% Filter function function y = myFilter(f, a, b) N = length(f); y = zeros(1, N); for k = 1:N y_k = 0; % Negative feedback terms if k-1 >= 1, y_k = y_k - a(3)*y(k-1); end if k-2 >= 1, y_k = y_k - a(2)*y(k-2); end if k-3 >= 1, y_k = y_k - a(1)*y(k-3); end % Input terms if k >= 1, y_k = y_k + b(4)*f(k); end if k-1 >= 1, y_k = y_k + b(3)*f(k-1); end if k-2 >= 1, y_k = y_k + b(2)*f(k-2); end if k-3 >= 1, y_k = y_k + b(1)*f(k-3); end y(k) = y_k; end end % --- MAIN SCRIPT --- % Make up a sequence f N = 30; n = 0:N-1; f = sin(2*pi*0.07*n) + 0.5*randn(1, N); % Low-freq signal + noise % Coefficients (example values) a = [0.1 0.2 0.3]; % [a0, a1, a2] b = [0.4 0.3 0.2 0.1]; % [b0, b1, b2, b3] % Filter y = myFilter(f, a, b); % Plot input and output figure; subplot(2,1,1); plot(n, f, 'b.-'); title('Input f[k]'); xlabel('k'); ylabel('f[k]'); subplot(2,1,2); plot(n, y, 'r.-'); title('Filtered Output y[k]'); xlabel('k'); ylabel('y[k]'); % -- 3. Run with all a coefficients zero -- a_zeros = [0 0 0]; y2 = myFilter(f, a_zeros, b); figure; subplot(2,1,1); plot(n, f, 'b.-'); title('Input f[k] (a=0)'); subplot(2,1,2); plot(n, y2, 'r.-'); title('Output y[k] (a=0)');

Result Discussion:

  • With nonzero a coefficients:
    The output yy will show the effect of feedback, possibly smoothing or coloring the input.

  • With a = [0 0 0]:
    The output becomes a moving weighted sum of current and previous 3 input values (no feedback). The result is a linear filter (FIR), and the output follows the input with smoothing according to the b coefficients.


You can copy and run this code in MATLAB or Octave.
It will plot both the input and output sequences for both cases, clearly showing the effect of feedback coefficients.


📩 Need a similar solution? Email me: adel455@hotmail.com




Previous Post Next Post

Comments

Nepali Graphics - Learn design, Animation, and Progrmming