File: smith.e

package info (click to toggle)
euler 1.61.0-12
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, bullseye, forky, sid, trixie
  • size: 5,164 kB
  • sloc: ansic: 24,761; sh: 8,314; makefile: 141; cpp: 47; php: 1
file content (63 lines) | stat: -rw-r--r-- 1,926 bytes parent folder | download | duplicates (16)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
function smith(r = [0, 0.2, 0.5, 1, 2, 5], x = [0.2, 0.5, 1, 2, 5])
## SMITH    Draws a Smith chart and sets hold to on so that you can plot the
##          reflection coefficient on top of it.
## This is a quick little hack that draws a simple Smith chart, a diagram
## that is very frequently used in high frequency engineering.  It maps
## the normalized impedance z to the reflection coefficient gamma:
## gamma = (z-1)/(z+1)  with z = r+i*x .
## You can customize the function by specifying the r and x parameters
## 3-13-95   Frank Wiedmann   for the matlab verion wiedmann@com.enst.fr
## 8-31-99   Eric Bouchar    for the update to euler Eric.Bouchare@wanadoo.fr
	
	_setplot([-1,1,-1,1]);
	hold on;
	h = textheight();
	w = textwidth();
	tr = 2*pi*(0:.01:1);

	plot([-1,1],[0,0]);
..	r = [0 .2 .5 1 2 5];   .. specify the r=const lines you want to draw
	for i=1 to length(r);
		rr = 1/(r{i}+1);
		cr = 1-rr;
		plot(cr+rr*cos(tr),rr*sin(tr));
		p = toscreen([cr-rr,0]);
		if r{i}==0;
			rtext(printf("%g",r{i}),[p{1}-(w/2),p{2}-(h/3)]);
		else
			rtext(printf("%g",r{i}),[p{1}-(w/2),p{2}]);
		endif;
	end;

..	x = [.2 .5 1 2 5];     .. specify the x=const lines you want to draw
	for i=1 to length(x);
		rx = 1/x{i};
		cx = rx;
		tx = 2*atan(x{i})*(0:.01:1);
		plot(1-rx*sin(tx),cx-rx*cos(tx));
		u = 1-rx*sin(2*atan(x{i}));
		v = cx-rx*cos(2*atan(x{i}));
		p=toscreen([u,v]);
		if u<0;
			rtext(printf("%g",x{i}),[p{1}-(w/2),p{2}-(h/3+h*v)]);
		elseif u>0
			text(printf("%g",x{i}),[p{1}+(w/2),p{2}-(h/3+h*v)]);
		else
			ctext(printf("%g",x{i}),[p{1},p{2}-(h+h/3)]);
		endif;
		
		plot(1-rx*sin(tx),-cx+rx*cos(tx));
		u = 1-rx*sin(2*atan(x{i}));
		v = -cx+rx*cos(2*atan(x{i}));
		p=toscreen([u,v]);
		if u<0;
			rtext(printf("%g",x{i}),[p{1}-(w/2),p{2}]);
		elseif u>0
			text(printf("%g",x{i}),[p{1}+(w/2),p{2}]);
		else
			ctext(printf("%g",x{i}),[p{1},p{2}+(h/3)]);
		endif;
	end;
	hold off;
	return 0;
endfunction