summaryrefslogtreecommitdiff
path: root/macros/phaseInputParseAs_ab.sci
blob: b5235fa791df878eee68912e085017fcee9842a8 (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
function [a,b,w,cas1,fs]=phaseInputParseAs_ab(arg,nargin)
    fs=0;
    if nargin<2 then
        error('no. of inputs not valid');
    end
    v=size(arg(2));
    if size(v)>2 then
        error ('invalid input dimension');
    end
    a=arg(1);
    b=arg(2);
    [n,k]=size(arg(2))
    if nargin==2 then //(a,b) is the input
        w=[0:(1/512):(511/512)]*%pi;
        cas1=1;
    elseif nargin==3 then //(a,b,n) or (a,b,w) or (a,b,'whole')
        cas1=1;
        v=size(arg(3));
        if type(arg(3))==10 then
            if arg(3)=='whole' then
                n=512;
                w=[0:(1/n):((n-1)/n)]*(2*%pi);
                cas1=1;
            else
                error('invalid input');
            end
        elseif (type(arg(3))==1)
            if (v==[1,1])&(floor(arg(3))==arg(3))&(arg(3)>0) then //i.e. the entry is a single integer
                n=arg(3);
                w=[0:(1/n):((n-1)/n)]*%pi;
            elseif (v(1)==1) then //(sos,w) w must be one dimensional
                w=arg(3);
            elseif (v(2)==1) then //w to row matrix
                w=(arg(3))';
            else
                error ('dimension of input is invalid');
            end
        else
            error ('invalid input');
        end
    elseif nargin==4 then //(a,b,n,fs) or (a,b,f,fs) or (a,b,n,'whole')
        if type(arg(4))==10 then
            cas1=1;
            if (arg(4)=='whole') then
                v=size(arg(3));
                if (v==[1,1])&(floor(arg(3))==arg(3))&(arg(3)>0) then //i.e. the entry is a single integer
                    n=arg(3);
                    w=[0:(1/n):((n-1)/n)]*(2*%pi);
                else
                    error ('dimension of input is invalid');
                end
            else
                error('invalid input');
            end
        elseif (type(arg(4))==1) then
            v=size(arg(4));
            if v~=[1,1] then
                error ('dimension of input is invalid');
            end
            cas1=2;
            fs=arg(4);
            v=size(arg(3));
            if (v==[1,1])&(floor(arg(3))==arg(3))&(arg(3)>0) then //i.e. the entry is a single integer
                n=arg(3);
                w=[0:(1/n):((n-1)/n)]*(%pi);
            elseif (v(1)==1) then //(sos,w) w must be one dimensional
                w=2*arg(3)*%pi/fs;
            elseif (v(2)==1) then //w to row matrix
                w=2*%pi*(arg(3))'/fs;
            else
                error ('dimension of input is invalid');
            end
        else
            error ('input format is invalid');
        end
    elseif nargin==5 //(a,b,n,fs,'whole') or (a,b,f,fs,'whole')
        if arg(5)=='whole' then
            v=size(arg(4));
            if v~=[1,1] then
                error ('dimension of input is invalid');
            end
            cas1=2;
            v=size(arg(3));
            if (v==[1,1])&(floor(arg(3))==arg(3))&(arg(3)>0) then //i.e. the entry is a single integer
                n=arg(3);
                w=[0:(1/n):((n-1)/n)]*(2*%pi);
            elseif (v(1)==1) then //(sos,w) w must be one dimensional
                w=2*arg(3)*%pi/fs;
            elseif (v(2)==1) then //w to row matrix
                w=2*%pi*(arg(3))'/fs;
            else
                error ('dimension of input is invalid');
            end
        else
            error ('input format is invalid');
        end
    end
    //so that a,b are row vectors
    [n,k]=size(a);
    if k==1 then
        a=a';
    end
    [n,k]=size(b);
    if k==1 then
        b=b';
    end
endfunction