AEE

Latest Posts

# antenna calculator using C++ programming

- Wednesday, July 29, 2015 No Comments
Below is a C++ program that calculates various antenna design parameters or performance evaluation parameters. The program calculates the reflection coefficient, VSWR, efficiency and gain for an antenna.

#include <iostream>
#include <cmath>
using namespace std;

int main()
{
int c;

cout << "Choice what you want to calculate: ";
cout << "\nEnter 1 for reflection coefficient,\n2 for VSWR,\n3 for gain,\n4 for efficiency" << endl;
cin >> c;

switch (c)
{
case 1:
float vi,vr;
cout << "Enter voltage incident: ";
cin >> vi;
cout << "Enter voltage reflected: ";
cin >> vr;

cout << "Reflection coefficient(S11): " << vr/vi;

break;

case 2:
float s11;
cout << "Enter reflection coefficient(S11): ";
cin >> s11;

cout << "VSWR :" << (1+abs(s11))/(1-abs(s11));

break;

case 3:
float pt, pr;
cout << "Enter Total Power Available: ";
cin >> pt;
cout << "Enter Power radiated: ";
cin >> pr;

cout << "Efficiency: " << pr/pt;

break;

case 4:
float eff,d;
cout << "Enter the antenna efficiency: ";
cin >> eff;
cout << "Enter the Directivity: ";
cin >> d;

cout << "The Gain is: " << d*eff;

break;

default:
cout << "Enter either 1,2,3 or 4 according to what you want to calculate";

}

return 0;

}

The program ask users to enter what they want to calculate(reflection coefficient, VSWR, efficiency or gain). Then according to user choice the user is asked to enter values which are required to calculate the corresponding antenna design parameter. The result is then displayed to the user.

# Reflection Coefficient, VSWR, Efficiency, Gain Online Calculator for antenna design

An antenna performance can be measured using various parameters. The important or essential antenna design parameter or performance calculator include the Reflection Coefficient, VSWR, Efficiency, Gain and Bandwidth. These are also used to compare antennas. Below are online calculator to calculate these values.

1. Reflection Coefficients

The Reflection Coefficient S11 gives information about how much voltage that was supplied to the antenna are reflected back. Mathematically it is expressed as the ratio of Voltage Reflected to the Voltage Incident(Supplied).

$S_{11} = \frac{Voltage\ Reflected}{Voltage\ Incident}$

 Reflection Coefficient Calculator: Voltage Incident : V Voltage Reflected : V         Reflection Coefficient(S11) : S11(dB) : dB Return Loss(RL) :

2. VSWR(Voltage Standing Wave Ratio)

The VSWR is another parameter that is used to check and analyze antenna design. It is a parameter that is based on the fact that when voltage is induced into the antenna and part of it is reflected back these waveform superimpose and form constructive and destructive waves. Based on this phenomenon, the VSWR is the ratio of voltage maximum and voltage minimum of the resulting superimposed waveform.

Mathematically VSWR is defined as follows,

$VSWR = \frac{|V_{max}|}{|V_{min}|}=\frac{1+|S_{11}|}{1-|S_{11}|}$

 VSWR Calculator: Reflection Coefficient(S11) :         VSWR :

3. Efficiency

Efficiency of an antenna describes how much power supplied to the antenna is actually used up. Mathematically it is the ratio of Power Radiated to the Total Power Available from the source.

$Efficiency = \frac{P_{rad}}{P_{total\ power\ available}}$

 Efficiency Calculator: Power Radiated(Pr) : W Total Power Available(Pt) : W         Efficiency : Efficiency(dB) :

4. Gain

Gain here means Power Gain in a certain specific direction. It measures the capability of an antenna to direct power into certain direction. Mathematically it is the product of  antenna Efficiency and Directivity of an antenna.

 Gain Calculator: Efficiency(Eff) : Directivity(D) :         Gain :

5. Bandwidth

The bandwidth of an antenna gives measure of frequency range over which the reflection coefficient(hence VSWR, return loss) is within a certain specified range. In order words, for example, when we say the the bandwidth of antenna is -6dB at 132MHz, it means that S11 or reflection coefficient in dB unit is -6dB over 132MHz frequency bandwidth. Below figure illustratives this concept.

The bandwidth of antenna is calculated using network analyzer(antenna measurement device) or is simulated using antenna software. Thus there is no calculator required here.

# What are Accessor and Mutator Functions in C++ programming?

Accessor and Mutator Functions are types class functions named so because the former type of function can only access the member data and the latter can modify the member data.

For example in the last C++ tutorial, we made a simple C++ program to illustrate how function can access and change the private data member.

Here is the code again,

#include <iostream>
using namespace std;

class U{
private:
int x;
public:

void display()
{
cout << "Value of x is: " << x;
}

void setdatamember(int mynum)
{
x = mynum;
}
};

int main()
{
U obj;
int num;

cout << "enter a number: ";
cin >> num;

obj.setdatamember(num);
obj.display();

return 0;

}

What we have is one data member x and two public functions setdatamember( ) and display( ).

The display( ) public function member is called Accessor and the setdatamember( ) public function member is called Mutator function in C++ programming.

The setdatamember( ) function which is mutator is used in the code example to set the value of data member x(which is private in this case). A function is called Mutator not only when it can set members of a class but also when it can change the member. So for example, when we write simple x++ in the function setdatamember( ) function thus changing value of x then it is also called mutator.

Similarly, display( ) function member in the code example above is a accessor because it is used only to access the member of the class. Accessor function cannot change the value or set the value of a class member.

# how to set and display private class data member in C++

The data member that are declared private in a C++ class are difficult to set and access.

Here is how one can set and display private class data member in C++.

Suppose we have x as private data member in a some class called U.

class U{
private:
int x;
};

Now we want to set value to this private data x and also later on display the value stored in this private data x.

Let user enter the value that they want to store in x.

cout << "enter a number: ";

in the main function.

The following will not work to set the private data member x.

cin >> obj.x;

where obj is object of class U,

int main()
{
U obj;
....
....

}

C compiler will report that x is a private member of class U.

The set the value x we need to declare a private member function of the class U. We should then use that function to set the value of private data member x.

Continuing the above example, we store the number entered by the user in some integer(in this example) num as follows,

int main()
{
U obj;
int num;

cout << "enter a number: ";
cin >> num;

Next we want to assign num to x. If we can do this then we have successfully set the private data x. And for this as said before we need a public function member. Let this function be called setdatamember( ).

Then we declare this in the class U as follows,

class U{
private:
int x;

public:
void setdatamember(int mynum)
{
x = mynum;
}
};

and call this function in the main function-

class U{
private:
int x;

public:

void setdatamember(int mynum)
{
x = mynum;
}
};

int main()
{
U obj;
int num;

cout << "enter a number: ";
cin >> num;

obj.setdatamember(num);

return 0;

}

Until now, the above code, sets the value of the private data member x. Users enters some integer value and that gets stored in num. The num is passed to the public function setdatamember( ) which is accessed using the member access operator ".", that is, obj.setdatamember(num).

Then when the function setdatamember( ) is called, the num is passed to mynum. Then x gets the value of mynum. That is,

num = mynum = x

This way we can set the data member function.

How about displaying the value stored in the private data member function of a class?

To display the private data member x of the class U, we require another public function. If we call this function display( ), then we display the value of x as follows-

void display()
{
cout << "Value of x is: " << x;
}

and call this function in the main function using the member access operator-

obj.display();

Here is the full C++ code for all this-

#include <iostream>
using namespace std;

class U{
private:
int x;
public:

void display()
{
cout << "Value of x is: " << x;
}

void setdatamember(int mynum)
{
x = mynum;
}
};

int main()
{
U obj;
int num;

cout << "enter a number: ";
cin >> num;

obj.setdatamember(num);
obj.display();

return 0;

}

So we need anther class public function to display the private data member.

Here is the output example:

The following for example will not work.

cout << obj.x;

It is comprehensive book on planar antenna design with illustrative pictures. It is useful for those interested in the design of wireless communication system design such as mobile handset where planar antenna are used. It provides guidance to engineering students who wishes to learn how to design different types of antenna in their system. Microstrip antenna design, array of antenna and the design theory behind it are explained in this book.

Another good antenna design book is Antenna Theory and Microstrip Antennas

# Examples of Microstrip Patch antenna with pictures

Microstrip Patch antenna are important type of planar antenna and are used in application which requires low weight, small size RF/microwave frequency sensors such as in wireless mobile devices, biomedical devices and remote sensing etc. One can design different microstrip antenna having different structure which produces usually different radiation pattern. Some of the examples of microstrip patch antenna structures pictures are shown below.

1. Dipole Microstrip Patch antenna

2. Slot Microstrip Patch Antenna

3. Travelling Wave Microstrip Patch Antenna

These pictures were taken from antenna design book called Broadband Planar Antennas.