DOC PREVIEW
UK EE 221 - Matlab and Parameter Optimization

This preview shows page 1-2-3-4 out of 11 pages.

Save
View full document
View full document
Premium Document
Do you want full access? Go Premium and unlock all 11 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 11 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 11 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 11 pages.
Access to all documents
Download any document
Ad free experience
Premium Document
Do you want full access? Go Premium and unlock all 11 pages.
Access to all documents
Download any document
Ad free experience

Unformatted text preview:

6.1Matlab and Parameter Optimization:You should develop equations that relate your design parameters to the error criteria. If you can solve for the parameters directly from the equation, you are finished - you have the optimal performance for the circuit you proposed. Unfortunately in many cases, the large number of parameters or the nonlinear relationship between them , makes this solution very difficult or impossible.The performance equations, however, can be examined though a program such as Matlab, and optimization can be done though a creative strategy for iterating thoughthe critical performance parameters until the error is at a practical minimum.Matlab functions: Available Matlab functions can be combined together in a program to create a custom function.Example: Create a Matlab function that will evaluate points of a transfer function of a first-order low-pass filter given an array for the frequency axis points (in Hz), the cutoff frequency (in Hz), and the gain at DC (in dB).1) Use a text editor to create a file lpf1.m (functions in Matlab always end in .m).2) Then enter the following text.6.2function h = lpf1(f,fc,gdb)% This function evaluates complex points of a first % order low-pass filter with cut-off frequency fc % in Hertz, and a gain in dB at DC of gdb. The% function syntax is:%% tflp = lpf1(f, fc, gdb)%% where f is an array of points in Hertz where the% function is eavluated at, and tfpl is the array of% complex evaluation points.%j = sqrt(-1);p = j*2*pi*f;gdc = 10^(gdb/20);h = gdc./(p/(2*pi*fc) + 1 ); 3) Save the file in your “working directory” and execute in Matlab just like any other function. If you type help lpf1 in Matlab, the first sequence of comments will print to the screen.4) All variables defined inside the function will be undefined when the function is through (local variables).6.3Create an analogous function for a high-pass filter:1) Create file with a text editor called hpf1.m and enter:function h = hpf1(f,fc,gdb)% This function evaluates complex points of a first % order high-pass filter with cut-off frequency fc % in Hertz, and a gain in dB at infinity of gdb. % The function syntax is:%% tfhp = hpf1(f, fc, gdb)%% where f is an array of points in Hertz where the% function is evaluated at, and tfhp is the array of% complex evaluation points.%j = sqrt(-1);p = j*2*pi*f;ginf=10^(gdb/20);h = ginf*(p/(2*pi*fc))./(p/(2*pi*fc) + 1 ); Matlab Scripts: Matlab functions can be combined together to create a series of commands to be executed.6.4Example: Create a Matlab script to examine the mean and variance error between acascaded low-pass and high-pass filter, and a band-pass-like transfer function with a flat 10 dB passband extending from 5 kHz to 50 kHz with a 20 dB per decade roll-offat either end of the passband. The gain in the passband is 10 dB. Only consider the error from 500 Hz to 500 kHz.1) Strategy: Consider the major portion of overlap between the passbands of the LPF and HPF to exist, so set the gains equal about 5.6 dB each, so now we only will consider minimizing the error with respect to 2 parameters - the cutoff frequencies ofthe LPF and the HPF. The gain can be adjusted later if our assumption is not very accurate.2) Create a file in a text editor called ex6.m, and enter:f =logspace(log10(500),log10(500e3), 512); % define axis for evaluation% Create target function (Described in Example)ht = zeros(1,512); % Set up array to fill with function pointsfor k=1:512 % For points less than 5kHz create a line on a log scale if( f(k) < 5e3) , ht(k) = -10 + 20*log10(f(k)/500); % For points greater than 5kHz and less than 50kHz elseif(f(k) < 5e4), ht(k) = 10;6.5 % for points greater than 50kHz create a line on a log scale else ht(k) = 10 - 20*log10(f(k)/5e4); endendfigure(1)semilogx(f,ht) % Check to see if it did what we wanted it togridtitle('Target TF')xlabel('Hertz')ylabel('dB')pause % Script will pause until the keyboard is struck% Set up nested loops to vary the cutoff frequencies for HPF and LPF% Try a neighborhood of frequencies around f= 5 kHz and 50 kHz.fhc = linspace(3500,7500,25); % Select a set of high-pass cut-offsflc = linspace(35000, 55000, 25); % Select a set of low-pass cut-offs% Set up arrays to store computed error termsem = zeros(25,25); % mean error (bias)ev = zeros(25,25); % variance error (consistency of fit)% Fix Gain at 5.6 dB => 10^(5.6/20) = 1.9055 and optimize for low-pass% and high-pass cutoff% Note, this may not be the best gain, but is just an initial guess.for k=1:25,6.6 for n=1:25, h = lpf1(f,flc(k),5.6).*hpf1(f,fhc(n),5.6); % Compute Resultant TF % Compute errors em(k,n) = mean(ht-20*log10(abs(h))); ev(k,n) = std(ht-20*log10(abs(h))); %This is actually square root of the % variance, which is just as good in terms of finding a minimum point. endend[k,n] = find(abs(em) == min(min(abs(em))))%find mean error index close to 0% look at optimal TFh = lpf1(f,flc(k),5.6).*hpf1(f,fhc(n),5.6); % Compute Resultant TF % points at optimum semilogx(f,20*log10(abs(h)),'g')hold onsemilogx(f, ht,':r')hold offtitle('Compare target with design TF for minimum mean error')xlabel('Hertz')ylabel('dB')flcmm = flc(k) % Convert index to frequency valuefhcmm = fhc(n) % Convert index to frequency valuepause[k,n] = find(ev == min(min(ev))) % find index of minimum variance errorh = lpf1(f,flc(k),5.6).*hpf1(f,fhc(n),5.6); % Compute Resultant TF points at optimum figure(2)semilogx(f,20*log10(abs(h)),'g')6.7hold onsemilogx(f, ht,':r')hold offtitle('Compare target with design TF for minimum variance error')xlabel('Hertz')ylabel('dB')flcsd = flc(k) % Convert index to frequency valuefhcsd = fhc(n) % Convert index to frequency valuepausefigure(3)mesh(fhc, flc, abs(em)) % Look at graphic distribution of error.title('mean error')figure(4)mesh(fhc, flc, ev)title('standard deviation error')pause% To get a better view, try an intensity plot of the same data:figure(3)imagesc(fhc, flc, abs(em)) colormap('gray')colorbartitle('mean error')xlabel(' High-pass cut-off')ylabel(' Low-pass cut-off')figure(4)imagesc(fhc, flc, ev)6.8colormap('gray')colorbarxlabel(' High-pass cut-off')ylabel(' Low-pass cut-off')title('standard deviation error')3) Save file and type ex6 at Matlab prompt. These commands will execute and when


View Full Document

UK EE 221 - Matlab and Parameter Optimization

Documents in this Course
Filters

Filters

8 pages

Unit 12

Unit 12

13 pages

Load more
Download Matlab and Parameter Optimization
Our administrator received your request to download this document. We will send you the file to your email shortly.
Loading Unlocking...
Login

Join to view Matlab and Parameter Optimization and access 3M+ class-specific study document.

or
We will never post anything without your permission.
Don't have an account?
Sign Up

Join to view Matlab and Parameter Optimization 2 2 and access 3M+ class-specific study document.

or

By creating an account you agree to our Privacy Policy and Terms Of Use

Already a member?