~ubuntu-branches/ubuntu/precise/yagiuda/precise

« back to all changes in this revision

Viewing changes to src/max_gain.c

  • Committer: Bazaar Package Importer
  • Author(s): Joop Stakenborg
  • Date: 2005-08-22 20:20:13 UTC
  • Revision ID: james.westby@ubuntu.com-20050822202013-mhhxp4xirdxrdfx1
Tags: upstream-1.19
ImportĀ upstreamĀ versionĀ 1.19

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#ifdef HAVE_STDLIB_H
 
2
#include <stdlib.h>
 
3
#endif
 
4
#include <stdio.h>
 
5
#include <math.h>
 
6
#include <errno.h>
 
7
#include "yagi.h"
 
8
 
 
9
extern int errno;
 
10
 
 
11
/* The maximum gain of a Yagi is given in the ARRL handbook, 1991, pp33-17
 
12
as 12dB at one wavelength boom length, rising at 2.6 dB 
 
13
each time boom lengtrh is doubled */
 
14
 
 
15
double determine_maximum_gain(double f, double boom_length_in_m)
 
16
{
 
17
        double lambda, wavelengths, max_gain;
 
18
 
 
19
        lambda=3e8/f;
 
20
 
 
21
        wavelengths=boom_length_in_m/lambda; /* boom length in wavelengths */
 
22
        if(wavelengths < 1)
 
23
                max_gain=8.0;
 
24
        else
 
25
                max_gain = 12.0 + 2.6*log2(wavelengths);
 
26
#ifdef DEBUG
 
27
        if(errno)
 
28
        {
 
29
                fprintf(stderr,"Errno =%d in determine_maximum_gain() of max_gain.c\n", errno);
 
30
                exit(1);
 
31
        }
 
32
#endif
 
33
        return(max_gain);
 
34
        
 
35
}
 
36
/* This is another algorithm. Its not as accurate as above, but it gives the
 
37
same result form given number of elements. This allows more accurate comparison
 
38
of fitnesss'es for the GA and -W algorithm, which would otherwise not be possible. */
 
39
double determine_maximum_gain2(int elements)
 
40
{
 
41
        double wavelengths, max_gain;
 
42
 
 
43
 
 
44
        wavelengths=(elements-1)*0.25; /* boom length in wavelengths */
 
45
        max_gain = 12.0 + 2.6*log2(wavelengths);
 
46
#ifdef DEBUG
 
47
        if(errno)
 
48
        {
 
49
                fprintf(stderr,"Errno =%d in determine_maximum_gain2() of max_gain.c\n", errno);
 
50
                exit(1);
 
51
        }
 
52
#endif
 
53
        return(max_gain);
 
54
        
 
55
}
 
56
double log2(double x)
 
57
{
 
58
        return(log(x)/0.6931471);
 
59
}