From 798f1fde0a2542577f994aed7c7191008b72c37f Mon Sep 17 00:00:00 2001 From: pauline Date: Fri, 10 Jul 2020 15:02:06 +0200 Subject: [PATCH] Klappt wohl --- abgabe6nochmal.cpp | 48 +++++++++++++++++++++++++++------------------- 1 file changed, 28 insertions(+), 20 deletions(-) diff --git a/abgabe6nochmal.cpp b/abgabe6nochmal.cpp index 763310e..e067a50 100644 --- a/abgabe6nochmal.cpp +++ b/abgabe6nochmal.cpp @@ -4,7 +4,6 @@ #include #include #include -> #include using namespace std; #ifndef M_PI @@ -13,14 +12,16 @@ using namespace std; typedef struct { long N; double b, a, beta, alpha; - double tmin, tmax,h; + double tmin, tmax,h,tl; int m; int sign; } fft_param; complex expo(fft_param *fp,int k) { int sign = fp->sign; - return exp(sign*2 * M_PI * 1i / ((double) k)); + int N=fp->N; + return exp(sign*2.0 * M_PI * 1i* ((double)(k/N))); + } vector> fourierTrafo(fft_param *fp, vector> x) { @@ -38,13 +39,19 @@ vector> fourierTrafo(fft_param *fp, vector> x) { ungerPkt[k] = x[2 * k + 1]; } - vector> ftger(N / 2) = fourierTrafo(fp, gerPkt); //??????????????????????? - vector> ftunger(N / 2) = fourierTrafo(fp, ungerPkt); //??????????????????? + vector> ftger = fourierTrafo(fp, gerPkt); + vector> ftunger = fourierTrafo(fp, ungerPkt); vector> out(N); for (int k = 0; k < N / 2; k++) { - out[k] = (ftger[k] + ftunger[k] * expo(fp,k))/(double)N; - out[k + N / 2] = (ftger[k] - ftunger[k] *expo(fp,k))/(double)N; + if(sign==-1){ + out[k] = (ftger[k] + ftunger[k] * expo(fp,k)); + out[k + N / 2] = (ftger[k] - ftunger[k] *expo(fp,k)); + } + else{ + out[k] = (ftger[k] + ftunger[k] * expo(fp,k)); + out[k + N / 2] = (ftger[k] - ftunger[k] *expo(fp,k)); + } } return out; @@ -60,15 +67,15 @@ vector> test(fft_param *fp){ vector> x(N); for(int k=0;k> out = fourierTrafo(fp, x); fft_param n= *fp; n.sign=-1; vector> doppelout = fourierTrafo(&n, out); - FILE *fp2 = fopen("testFFT.csv" ,'w'); + FILE *fp2 = fopen("testFFT.csv" ,"w"); for(int k=0;k> makeS(fft_param *fp){ double tmin=0; double t; double tl=fp->tl; - double alpha=f->alpha; + double alpha=fp->alpha; int N=fp->N; vector> s(N); for(int k=0;k> makeE(fft_param *fp){ double tmax=fp->tmax; double tmin=0; double t; - double beta=f->beta; + double beta=fp->beta; double tl=fp->tl; double a=fp->a; double b=fp->b; @@ -102,7 +109,8 @@ vector> makeE(fft_param *fp){ vector> s=makeS(fp); for(int k=0;k> aufgabe3 (fft_param *fp){ double tmax=fp->tmax; double t=tmin; int N=fp->N; - vector> e(N)=makeE; - vector> s(N)=makeS(fp); - vector> Fe=fourierTrafo(fp,e); + vector> e=makeE(fp); + vector> s=makeS(fp); + vector> Fe=fourierTrafo(fp,e); fft_param fps=*fp; fps.sign=-1; - vector> Fs=fourierTrafo(&fps,s); - vector> FFes(N); + vector> Fs=fourierTrafo(&fps,s); + vector> FFes(N); for(int k=0;k> FFFes(N)=fourierTrafo(fp, FFes); + vector> FFFes=fourierTrafo(fp, FFes); return FFFes; } -double main(){ +int main(){ fft_param fp; fp.N= pow(2,13); fp.tmin=0;