#include <stdio.h>
#include <math.h>
#include <stdint.h>
/*
1弧度(rad) = 180/PI 度(deg) = 57.29577951308232 度(deg)
1度(deg) = PI/180 弧度(rad) = 0.017453292519943 弧度(rad)
*/
/* 波长计算公式
* lambda(λ)是波长,单位为米(m)
* c 是光速,约为 299,792,458 米/秒(m/s)
* f 是频率,单位为赫兹(Hz)
* 例如,如果毫米波雷达的工作频率为 77 GHz,则其波长约为 3.89 毫米。
*/
float get_lambda(float freq_GHz)
{
float c = 299792458.f;
float lambda = 0;
lambda = c / (freq_GHz * 1000.f * 1000.f * 1000.f);
return lambda;
}
#define PI (3.1415926F)
#define D_PI (6.2831852F)
#define TINY_VALUE (1e-3f) // computation accuracy
/** -----------------------------------------------------------------------------------------------
@brief absolute value function
@param[in] float x - input number
@return float result - absolute value of input data.
*//*---------------------------------------------------------------------------------------------*/
static inline float MyFabs(float x)
{
return (x > 0.0f) ? x : -x;
}
/** -----------------------------------------------------------------------------------------------
@brief sine calculation function
@param[in] float x - input number
@return float sum -result
*//*---------------------------------------------------------------------------------------------*/
float MySinf(float x)
{
float n,sum,x2,temp;
int32_t i, m;
/* the period of sine fucntion is 2*PI */
m = (int32_t)(x / D_PI);
x = x - D_PI * m;
n = x;
sum = 0.0f;
i = 1;
x2 = x * x;
/* Taylor expansion*/
do
{
sum += n;
i++;
temp = -n * x2;
n = temp / (((i << 2) - 6) * i + 2); // n = temp / (2*i - 1) / (2*i - 2);
} while (MyFabs(n)>=TINY_VALUE);
return sum;
}
/** -----------------------------------------------------------------------------------------------
@brief cosine calculation function
@param[in] float x - input number
@return float result
*//*---------------------------------------------------------------------------------------------*/
inline float MyCosf(float x)
{
return MySinf(PI/2.0f-x);
}
float d = 15;
float theta = 45.f;
float angle = 90.f - 45.f;
float w = 2 * 3.14 / 0.00001;
int main () {
printf("lambda λ = %f", get_lambda(76.05) * 1000.f);
float w = 2 . PI / get_lambda(76.05);
printf("w = %f\r\n", w);
return 0;
}