📄 calc_components.m
字号:
%% calc_components.m%%% This function computes the component values for each filter in the% equalizer. It also returns an error string in the case that good% component combinations cannot be found. In addition to the filter% parameters, the function also needs the maximum and minium component% values set by the user, which are held in the |options| vector.function [r1,r2,r5,c3,c4,error_msg] = calc_components(q0,w0,hbp,options)%% %% Initializations%%% First, the error messages are initialized. Later, specific information will % be added to error_msg2, and the 2 error messages will be concantinated% Next, a vector is made for each component of a multiple feedback filter.% The index of these vectors will define which filter of equalizer the% particular component belongs to. For example, r5(2) is R5 of filter 2.% % Next, an intial capacitor value is established. Since the capacitor% value will be divided down, the value is first mutliplied (see below).% Could have used a do/while there instead.%% Finally, the minimum and maximum capacitor values are set as defined by% the user in the options vector. error_msg1 = 'With the supplied parameters and options, a component match could not be found for filter(s):'; error_msg2 = ''; n = length(q0); r1 = zeros(1,n); %initialize component values r2 = zeros(1,n); c3 = zeros(1,n); c4 = zeros(1,n); r5 = zeros(1,n); cap_init = options(4)*1.5; %initial cap choice may change %due to scaling. start %high, we'll scale down. max_r = options(2); %min and max resistance valcues min_r = options(1); %governed by max op amp current output %and noise.%% %% Component calculations:%%% For each filter, the program searches for a component value combination% which will satisfy the filter parameters and the limitations set by the% user.%% The while loop continues the search until a match satisfying the% conditions has been found. If the search continues too long (IE, the% capacitor value has become too small), the search fails, and an error% string.%% The 5 component values must satisfy the 3 filter parameters, so a% relationship between 2 component values can be established. For high% quality filters, c3 = c4. For low quality filters, c3 = n*c4, and n is% calculated. % % The specific equations can be found online. for filter_n = 1:n %calculate the component values while( ((r1(filter_n) < min_r) || (r1(filter_n) > max_r)) || ((r2(filter_n) < min_r) || (r2(filter_n) > max_r)) || ((r5(filter_n) < min_r) || (r5(filter_n) > max_r)) ) cap_init = cap_init/1.5; if(cap_init < options(3)) error_num = sprintf(' %d ',filter_n); error_msg2 = strcat(error_msg2,error_num); break end if(q0(filter_n) > sqrt(hbp(filter_n)/2)) c3(filter_n) = cap_init; c4(filter_n) = cap_init; r1(filter_n) = q0(filter_n)/(hbp(filter_n)*w0(filter_n)*c3(filter_n)); r2(filter_n) = q0(filter_n)/((2*q0(filter_n)^2 - hbp(filter_n))*w0(filter_n)*c3(filter_n)); r5(filter_n) = 2*q0(filter_n)/(w0(filter_n)*c3(filter_n)); else k = (hbp(filter_n)/q0(filter_n)^2) - 1; final_k = k + 2; %this ensures that a value of r5 will be %positive. 2 can be %reduced to allow more %values c3(filter_n) = final_k * cap_init; c4(filter_n) = cap_init; r1(filter_n) = q0(filter_n)/(hbp(filter_n)*w0(filter_n)*c4(filter_n)); r2(filter_n) = q0(filter_n)/(((final_k + 1)*q0(filter_n)^2 - hbp(filter_n))*w0(filter_n)*c4(filter_n)); r5(filter_n) = (final_k + 1)*q0(filter_n)/(w0(filter_n)*c4(filter_n)*final_k); end%quality check end %resistor check end %for each filter%% Error message return error_msg = strcat(error_msg1,error_msg2); end %function %%
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -