Browse Source

repariert

master
teajay 5 years ago
parent
commit
e9140652d1
1 changed files with 21 additions and 7 deletions
  1. 28
      abgabe6.cpp

28
abgabe6.cpp

@ -16,7 +16,7 @@ using namespace std;
typedef struct {
long n;
double b, a, beta, alpha;
double tmin, tmax,h,tl;
double tmin, tmax,h,tl,signalLenght;
int m;
int sign;
} fft_param;
@ -184,7 +184,8 @@ vector<complex<double>> makeS(fft_param *fp){
vector<complex<double>> s(n); //Vektor zum speichern von s
for(int k=0;k<n;k++){
t=tmin+k*h;
if (t-tl >= 0 && t-tl <= tmax){
//TODO s ist nicht geschiftet
if (t >= 0 && t <= fp->signalLenght){
s[k]=sin(2*M_PI*alpha*(t-tl)); //s berechnen
}
@ -201,16 +202,22 @@ vector<complex<double>> makeE(fft_param *fp){
double tmin=fp->tmin;
double t;
double beta=fp->beta;
double alpha=fp->alpha;
double tl=fp->tl;
double a=fp->a;
double b=fp->b;
int n=fp->n;
vector<complex<double>> e(n); //Vektor zum speichern von e
vector<complex<double>> s=makeS(fp); //Vektor s wird benötigt
//vector<complex<double>> s=makeS(fp); //Vektor s wird benötigt
//FILE *fp3 = fopen("H10_2_30.txt" ,"w");
for(int k=0;k<n;k++){
t=tmin+k*h;
e[k]=b*sin(2*M_PI*beta*t)+ 2*a*(genrand_res53()-0.5)+s[k]; //e berechnen
e[k]=b*sin(2*M_PI*beta*t)+ 2*a*(genrand_res53()-0.5); //e berechnen
if (t-tl >= 0 && t-tl <= fp->signalLenght){
e[k]+=sin(2*M_PI*alpha*(t-tl)); //s berechnen
}
//fprintf(fp3,"%f\t%f\n",t,pow(e[k].real(),2));
//printf("%f\t%f\n",t,pow(e[k].real(),2));
//printf("%f\t%f\t%f\n",t,e[k].real(),e[k].imag());
@ -239,6 +246,12 @@ vector<complex<double>> aufgabe3 (fft_param *fp){
fft_param fps=*fp; //Sign im struct ändern
fps.sign=-1;
vector<complex<double>> FFFes=fourierTrafo(&fps, FFes); //Rücktransformation des Produkts
FILE *fpPlot =fopen("esPlot.csv","w");
for(int k = 0; k<n; k++){
fprintf(fpPlot, "%f\t%f\t%f\n", tmin+k*h, s[k].real(), e[k].real());
}
return FFFes;
//init_genrand((long)seed);
}
@ -249,9 +262,9 @@ void plotAufgabe3(fft_param *fp){
vector<complex<double>> es = aufgabe3(fp);
FILE *fp4 =fopen("es4.csv","w");
for (int k=0;k<n;k++){
printf("%f\n", norm(es[k]));
//printf("%f\n", norm(es[k]));
fprintf(fp4,"%f\t%f\n", tmin+k*h, norm(es[k]));
fprintf(fp4,"%f\t%f\n", tmin+k*h, norm(es[k]/(double)N));
}
@ -271,7 +284,8 @@ int main(){
fp.beta=1;
fp.a=0.5;
fp.b=0.50;
fp.tl=5;
fp.tl=50;
fp.signalLenght = 5;
//test(&fp);
plotAufgabe3(&fp);
//printf("%f\n",genrand_res53());

Loading…
Cancel
Save