function [y] = EQ(x, fc, fs ,fb, G)

% EQ originally, created by M. Holters (2011), modified by David
% Stepanavicius April 2015. and further developed by Meisha Stevens June 2015

% d =  amount of distortion.
% The input signal is clipped.
% Where 0 = 0% / 1 = 100%

% x =  Input.
% Sound file of your choice. 
% Example = .wav, .flac

% fc =  the center frequency
% Example: 1250 Hz.

% fb = the bandwidth 
% Values 1 (Hz)  Narrow a Wide slope, and 1000 = Wide.

% fs = Sampling rate.

% G = the gain in dB.
% + = Boost of Wc / - = Cut of fc

% Exporting file:
% audiowrite('______.wav',_____(no inverted comas as we're calling from workspace),fs);

Wc = 2*fc/fs;
Wb = 2*fb/fs;

V0 = 10^(G/20); H0 = V0 - 1;
if G >= 0
   c = (tan(pi*Wb/2)-1) / (tan(pi*Wb/2)+1); % Boost
else
   c = (tan(pi*Wb/2)-V0) / (tan(pi*Wb/2)+V0); % Cut
end;
d1 = -cos(pi*Wc);
xh = [0, 0];
for n = 1:length(x)
    xh_new = x(n) - d1*(1-c)*xh(1) + c*xh(2);
    ap_y = -c * xh_new + d1*(1-c)*xh(1) + xh(2);
    xh = [xh_new, xh(1)];
    y(n) = 0.5 * H0 * (x(n) - ap_y) + x(n);
end;

end
