summaryrefslogtreecommitdiff
path: root/2.3-1/src/c/signalProcessing/%sn/zmodsns.c
blob: 5f35059ffa0c47e172fdce61cc6213df00f4ee6e (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
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
/* Copyright (C) 2017 - IIT Bombay - FOSSEE

 This file must be used under the terms of the CeCILL.
 This source file is licensed as described in the file COPYING, which
 you should have received as part of this distribution.  The terms
 are also available at
 http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt
 Author: Ankit Raj
 Organization: FOSSEE, IIT Bombay
 Email: toolbox@scilab.in
 Reference:- Abramowitz, Milton and Stegun, Irene A
             Handbook of Mathematical Functions, Dover, 1965
             Chapter 16 (Sections 16.4, 16.13 and 16.15)
	Link for FORTRAN code:-http://www.aip.de/groups/soe/local/numres/bookfpdf/f6-11.pdf
*/

#include<stdio.h>
#include<math.h>
#include "modsn.h"
#include "doubleComplex.h"
#define CA 0.0003

doubleComplex zmodsns(doubleComplex uu,double emmc)
{
	doubleComplex ans;
	double uur,uui;
	uur=zreals(uu);
	uui=zimags(uu);
	double sr,cr,dr;
        //Performing Elliptic Function operation for the real values
	double a1,b1,c1,d1,emc1,u1;
	double em1[14],en1[14];
	int i1,ii1,l1,bo1;
	emc1=1-emmc;
	u1=uur;
	if(emc1)
	{
	bo1=(emc1<0.0);
		if(bo1)
		{
			d1=1.0-emc1;
			emc1/=-1.0/d1;
			u1*=(d1=sqrt(d1));
		}
		a1=1.0;
		dr=1.0;
		for(i1=1;i1<=13;i1++)
		{
			l1=i1;
			em1[i1]=a1;
			en1[i1]=(emc1=sqrt(emc1));
			c1=0.5*(a1+emc1);
			if(fabs(a1-emc1)<=CA*a1)break;
			emc1*=a1;
			a1=c1;
		}
		u1*=c1;
		sr=sin(u1);
		cr=cos(u1);
		if(sr)
		{
			a1=cr/sr;
			c1*=a1;
			for(ii1=l1;ii1>=1;ii1--)
			{
				b1=em1[ii1];
				a1*=c1;
				c1*=dr;
				dr=(en1[ii1]+a1)/(b1+a1);
				a1=c1/b1;
			}
			a1=1.0/sqrt(c1*c1+1.0);
			sr=(sr>=0.0?a1:-a1);
			cr=c1*(sr);
		}
		if(bo1)
		{
			a1=dr;
			dr=cr;
			cr=a1;
			sr/=d1;
		}
	}
	else
	{
		cr=1.0/cosh(u1);
		dr=cr;
		sr=tanh(u1);
	}
	////////////////////////////////////////////////////////////////
	double si,ci,di;
	//Performing Elleptic Function operation for the imaginary values
	double a,b,c,d,emc,u;
	double em[14],en[14];
	int i,ii,l,bo;
	//double s1,c1,d1;
	emc=emmc;
	u=uui;
	if(emc)
	{
	bo=(emc<0.0);
		if(bo)
		{
			d=1.0-emc;
			emc/=-1.0/d;
			u*=(d=sqrt(d));
		}
		a=1.0;
		di=1.0;
		for(i=1;i<=13;i++)
		{
			l=i;
			em[i]=a;
			en[i]=(emc=sqrt(emc));
			c=0.5*(a+emc);
			if(fabs(a-emc)<=CA*a)break;
			emc*=a;
			a=c;
		}
		u*=c;
		si=sin(u);
		ci=cos(u);
		if(si)
		{
			a=ci/si;
			c*=a;
			for(ii=l;ii>=1;ii--)
			{
				b=em[ii];
				a*=c;
				c*=di;
				di=(en[ii]+a)/(b+a);
				a=c/b;
			}
			a=1.0/sqrt(c*c+1.0);
			si=(si>=0.0?a:-a);
			ci=c*(si);
		}
		if(bo)
		{
			a=di;
			di=ci;
			ci=a;
			si/=d;
		}
	}
	else
	{
		ci=1.0/cosh(u);
		di=ci;
		si=tanh(u);
	}
	/////////////////////////////////////////////////////////
	double delta;
	delta=ci*ci + emmc*sr*sr*si*si;
	double snir,snii;
	snir=(sr*di)/delta;
	snii=(cr*dr*si*ci)/delta;
	ans=DoubleComplex(snir,snii);
	return ans;	
}