std::vector<double> calculate_mag_response(double start_freq, double end_freq,
int N, std::vector<double> num, std::vector<double> den
The function should return a vector size N of magnitude responses in decibels of the transfer function defined by numerator and denominator vectors num and den.
To adequately test, you should drive this with more transfer functions.
#include <vector>
#include <iostream>
#include <cstdlib>
#include <ifstream>
using namespace std;
int main(int argc,char *argv[])
{
vector<double> myNum, myDen, results;
ifstream outfile;
int N;
outfile.open("datafile.txt");
myNum.push_back(1.0);
myNum.push_back(1.0); //create a smple zero at s=-1
myDen.push_back(1.0);
myDen.push_back(3.0);
myDen.push_back(2.0); //create two poles at s=-1,-2
results=calculate_mag_response(.1,1000,100,myNum,myDen); //Call the student function
if (N=results.size()!= 100)
{
cout << "Your function did not provide correct number of data points. Please fix" << endl;
exit(0);
}
for (int i=0;i<N;i++)
outfile << i << "\t" << results[i] << endl; //Write this garbage to a file
return(0);
}
# include <vector>
# include <iostream>
# include <cstdlib>
# include <fstream>
usingnamespace std;
std::vector<double> calculate_mag_response(double start_freq, double end_freq,
int N, std::vector<double> num, std::vector<double> den)
{
vector<double> tmpVect;
tmpVect.push_back(5.0);
tmpVect.push_back(1.3);
tmpVect.push_back(2.9);
tmpVect.push_back(3.0);
return tmpVect;
}
int main(int argc,char *argv[])
{
vector<double> myNum, myDen, results;
ofstream outfile;
int N;
outfile.open("datafile.txt");
myNum.push_back(1.0);
myNum.push_back(1.0); //create a smple zero at s=-1
myDen.push_back(1.0);
myDen.push_back(3.0);
myDen.push_back(2.0); //create two poles at s=-1,-2
results = calculate_mag_response(.1,1000,100,myNum,myDen); //Call the student function
if((N=results.size())!= 100)
{
cout << "Your function did not provide correct number of data points. Please fix" << endl;
exit(0);
}
for (int i=0;i<N;i++)
outfile << i << "\t" << results[i] << endl; //Write this garbage to a file
return(0);
}
I see you place a variable in here but put values in here that won't change. Is this correct? Also, Line 25 "datafile.txt", I dont know what to do with this because I don't have any files to open. Is this something I have to create? What would I but in it if that is the case?