📄 calc_components.html
字号:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"><html xmlns:mwsh="http://www.mathworks.com/namespace/mcode/v1/syntaxhighlight.dtd"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> <!--This HTML is auto-generated from an M-file.To make changes, update the M-file and republish this document. --> <title>calc_components.m</title> <meta name="generator" content="MATLAB 7.4"> <meta name="date" content="2008-05-08"> <meta name="m-file" content="calc_components"><style>body { background-color: white; margin:10px;}h1 { color: #990000; font-size: x-large;}h2 { color: #990000; font-size: medium;}/* Make the text shrink to fit narrow windows, but not stretch too far in wide windows. */ p,h1,h2,div.content div { max-width: 600px; /* Hack for IE6 */ width: auto !important; width: 600px;}pre.codeinput { background: #EEEEEE; padding: 10px;}@media print { pre.codeinput {word-wrap:break-word; width:100%;}} span.keyword {color: #0000FF}span.comment {color: #228B22}span.string {color: #A020F0}span.untermstring {color: #B20000}span.syscmd {color: #B28C00}pre.codeoutput { color: #666666; padding: 10px;}pre.error { color: red;}p.footer { text-align: right; font-size: xx-small; font-weight: lighter; font-style: italic; color: gray;} </style></head> <body> <div class="content"> <h1>calc_components.m</h1> <introduction></introduction> <h2>Contents</h2> <div> <ul> <li><a href="#2">Initializations</a></li> <li><a href="#4">Component calculations:</a></li> <li><a href="#6">Error message return</a></li> </ul> </div> <p>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 <tt>options</tt> vector. </p><pre class="codeinput"><span class="keyword">function</span> [r1,r2,r5,c3,c4,error_msg] = calc_components(q0,w0,hbp,options)</pre><h2>Initializations<a name="2"></a></h2> <p>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. </p> <p>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. </p> <p>Finally, the minimum and maximum capacitor values are set as defined by the user in the options vector.</p><pre class="codeinput"> error_msg1 = <span class="string">'With the supplied parameters and options, a component match could not be found for filter(s):'</span>; error_msg2 = <span class="string">''</span>; n = length(q0); r1 = zeros(1,n); <span class="comment">%initialize component values</span> r2 = zeros(1,n); c3 = zeros(1,n); c4 = zeros(1,n); r5 = zeros(1,n); cap_init = options(4)*1.5; <span class="comment">%initial cap choice may change</span> <span class="comment">%due to scaling. start</span> <span class="comment">%high, we'll scale down.</span> max_r = options(2); <span class="comment">%min and max resistance valcues</span> min_r = options(1); <span class="comment">%governed by max op amp current output</span> <span class="comment">%and noise.</span></pre><h2>Component calculations:<a name="4"></a></h2> <p>For each filter, the program searches for a component value combination which will satisfy the filter parameters and the limitations set by the user. </p> <p>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. </p> <p>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. </p> <p>The specific equations can be found online.</p><pre class="codeinput"> <span class="keyword">for</span> filter_n = 1:n <span class="comment">%calculate the component values</span> <span class="keyword">while</span>( ((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; <span class="keyword">if</span>(cap_init < options(3)) error_num = sprintf(<span class="string">' %d '</span>,filter_n); error_msg2 = strcat(error_msg2,error_num); <span class="keyword">break</span> <span class="keyword">end</span> <span class="keyword">if</span>(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)); <span class="keyword">else</span> k = (hbp(filter_n)/q0(filter_n)^2) - 1; final_k = k + 2; <span class="comment">%this ensures that a value of r5 will be</span> <span class="comment">%positive. 2 can be</span> <span class="comment">%reduced to allow more</span> <span class="comment">%values</span> 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); <span class="keyword">end</span><span class="comment">%quality check</span> <span class="keyword">end</span> <span class="comment">%resistor check</span> <span class="keyword">end</span> <span class="comment">%for each filter</span></pre><h2>Error message return<a name="6"></a></h2><pre class="codeinput"> error_msg = strcat(error_msg1,error_msg2); <span class="keyword">end</span> <span class="comment">%function</span></pre><p class="footer"><br> Published with MATLAB® 7.4<br></p> </div> <!--##### SOURCE BEGIN #####%% 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 %%##### SOURCE END #####--> </body></html>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -