我正试图根据他在书中的方程式创建一个泰勒加权光束图案。一切都可以正确计算到某个特定点,但是将使用taylor denom的值,而不是重新计算。这就是我所拥有的:
#include <math.h>
#include <vector>
#include <iostream>
#include <cmath>
using namespace std;
int main ()
{
double sidelobeRatio, nbar, zeros, wave, length;
cout << "Please enter side lobe ratio, nbar, number of zeros less than or equal to nbar, the wavelength and length of the array." << endl;
cin >> sidelobeRatio >> nbar >> zeros >> wave >> length;
vector<double> DbValues;
double taylorA = 1/M_PI * acosh(pow(10,sidelobeRatio/20)); //Calculates the value of A for sigma and Zn (step 1b)
double sigma = nbar/pow(pow(taylorA,2)+pow((nbar-0.5),2),0.5); //Calculates the sigma constant for taylor weighting (step 2)
double Zn = sigma * pow(pow(taylorA,2)+pow((zeros-.5),2),(0.5)); //The Zn constant for taylor weighting (step 3)
for (double u=-90; u<=90; u=u + 45)
{
double z = (sin(u*M_PI/180)*length) / wave; //Calculates z for taylor weighting constant (step 1a)
double taylorSine = sin(M_PI*z)/(M_PI*z); //The sinc function for beamforming (step 4a)
cout << taylorSine << " this is taylor sine" << endl;
double taylorNumerator = 1-pow((z/Zn),2); //The numerator for the taylor weight constant (step 4b)
cout << taylorNumerator << " this is numerator" << endl;
double newValue = 1;
vector<double> newValues;
for (int zeros=1; zeros <= nbar-1; zeros++)
{
double taylorDenom = 1-pow((z/zeros),2); //The denomenator for the taylor weight constant (step 4c)
double taylorValue = taylorSine*(taylorNumerator/taylorDenom); //The taylor equation with capital pi operand (step 5)
newValue *= taylorValue;
newValues.push_back(newValue);
cout << taylorValue << " this is taylorValue" << endl;
}
int i;
for (i=0; i < newValues.size(); i++)
{
double convert = 10*log10(pow(newValues[i],2)); //converts F from linear to Db (step 6)
DbValues.push_back(convert);
}
double j;
for (j=0; j < DbValues.size(); j++)
{
cout << DbValues[j] <<endl;
}
cout << DbValues.size() << " this is DbValue" << endl;
cout << newValues.size() << " this is newValue" << endl;
}
return 0;
};
输出:
-3.89817e-17 this is taylor sine
-3 this is numerator
-1.18126e-18 this is taylorValue
-4.87271e-18 this is taylorValue
-1.1566e-17 this is taylorValue
-2.22753e-17 this is taylorValue
-358.553
-704.798
-1043.53
-1376.58
4 this is DbValue
4 this is newValue
-nan this is taylor sine
1 this is numerator
-nan this is taylorValue
-nan this is taylorValue
-nan this is taylorValue
-nan this is taylorValue
-358.553
-704.798
-1043.53
-1376.58
-nan
-nan
-nan
-nan
8 this is DbValue
4 this is newValue
-3.89817e-17 this is taylor sine
-3 this is numerator
-1.18126e-18 this is taylorValue
-4.87271e-18 this is taylorValue
-1.1566e-17 this is taylorValue
-2.22753e-17 this is taylorValue
-358.553
-704.798
-1043.53
-1376.58
-nan
-nan
-nan
-nan
-358.553
-704.798
-1043.53
-1376.58
12 this is DbValue
4 this is newValue
预期输出: enter image description here
对于每个计算出的新z,都需要计算一个新的泰勒定理,但由于某种原因,我一遍又一遍地得到相同的泰勒定理。如果需要进一步说明,请告诉我。
澄清:当u = 90度时,如果用户输入的nbar为5,则泰勒定理需要计算5次,且z和n从1到nbar-1。这没有发生,也许需要引入while循环吗?
我打印了sigma,Zn和taylorA,并且计算正确。最后的尺寸打印输出始终正确。其中的值不是。
输入: 比率:30 nbar:5个零点:5个波长:.1长度:1
答案 0 :(得分:0)
删除int i;并将其放入循环中
for (int i=0; i < newValues.size(); i++)
{
double convert = 10*log10(pow(newValues[i],2)); //converts F from linear to Db (step 6)
DbValues.push_back(convert);
}