bass _ treble shelving filter_ shelving(g, fc, fs, q, type) - file exchange - matlab central

2
Search: File Exchange Create Account Log In File Exchange Answers Newsgroup Link Exchange Blogs Trendy Cody Contest MathWorks.com by Jeff Tackett Bass / Treble Shelving Filter 25 Sep 2007 (Updated 26 Sep 2007) Generates coefficients for a 2nd order IIR digital filter shelving(G, fc, fs, Q, type) Download Submission Code covered by the BSD License Highlights from Bass / Treble Shelving Filter shelving(G, fc, fs, Q, ty...% Derive coefficients for a shelving filter with a given amplitude and View all files function [b, a] = shelving(G, fc, fs, Q, type) % % Derive coefficients for a shelving filter with a given amplitude and % cutoff frequency. All coefficients are calculated as described in % Zolzer's DAFX book (p. 50 -55). % % Usage: [B,A] = shelving(G, Fc, Fs, Q, type); % % G is the logrithmic gain (in dB) % FC is the center frequency % Fs is the sampling rate % Q adjusts the slope be replacing the sqrt(2) term % type is a character string defining filter type % Choices are: 'Base_Shelf' or 'Treble_Shelf' % % Author: Jeff Tackett 08/22/05 % %Error Check if((strcmp(type,'Base_Shelf') ~= 1) && (strcmp(type,'Treble_Shelf') ~= 1)) error(['Unsupported Filter Type: ' type]); end K = tan((pi * fc)/fs); V0 = 10^(G/20); root2 = 1/Q; %sqrt(2) %Invert gain if a cut if(V0 < 1) V0 = 1/V0; end %%%%%%%%%%%%%%%%%%%% % BASE BOOST %%%%%%%%%%%%%%%%%%%% if(( G > 0 ) & (strcmp(type,'Base_Shelf'))) b0 = (1 + sqrt(V0)*root2*K + V0*K^2) / (1 + root2*K + K^2); b1 = (2 * (V0*K^2 - 1) ) / (1 + root2*K + K^2); b2 = (1 - sqrt(V0)*root2*K + V0*K^2) / (1 + root2*K + K^2); a1 = (2 * (K^2 - 1) ) / (1 + root2*K + K^2); a2 = (1 - root2*K + K^2) / (1 + root2*K + K^2); %%%%%%%%%%%%%%%%%%%% % BASE CUT %%%%%%%%%%%%%%%%%%%% elseif (( G < 0 ) & (strcmp(type,'Base_Shelf'))) b0 = (1 + root2*K + K^2) / (1 + root2*sqrt(V0)*K + V0*K^2); b1 = (2 * (K^2 - 1) ) / (1 + root2*sqrt(V0)*K + V0*K^2); b2 = (1 - root2*K + K^2) / (1 + root2*sqrt(V0)*K + V0*K^2); a1 = (2 * (V0*K^2 - 1) ) / (1 + root2*sqrt(V0)*K + V0*K^2); a2 = (1 - root2*sqrt(V0)*K + V0*K^2) / (1 + root2*sqrt(V0)*K + V0*K^2); %%%%%%%%%%%%%%%%%%%% % TREBLE BOOST %%%%%%%%%%%%%%%%%%%% elseif (( G > 0 ) & (strcmp(type,'Treble_Shelf'))) b0 = (V0 + root2*sqrt(V0)*K + K^2) / (1 + root2*K + K^2); b1 = (2 * (K^2 - V0) ) / (1 + root2*K + K^2); Bass / Treble Shelving Filter: shelving(G, fc, fs, Q, type) - File Exchang... http://www.mathworks.com/matlabcentral/fileexchange/16568-bass-tre... 1 of 2 2014/01/19 5:09 ﺏ.ﻅ

Upload: googlechrome1

Post on 30-Dec-2015

30 views

Category:

Documents


0 download

DESCRIPTION

Shelving filter

TRANSCRIPT

Page 1: Bass _ Treble Shelving Filter_ Shelving(G, Fc, Fs, Q, Type) - File Exchange - MATLAB Central

Search: File Exchange

Create Account Log In

File Exchange Answers Newsgroup Link Exchange Blogs Trendy Cody Contest MathWorks.com

by Jeff Tackett

Bass / Treble Shelving Filter

25 Sep 2007 (Updated 26 Sep 2007)

Generates coefficients for a 2nd order IIR digital filter

shelving(G, fc, fs, Q, type)

Download SubmissionCode covered by the BSD License

Highlights fromBass / Treble Shelving Filter

shelving(G, fc, fs, Q, ty...% Derive coefficients for a shelving filter with a given amplitude andView all files

function [b, a] = shelving(G, fc, fs, Q, type)

%% Derive coefficients for a shelving filter with a given amplitude and% cutoff frequency. All coefficients are calculated as described in % Zolzer's DAFX book (p. 50 -55). %% Usage: [B,A] = shelving(G, Fc, Fs, Q, type);%% G is the logrithmic gain (in dB)% FC is the center frequency% Fs is the sampling rate% Q adjusts the slope be replacing the sqrt(2) term% type is a character string defining filter type% Choices are: 'Base_Shelf' or 'Treble_Shelf'%% Author: Jeff Tackett 08/22/05%

%Error Checkif((strcmp(type,'Base_Shelf') ~= 1) && (strcmp(type,'Treble_Shelf') ~= 1)) error(['Unsupported Filter Type: ' type]);end

K = tan((pi * fc)/fs);V0 = 10^(G/20);root2 = 1/Q; %sqrt(2)

%Invert gain if a cutif(V0 < 1) V0 = 1/V0;end

%%%%%%%%%%%%%%%%%%%%% BASE BOOST%%%%%%%%%%%%%%%%%%%%if(( G > 0 ) & (strcmp(type,'Base_Shelf'))) b0 = (1 + sqrt(V0)*root2*K + V0*K^2) / (1 + root2*K + K^2); b1 = (2 * (V0*K^2 - 1) ) / (1 + root2*K + K^2); b2 = (1 - sqrt(V0)*root2*K + V0*K^2) / (1 + root2*K + K^2); a1 = (2 * (K^2 - 1) ) / (1 + root2*K + K^2); a2 = (1 - root2*K + K^2) / (1 + root2*K + K^2);

%%%%%%%%%%%%%%%%%%%%% BASE CUT%%%%%%%%%%%%%%%%%%%%elseif (( G < 0 ) & (strcmp(type,'Base_Shelf'))) b0 = (1 + root2*K + K^2) / (1 + root2*sqrt(V0)*K + V0*K^2); b1 = (2 * (K^2 - 1) ) / (1 + root2*sqrt(V0)*K + V0*K^2); b2 = (1 - root2*K + K^2) / (1 + root2*sqrt(V0)*K + V0*K^2); a1 = (2 * (V0*K^2 - 1) ) / (1 + root2*sqrt(V0)*K + V0*K^2); a2 = (1 - root2*sqrt(V0)*K + V0*K^2) / (1 + root2*sqrt(V0)*K + V0*K^2);

%%%%%%%%%%%%%%%%%%%%% TREBLE BOOST%%%%%%%%%%%%%%%%%%%%elseif (( G > 0 ) & (strcmp(type,'Treble_Shelf')))

b0 = (V0 + root2*sqrt(V0)*K + K^2) / (1 + root2*K + K^2); b1 = (2 * (K^2 - V0) ) / (1 + root2*K + K^2);

Bass / Treble Shelving Filter: shelving(G, fc, fs, Q, type) - File Exchang... http://www.mathworks.com/matlabcentral/fileexchange/16568-bass-tre...

1 of 2 ب.ظ 5:09 2014/01/19

Page 2: Bass _ Treble Shelving Filter_ Shelving(G, Fc, Fs, Q, Type) - File Exchange - MATLAB Central

Site Help Patents Trademarks Privacy Policy Preventing Piracy Terms of Use

Featured MathWorks.com Topics: New Products Support Documentation Training Webinars Newsletters MATLAB Trials Careers

b2 = (V0 - root2*sqrt(V0)*K + K^2) / (1 + root2*K + K^2); a1 = (2 * (K^2 - 1) ) / (1 + root2*K + K^2); a2 = (1 - root2*K + K^2) / (1 + root2*K + K^2);

%%%%%%%%%%%%%%%%%%%%% TREBLE CUT%%%%%%%%%%%%%%%%%%%%

elseif (( G < 0 ) & (strcmp(type,'Treble_Shelf')))

b0 = (1 + root2*K + K^2) / (V0 + root2*sqrt(V0)*K + K^2); b1 = (2 * (K^2 - 1) ) / (V0 + root2*sqrt(V0)*K + K^2); b2 = (1 - root2*K + K^2) / (V0 + root2*sqrt(V0)*K + K^2); a1 = (2 * ((K^2)/V0 - 1) ) / (1 + root2/sqrt(V0)*K + (K^2)/V0); a2 = (1 - root2/sqrt(V0)*K + (K^2)/V0) / (1 + root2/sqrt(V0)*K + (K^2)/V0);

%%%%%%%%%%%%%%%%%%%%% All-Pass%%%%%%%%%%%%%%%%%%%%else b0 = V0; b1 = 0; b2 = 0; a1 = 0; a2 = 0;end

%return valuesa = [ 1, a1, a2];b = [ b0, b1, b2];

Contact us

© 1994-2014 The MathWorks, Inc.

Bass / Treble Shelving Filter: shelving(G, fc, fs, Q, type) - File Exchang... http://www.mathworks.com/matlabcentral/fileexchange/16568-bass-tre...

2 of 2 ب.ظ 5:09 2014/01/19