Differences

This shows you the differences between two versions of the page.

chapters:mttap:microwaveutilities [2014/07/31 10:33]
robbo
chapters:mttap:microwaveutilities [2014/07/31 10:34] (current)
robbo
Line 1: Line 1:
 +====== Conversion and Function Utilities ======
 +
 +<html>
 +<link loadFile('//netdna.bootstrapcdn.com/twitter-bootstrap/2.3.1/css/bootstrap-combined.min.css') rel="stylesheet"></link>
 +</html>
 +
 +===== Power =====
 +
 +<html>
 +
 +<div class="span4">
 +  <div class="control-group">
 +      <label class="control-label" for="inputPowerDB">Power (dB)</label>
 +      <div class="controls">
 +      <div class="input-append">
 +          <input class="span2" id="powerdb" type="text">
 +          <span class="add-on">dB [Unit]</span>
 +          <button id="submitdb" class="btn">Convert <i class="icon-chevron-right"></i></button>
 +      </div>
 +    </div>
 +  </div>
 +</div>
 +
 +<div class="span4">
 +  <div class="control-group">
 +      <label class="control-label" for="inputPower">Power</label>
 +      <div class="controls">
 +      <div class="input-append">
 +          <input class="span2" id="powerlinear" type="text">
 +          <span class="add-on">[Unit]</span>
 +          <button id="submitlin" class="btn">Convert <i class="icon-chevron-left"></i></button>
 +      </div>
 +    </div>
 +  </div>
 +</div>
 +
 +<script src="//ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
 +<script src="//netdna.bootstrapcdn.com/twitter-bootstrap/2.3.1/js/bootstrap.min.js"></script>
 +<script DEFER>
 +// js-complex-math -  $Id: complex.js,v 0.17 2012/01/10 11:01:12 dankogai Exp dankogai $
 +eval(function(p,a,c,k,e,d){e=function(c){return(c<a?'':e(parseInt(c/a)))+((c=c%a)>35?String.fromCharCode(c+29):c.toString(36))};while(c--)if(k[c])p=p.replace(new RegExp('\\b'+e(c)+'\\b','g'),k[c]);return p}('(9(w){g(w.b.n)7;b.n=9 n(5,6){g(5 C b.n){7 a b.n(5.5,5.6)}z g(3 C b.n){3.5=5?+5:0;3.6=6?+6:0}z{7 a b.n(5,6)}};k 8=b.n,j=a 8(0,1),Q=11.G.Q;8.G.10=9(){k s=\'\'+3.5;g(3.6){g(3.6>0)s+=\'+\';s+=3.6;s+=\'i\'}7 s};8.I=8.J=j;8.H=9(f,m){7 a 8(f*b.B(m),f*b.A(m))},(9(v){P(k p O v)8.G[p]=v[p];P(k p O v)8[p]=(9(D){7 D.Z?9(x,y){7 D.N(x C 8?x:a 8(x),y)}:9(x){7 D.N(x C 8?x:a 8(x))}})(v[p])})({q:9(){7 a 8(-3.5,-3.6)},M:9(){7 a 8(3.5,-3.6)},m:9(){7 b.L(3.6,3.5)},f:9(){7 b.t(3.5*3.5+3.6*3.6)},Y:9(){7 3.5*3.5+3.6*3.6},o:9(4){7(4.e===3.e)?a 8(3.5+4.5,3.6+4.6):a 8(3.5+(+4),3.6)},F:9(4){7(4.e===3.e)?a 8(3.5-4.5,3.6-4.6):a 8(3.5-(+4),3.6)},c:9(4){7(4.e===3.e)?a 8(3.5*4.5-3.6*4.6,3.6*4.5+3.5*4.6):a 8(3.5*(+4),3.6*(+4))},u:9(4){g(4.e===3.e){k d=4.5*4.5+4.6*4.6;g(d===0)7 a 8(3.5/ 0, 3.6 /0);7 a 8((3.5*4.5+3.6*4.6)/d,(3.6*4.5-3.5*4.6)/d)}z{7 a 8(3.5/ (+4), 3.6 /(+4))}},l:9(){k f=b.l(3.5),m=3.6;7 a 8(f*b.B(m),f*b.A(m))},h:9(){7 a 8(b.h(3.f()),3.m())},X:9(4){7(4.e===3.e)?4.c(3.h()).l():(a 8(4,0)).c(3.h()).l()},t:9(){k r=3.f();7 a 8(b.t((r+3.5)/2),3.6<0?-b.t((r-3.5)/2):b.t((r-3.5)/2))},B:9(){7 3.c(j).l().o(3.q().c(j).l()).u(2)},A:9(){7 3.c(j).l().F(3.q().c(j).l()).u(j.c(2))},W:9(){7 3.B().u(3.A())},V:9(){7 3.o(3.c(3).q().o(1).t().c(j)).h().c(j).q()},U:9(){7 3.c(j).o(3.c(3).q().o(1).t()).h().c(j).q()},K:9(){k d=j.c(3).o(1);7 d.M().h().F(d.h()).c(j).u(2)},L:9(4){7 3.u(4).K()},E:9(4){g(4.e===3.e){7 3.5===4.5&&3.6===4.6}z{7 3.E(a 8(4,0))}},T:9(4){7!3.E(4)}});w.S=8;w.R=8.H})(3);',62,64,'|||this|that|re|im|return|CPLX|function|new|Math|mul||constructor|abs|if|log|||var|exp|arg|Complex|add||neg|||sqrt|div|methods|global|||else|sin|cos|instanceof|method|eq|sub|prototype|polar|||atan|atan2|con|call|in|for|slice|cplxe|cplx|ne|asin|acos|tan|pow|norm|length|toString|Array'.split('|')))
 +
 +
 +$('#submitdb').click(
 +  function (e) {
 +    $('#powerlinear').val( Math.pow(10, $('#powerdb').val() / 10) );   
 +});
 +
 +$('#submitlin').click(
 +  function (e) {
 +    $('#powerdb').val( 10 * Math.log($('#powerlinear').val())/Math.log(10) );   
 +});
 +</script>
 +</html>
 +
 +<html>
 +<div class="clearfix"></div>
 +</html>
 +
 +
 +===== Transmission Networks =====
 +
 +<html>
 +
 +<div class="span8">
 + <div class="control-group">
 +      <label class="control-label" for="impedance">Impedance (Z<sub>0</sub>)</label>
 +      <div class="control">
 +      <div class="input-append">
 +          <input class="span2" id="z0" type="text" value="50">
 +          <span class="add-on">Ω</span>
 +      </div>
 +      </div>
 + </div>
 +</div>
 +
 +<div class="span4">
 +<div class="row">ABCD Matrix</div>
 +<div class="row">
 +<div class="span1"><div class="control-group"><input type="text" id="abcd_A" placeholder="A" class="span1"></div></div>
 +<div class="span1"><div class="control-group"><input type="text" id="abcd_B" placeholder="B" class="span1"></div></div>
 +</div>
 +<div class="row">
 +<div class="span1"><div class="control-group"><input type="text" id="abcd_C" placeholder="C" class="span1"></div></div>
 +<div class="span1"><div class="control-group"><input type="text" id="abcd_D" placeholder="D" class="span1"></div></div>
 +</div>
 +</div>
 +
 +<div class="span4">
 +<div class="row">S Matrix</div>
 +<div class="row">
 +<div class="span1"><div class="control-group"><input type="text" id="s_S11" placeholder="S11" class="span1"></div></div>
 +<div class="span1"><div class="control-group"><input type="text" id="s_S12" placeholder="S12" class="span1"></div></div>
 +</div>
 +<div class="row">
 +<div class="span1"><div class="control-group"><input type="text" id="s_S21" placeholder="S21" class="span1"></div></div>
 +<div class="span1"><div class="control-group"><input type="text" id="s_S22" placeholder="S22" class="span1"></div></div>
 +</div>
 +</div>
 +
 +<button id="submitStoABCD" class="btn">Convert <i class="icon-chevron-left"></i></button>
 +<button id="submitABCDtoS" class="btn">Convert <i class="icon-chevron-right"></i></button>
 +
 +<script DEFER>
 +  function cleanWhitespace(str) {
 + str.replace(/\s+/g, " ");
 + return(str);
 +  }
 +  function parseComplex(str) {
 +// regex = /^([-+]?\d*\.?\d+)?([-+]?)(\d*\.?\d+?[ij])?$/i;
 + real = 0.0;
 + if (str == '-j') {
 + imag = -1;
 + } else if (str == 'j' || str == '+j') {
 + imag = 1;
 + } else {
 + regex = /^([-+]?\d+\.?\d*|[-+]?\d*\.?\d+)?(([-+]\d+\.?\d*|[-+]\d*\.?\d+|[-+])[ij])?$/i;
 + match = str.match(regex);
 + all = match[0];
 + real = match[1] != null ? parseFloat(match[1]) : 0.0;
 + if (match[2] == '+j') imag = 1;
 + else if (match[2] == '-j') imag = -1;
 + else imag = match[3] != null ? parseFloat(match[3]) : 0.0;
 + }
 + return(cplx(real, imag));
 +  }
 +
 +  function showSxxErrorFields() {
 +    var s11 = cleanWhitespace($('#s_S11').val());
 +    var s12 = cleanWhitespace($('#s_S12').val());
 +    var s21 = cleanWhitespace($('#s_S21').val());
 +    var s22 = cleanWhitespace($('#s_S22').val());
 +
 +    ok = 1;
 +    if (s11 == '') {
 +      $('#s_S11').parent().addClass('error'); ok = 0;
 +    } else
 +      $('#s_S11').parent().removeClass('error');
 +
 +    if (s12 == '') {
 +      $('#s_S12').parent().addClass('error'); ok = 0;
 +    } else
 +      $('#s_S12').parent().removeClass('error');
 +
 +    if (s21 == '') {
 +      $('#s_S21').parent().addClass('error'); ok = 0;
 +    } else
 +      $('#s_S21').parent().removeClass('error');
 +
 +    if (s22 == '') {
 +      $('#s_S22').parent().addClass('error'); ok = 0;
 +    } else
 +      $('#s_S22').parent().removeClass('error');
 +
 +    if (ok)
 +      return([s11, s12, s21, s22]);
 +    return(null);
 +  }
 +
 +  function showABCDErrorFields() {
 +    var aa = cleanWhitespace($('#abcd_A').val());
 +    var bb = cleanWhitespace($('#abcd_B').val());
 +    var cc = cleanWhitespace($('#abcd_C').val());
 +    var dd = cleanWhitespace($('#abcd_D').val());
 +
 +    ok = 1;
 +    if (aa == '') {
 +      $('#abcd_A').parent().addClass('error'); ok = 0;
 +    } else
 +      $('#abcd_A').parent().removeClass('error');
 +
 +    if (bb == '') {
 +      $('#abcd_B').parent().addClass('error'); ok = 0;
 +    } else
 +      $('#abcd_B').parent().removeClass('error');
 +
 +    if (cc == '') {
 +      $('#abcd_C').parent().addClass('error'); ok = 0;
 +    } else
 +      $('#abcd_C').parent().removeClass('error');
 +
 +    if (dd == '') {
 +      $('#abcd_D').parent().addClass('error'); ok = 0;
 +    } else
 +      $('#abcd_D').parent().removeClass('error');
 +
 +    if (ok)
 +      return([aa, bb, cc, dd]);
 +    return(null);
 +  }
 +
 +
 +$('#submitStoABCD').click(
 +  function (e) {
 +    z0 = parseFloat($('#z0').val());
 +    sparam = showSxxErrorFields();
 +
 +    if (sparam == null) return;
 +   
 +    xs11 = parseComplex(sparam[0]);
 +    xs12 = parseComplex(sparam[1]);
 +    xs21 = parseComplex(sparam[2]);
 +    xs22 = parseComplex(sparam[3]);
 +
 +    c1 = cplx(1, 0);
 +    xs11_p1 = xs11.add(1); // 1 + S11
 +    xs22_p1 = xs22.add(1); // 1 + S22
 +    xs22_s1 = c1.sub( xs22 ); // 1 - S22
 +    xs11_s1 = c1.sub( xs11 ); // 1 - S11
 +    xs12_ss21 = xs12.mul( xs21 ); // S12 * S21
 +    x2s21 = xs21.mul( 2 ); // 2 * S21
 +
 +    // real number starting point.
 +    //$('#abcd_A').val( ((1 + s11) * (1 - s22) + s12*s21)/(2*s21) );
 +    //$('#abcd_B').val( z0*((1 + s11) * (1 + s22) - s12*s21)/(2*s21) );
 +    //$('#abcd_C').val( 1/z0*((1 - s11) * (1 - s22) - s12*s21)/(2*s21) );
 +    //$('#abcd_D').val( ((1 - s11) * (1 + s22) + s12*s21)/(2*s21) );
 +
 +
 +    aa = (xs11_p1.mul( xs22_s1 ).add(xs12_ss21)).div(x2s21);
 +    bb = (xs11_p1.mul( xs22_p1 ).sub(xs12_ss21)).div(x2s21).mul(z0);
 +    cc = (xs11_s1.mul( xs22_s1 ).sub(xs12_ss21)).div(x2s21).div(z0);
 +    dd = (xs11_s1.mul( xs22_p1 ).add(xs12_ss21)).div(x2s21);
 +
 +    $('#abcd_A').val(aa);
 +    $('#abcd_B').val(bb);
 +    $('#abcd_C').val(cc);
 +    $('#abcd_D').val(dd);
 +
 +    });
 +
 +$('#submitABCDtoS').click(
 +  function (e) {
 +    z0 = parseFloat($('#z0').val());
 +    abcd = showABCDErrorFields();
 +
 +    if (abcd == null) return;
 +
 +    xaa = parseComplex(abcd[0]);
 +    xbb = parseComplex(abcd[1]);
 +    xcc = parseComplex(abcd[2]);
 +    xdd = parseComplex(abcd[3]);
 +
 +//    $('#s_S11').val( (aa+bb/z0 - cc*z0 - dd)/(aa+bb/z0 + cc*z0 + dd) );
 +//    $('#s_S12').val( (2*(aa*dd+bb*cc))/(aa+bb/z0+cc*z0+dd) );
 +//    $('#s_S21').val( (2)/(aa+bb/z0+cc*z0+dd) );
 +//    $('#s_S22').val( (-aa+bb/z0-cc*z0+dd)/(aa+bb/z0+cc*z0+dd) );
 +
 +        c2 = cplx(2, 0);
 + denom = xaa.add( (xbb.div(z0)) ).add( xcc.mul(z0) ).add(xdd);
 +        s11 = (xaa.add( (xbb.div(z0)) ).sub( xcc.mul(z0) ).sub(xdd)).div(
 +       denom );
 +        s12 = ( (xaa.mul(xdd).sub( xbb.mul(xcc) )).mul(2) ).div( denom );
 +        s21 = ( c2 ).div(denom);
 +        s22 = ( (xbb.div(z0)).sub(xaa).sub( (xcc.mul(z0)) ).add(xdd) ).div(denom);
 +
 +      $('#s_S11').val( s11 );
 +      $('#s_S12').val( s12 );
 +      $('#s_S21').val( s21 );
 +      $('#s_S22').val( s22 );
 +
 +});
 +</script>
 +
 +</html>
 +
 +<html>
 +<div class="clearfix"></div>
 +</html>
 +
 +Based on Table 5.2 in D. Pozar "Microwave Engineering", Addison-Wesley, 1993
 +
 +
 +
 
Last modified: 31 July, 2014