summaryrefslogtreecommitdiff
path: root/macros/zplane.sci
blob: 696fef0db19f3a8ce82f7aff095634a8f0696048 (plain)
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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
//Pole-Zero plot for Discrete time systems

//Calling Sequence
//zplane(z)
//zpalne(z,p)

//Parameters:
//z: vector containing numerator coefficients
//p: vector containing denumerator coefficients

//Description:
//This function gives pole zero plote of discrete time systems

//Example :
//zplane([1 2 3],[4 5 6])
//Output :
//Output is pole zero plot of respective discrete time system.



//**************************************************************************************************
//______________________________________version1 code (not working)_________________________________
//__________________________________________________________________________________________________
//**************************************************************************************************

//function [y] = zplane(z,p)
//funcprot(0);
//
//rhs = argn(2)
//
//if(rhs<1 | rhs>2)
//error("Wrong number of input arguments.")
//end
//	select(rhs)
//	case 1 then
//	callOctave("zplane",z)
//	case 2 then
//	callOctave("zplane",z,p)
//	end
//endfunction

//**************************************************************************************************
//______________________________________________version2 code ( working)____________________________
//__________________________________________________________________________________________________
//**************************************************************************************************

function zplane(z,varargin)

    funcprot(0);

    [nargout nargin] = argn();
    if nargin == 1 then
        p = [];
    else
        p = varargin(1);
    end

[rows_z columns_z] = size(z);
[rows_p columns_p] = size(p);
  if (nargin < 1 | nargin > 2)
    error("Invalid inputs")
  end
  if columns_z>1 | columns_p>1
    if rows_z>1 | rows_p>1
//      ## matrix form: columns are already zeros/poles
    else
//      ## z -> b
//      ## p -> a
      if isempty(z), z=1; end
      if isempty(p), p=1; end

      M = length(z) - 1;
      N = length(p) - 1;
      z = [ roots(z); zeros(N - M, 1) ];
      p = [ roots(p); zeros(M - N, 1) ];
    end
  end


  xmin = min([-1; real(z(:)); real(p(:))]);
  xmax = max([ 1; real(z(:)); real(p(:))]);
  ymin = min([-1; imag(z(:)); imag(p(:))]);
  ymax = max([ 1; imag(z(:)); imag(p(:))]);
  xfluff = max([0.05*(xmax-xmin), (1.05*(ymax-ymin)-(xmax-xmin))/10]);
  yfluff = max([0.05*(ymax-ymin), (1.05*(xmax-xmin)-(ymax-ymin))/10]);
  xmin = xmin - xfluff;
  xmax = xmax + xfluff;
  ymin = ymin - yfluff;
  ymax = ymax + yfluff;

//  text();
//  plot_with_labels(z, "o");
//  plot_with_labels(p, "x");
//  refresh;

  r = exp(2*%i*%pi*[0:100]/100);
  plot(real(r), imag(r),'k'); //hold on;
//  axis equal;
//  grid on;
  xgrid ;
  mtlb_axis(1.05*[xmin, xmax, ymin, ymax]);
  if (~isempty(p))
    h = plot(real(p), imag(p), "bx");
    //set (h, 'MarkerSize', 7);
  end
  if (~isempty(z))
    h = plot(real(z), imag(z), "bo");
    //set (h, 'MarkerSize', 7);
  end
  legend('unit circle','poles','zeros');
//  hold off;

endfunction

//function plot_with_labels(x, symbol)
//
//    [rows_x columns_x] = size(x);
//
//  if ( ~isempty(x) )
//
//    x_u = unique(x(:));
//
//    for i = 1:length(x_u)
//      n = sum(x_u(i) == x(:));
//      if (n > 1)
//        xstring(real(x_u(i)), imag(x_u(i)), [" " msprintf('string', n)]);
//      end
//    end
//
//    col = "rgbcmy";
//    for c = 1:columns_x
//      plot(real( x(:,c) ), imag( x(:,c) ), [col(pmodulo(c,6)),symbol ";;"]);
//    end
//
//  end
//
//endfunction