CHÖÔNG 15: TRÌNH TÍNH TOAÙN TUYEÁN VI BA
#include <stdio.h>
#include <conio.h>
#include <string.h>
#include <math.h>
#include "c:\hien\viba.h"
double f,ha,h1,h2,d,Ao,feeder,Lv,Aa,lamda,G,A,
FMa, FMb,Gt;
double
A1,pr,pt,RXa,RXb,loseA,loseB,G1,po,pa,pb,Ta,Tb;
double khongkhadung,Za,Zb,p10,p60;
double mem =3.95,e=2.71828,giandoan,tong_giandoan;
double erfc_fun(double x)
{
double k;
int i;
for (i=0;i<260;i++)
if(erfd[i]==x)
k=erfdr[i];
return k;
}
double arround(double x)
{
double nguyen,thapphan,tamp,tmp,temp;
thapphan = modf(x,&nguyen);
thapphan = thapphan*100;
tamp = modf(thapphan,&temp);
if(tamp<=0.3) tamp = 0;
if(0.3<tamp && tamp <=0.7) tamp =0.5;
if(tamp>0.7) tamp =1;
thapphan = temp + tamp;
thapphan = thapphan /100;
return thapphan + nguyen;
}
void nhap_bien()
{
printf("\nNhap Thong So\n");
printf("Cho biet do dai duong truyen dan (km):
"); scanf("%lf",&d);
printf("Cho biet tan so lam viec trung tam
(GHz): "); scanf("%lf",&f);
clrscr();
}
void free_space_lose()//ton that tuyen cua khong
gian tu do
{
Ao = 92.5 + 20*log10(f) + 20*log10(d);
printf("Ton that duong truyen cua khong gian tu
do la: %.3lf dB", Ao);
}
void feeder_lose() //ton that feeder
{
double lf1,lf2,feeder_type;
printf("Cho biet loai feeder su dung: \n");
printf("1. RG-59/U\n");
printf("2. RG-11/U\n");
printf("3. RG-24/U\n");
printf("4. RG-58/U\n");
switch(getch())
{
case '1' : feeder_type = 3.4; break;
case '2' : feeder_type = 2.5; break;
case '3' : feeder_type = 2; break;
case '4' : feeder_type = 7.8; break;
default : feeder_type =3.4;
}
printf("\nCho biet do cao anten tai tram A (m):
"); scanf("%lf",&h1);
printf("Cho biet do cao anten tai tram B (m):
"); scanf("%lf",&h2);
lf1 = 1.5*h1;
lf2 = 1.5*h2;
loseA = lf1*3.28*feeder_type/100;
loseB = lf2*3.28*feeder_type/100;
feeder = loseA + loseB;
printf("Ton that feeder tai tram A: %.3lf dB\n",
loseA);
printf("Ton that feeder tai tram B: %.3lf dB\n",
loseB);
printf("Ton that feeder: %.3lf dB\n", feeder);
}
void vatchan() //ton hao cua bo suy hao hoac cac
vat chanx
{
double d1[100],d2[100], hc[100],V[100],c,tmp;
int i, vc;
printf("Co bao nhieu vat chan: ");
scanf("%d",&vc);
for(i=0; i<vc; i++)
{
printf("Cho biet khoang cach tu tram A den
vat chan thu %d: ",i+1);
scanf("%lf", &tmp); d1[i] =tmp;
printf("Cho biet khoang cach tu tram B den
vat chan thu %d: ",i+1);
scanf("%lf",&tmp); d2[i]=tmp;
printf("Cho biet do cao vat chan %d:",i+1);
scanf("%lf",&tmp); hc[i] =tmp;
}
c = 3*pow(10,8);
lamda = c/(f*pow(10,9));
for(i=0;i<vc;i++)
printf("hc = %lf\n",hc[i]);
printf("Lamda = %0.3lf c= %0.3lf\n",lamda,c);
for(i=0;i<vc;i++)
{
V[i] = hc[i] * sqrt( (2/lamda) * (1/d1[i]) *
(1/d2[i]));
printf("\n V[%d] = %lf\n",i+1,V[i]);
}
for(Lv=0,i=0;i<vc;i++)
Lv += 6.4 + 20*log10(sqrt(V[i]+1)) + V[i];
printf("Ton hao cua bo suy hao hoac cac vat
chan: %.3lf dB", Lv);
}
void khiquyen() //ton hao khi quyen
{
double Tkq;
printf("Cho biet ton hao dac trung cua khi quyen
: "); scanf("%lf",&Tkq);
Aa=Tkq*d;
printf("Ton hao khi quyen: %.3lf dB ",Aa);
}
void total()//tong ton hao
{
double renhanh,bodaunoi;
printf("Cho biet ton hao re nhanh ( 2dB-8dB ):
"); scanf("%lf",&renhanh);
printf("Cho biet ton hao cac bo dau noi( 0.5dB-
1dB) : "); scanf("%lf",&bodaunoi);
A = Ao + Aa + feeder + renhanh + bodaunoi + Lv;
printf("Tong ton hao la: %.3lf dB", A);
}
void line_lose() //ton hao tuyen truyen
{
while(1)
{
clrscr();
printf("Ton that tuyen:\n");
printf("1. Ton that duong truyen cua khong gian
tu do\n");
printf("2. Ton that feeder\n");
printf("3. Ton hao cua bo suy hao hoac cac vat
chan\n");
printf("4. Ton hao khi quyen \n");
printf("5. Tong ton hao \n");
printf("s. Exit\n");
printf("Select: \n");
switch( getch())
{
case '1' : free_space_lose(); break;
case '2' : feeder_lose(); break;
case '3' : vatchan(); break;
case '4' : khiquyen();break;
case '5' : total();break;
}
if(getche() == '6') break ;
}
}
void gain() //do loi
{
double D,n;
clrscr();
printf("\t\tTinh Toan Do Loi\n");
printf("Cho biet cong suat may phat(dBm): ");
scanf("%lf",&pt);
printf("Cho biet duong kinh anten (m): ");
scanf("%lf",&D);
printf("Cho biet goc mo hieu dung: ");
scanf("%lf",&n);
printf("Cho biet nguong thu ung voi BER = 10^-3
(dB): "); scanf("%lf",&RXa);
printf("Cho biet nguong thu ung voi BER = 10^-6
(dB): "); scanf("%lf",&RXb);
G = 20 * log10(D) - 20*log10(lamda) + 10 *
log10(n) + 9.943;
G1 = pt; Gt = 2*G + G1 ;
A1 = A - Gt; pr = pt -A1;
FMa = pr -RXa;
FMb = pr - RXb;
clrscr();
printf("\n");
printf("Do loi cua anten: %.3lf dB\n",G);
printf("Do loi may phat: %.3lf dB\n",G1);
printf("Tong do loi: %.3lf dB\n", Gt);
printf("Tong ton hao: %.3lf dB\n", A1);
printf("Muc dau vao cua may thu: %.3lf dBm\n",
pr);
printf("Do du tru fading phang FMa: %.3lf dB,voi
BER = 10^-3\n", FMa);
printf("Do du tru fading phang FMb: %.3lf dB,voi
BER = 10^-6\n", FMb);
getch();
}
void fading() //gom xac suat fading nhiue tia, xs
tai cac nguong, thoi gian fading
{
double a,c, alpha,beta,c2;
double gamma,M,nuy,K,t;
clrscr();
printf("Cho biet he so cai tien dac trung cho dia
hinh a (0.25 - 4): ");
scanf("%lf",&a);
printf("Cho biet he so dia hinh C: \n");
printf(" 1. 1 cho dia hinh trung binh co khi hau
on doi\n");
printf(" 2. 4 cho dia hinh tren mat nuoc bo bien
hay khi hau am uot\n");
printf(" 3. 0.25 cho dia hinh mien nui va khi hau
kho\n");
switch (getch())
{
case '1' : c = 1;printf("C=1"); break;