private void button3_Click(object sender, EventArgs e) // Обратное преобразование Фурье 2**M { k1 = Convert.ToInt32(textBox4.Text); k2 = Convert.ToInt32(textBox5.Text); if (Form1.zComplex[k1] == null) { MessageBox.Show("zComplex[0] == NULL"); return; } int m = 1; int n = Form1.zComplex[k1].width; int nn = 2; for (int i = 1; ; i++) { nn = nn * 2; if (nn > n) { n = nn / 2; m = i; break; } } MessageBox.Show("n = " + Convert.ToString(n) + " m = " + Convert.ToString(m)); ZComplexDescriptor rez = new ZComplexDescriptor(n, n); rez = Furie.InverseFourierTransform(Form1.zComplex[k1], m); Form1.zComplex[k2] = rez; Complex_pictureBox(k2); //OnFurieM(k1, k2); Close(); }
/// <summary> /// Добавление нулей по строкам /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void button8_Click(object sender, EventArgs e) { n0 = Convert.ToInt32(textBox1.Text); k1 = Convert.ToInt32(textBox2.Text); k2 = Convert.ToInt32(textBox3.Text); int nx = Form1.zComplex[k1 - 1].width; int ny = Form1.zComplex[k1 - 1].height; int n = n0 + 1; int nx2 = n * nx; ZComplexDescriptor rez = new ZComplexDescriptor(nx2, ny); for (int i = 0; i < nx2; i += n) { for (int j = 0; j < ny; j++) { rez.array[i, j] = Form1.zComplex[k1 - 1].array[i / n, j]; } } Form1.zComplex[k2 - 1] = rez; VisualComplex(k2 - 1); }
// Отличается от предыдущего тем, что массивы 0,1,2,3 (а не 8,9,10,11) public static ZComplexDescriptor ATAN_ar(ZArrayDescriptor[] zArrayPicture, double[] fzz, double amplit = 255) { int w1 = zArrayPicture[0].width; int h1 = zArrayPicture[0].height; //MessageBox.Show(" ATAN_ar w1 " + w1+ " w1 "+ h1); ZComplexDescriptor faza = new ZComplexDescriptor(w1, h1); int n_sdv = 4; // Число фазовых сдвигов double[] i_sdv = new double[4]; double[] k_sin = new double[4]; double[] k_cos = new double[4]; for (int i = 0; i < n_sdv; i++) { k_sin[i] = Math.Sin(fzz[i]); k_cos[i] = Math.Cos(fzz[i]); } //ZArrayDescriptor amp = new ZArrayDescriptor(zArrayPicture[1 * 4 + 2]); //ZArrayDescriptor ampf = new ZArrayDescriptor(zArrayPicture[1 * 4 + 3]); for (int i = 0; i < w1; i++) { for (int j = 0; j < h1; j++) { i_sdv[0] = zArrayPicture[0].array[i, j]; i_sdv[1] = zArrayPicture[1].array[i, j]; i_sdv[2] = zArrayPicture[2].array[i, j]; i_sdv[3] = zArrayPicture[3].array[i, j]; double[] v_sdv = Vector_orto(i_sdv); // ------ Формула расшифровки фазы double fz1 = Vector_Mul(v_sdv, k_sin); double fz2 = Vector_Mul(v_sdv, k_cos); double a = Math.Atan2(fz1, fz2); double[] cos_orto = Vector_orto(k_cos); // ------ Формула расшифровки амплитуды double znmt = Vector_Mul(cos_orto, k_sin); double am = Math.Sqrt(fz1 * fz1 + fz2 * fz2) / Math.Abs(znmt); //am = am / (2 * amplit); //a= ampf.array[i, j]; // am = amp.array[i, j]; //am = 255; faza.array[i, j] = Complex.FromPolarCoordinates(am, a); } } return(faza); }
public static ZComplexDescriptor Exponenta(double g, int N) { ZComplexDescriptor cmpl = new ZComplexDescriptor(N, 256); double kx = 2 * Math.PI * g / N; double am = 1; for (int i = 0; i < N; i++) { for (int j = 0; j < 256; j++) { double fz = -kx * i; cmpl.array[i, j] = Complex.FromPolarCoordinates(am, fz); } } return(cmpl); }
/// <summary> /// Быстрое преобразование PSI для четырех сдвигов /// </summary> /// <param name="zArrayPicture"></param> /// <param name="progressBar1"></param> /// <param name="fzz"></param> /// <param name="amplit"></param> /// <returns></returns> public static ZArrayDescriptor ATAN_quick(ZArrayDescriptor[] zArrayDescriptor, ProgressBar progressBar1, double[] fzz, double xmax, double lambda, double d, double amplit) { // 8, 9, 10, 11 -> Complex[1] int w1 = zArrayDescriptor[8].width; int h1 = zArrayDescriptor[8].height; System.Diagnostics.Stopwatch sw = new Stopwatch(); sw.Start(); //MessageBox.Show("width= " + w1 + "height= " + h1); ZComplexDescriptor zComplex_rab = new ZComplexDescriptor(w1, h1); /* * double i_sdv1; //PSI * double i_sdv2; * double i_sdv3; * double i_sdv4; * //double[] i_s = new double[w1]; // Числитель * //double[] i_c = new double[w1]; // Знаменатель * * double k_sin1 = Math.Sin(fzz[0]); * double k_sin2 = Math.Sin(fzz[1]); * double k_sin3 = Math.Sin(fzz[2]); * double k_sin4 = Math.Sin(fzz[3]); * * double k_cos1 = Math.Cos(fzz[0]); * double k_cos2 = Math.Cos(fzz[1]); * double k_cos3 = Math.Cos(fzz[2]); * double k_cos4 = Math.Cos(fzz[3]); * * //double znmt = Math.Abs((k_sin2 - k_sin4) * k_cos1 + (k_sin3 - k_sin1) * k_cos2 + (k_sin4 - k_sin2) * k_cos3 + (k_sin1 - k_sin3) * k_cos4); * double znmt = Math.Abs((k_cos2 - k_cos4) * k_sin1 + (k_cos3 - k_cos1) * k_sin2 + (k_cos4 - k_cos2) * k_sin3 + (k_cos1 - k_cos3) * k_sin4); * znmt = znmt * (2 * amplit); * * progressBar1.Visible = true; * progressBar1.Minimum = 1; * progressBar1.Maximum = w1 - 1; * progressBar1.Value = 1; * progressBar1.Step = 1; * * * * * for (int j = 0; j < h1; j++) * { * for (int i = 0; i < w1; i++) * { * i_sdv1 = zArrayDescriptor[8].array[i, j]; * i_sdv2 = zArrayDescriptor[9].array[i, j]; * i_sdv3 = zArrayDescriptor[10].array[i, j]; * i_sdv4 = zArrayDescriptor[11].array[i, j]; * * double i1 = i_sdv2 - i_sdv4; * double i2 = i_sdv3 - i_sdv1; * double i3 = i_sdv4 - i_sdv2; * double i4 = i_sdv1 - i_sdv3; * * double i_s = i1 * k_sin1 + i2 * k_sin2 + i3 * k_sin3 + i4 * k_sin4; * double i_c = i1 * k_cos1 + i2 * k_sin2 + i3 * k_sin3 + i4 * k_sin4; * * double faza = Math.Atan2(i_c, i_s); // Фаза * //double faza = Math.Atan2(i_s, i_c); * double am = Math.Sqrt(i_s * i_s + i_c * i_c) / znmt; // Амплитуда * * zComplex_rab.array[i, j] = Complex.FromPolarCoordinates(am, faza); * * } * progressBar1.PerformStep(); * } * progressBar1.Value = 1; */ zComplex_rab = ATAN_PSI.ATAN_891011(zArrayDescriptor, progressBar1, fzz, amplit); // PSI //zComplex[1] = zComplex_rab; ZArrayDescriptor zArrayPicture = new ZArrayDescriptor(w1, h1); zComplex_rab = FurieN.FrenelTransformN(zComplex_rab, lambda, d, xmax); // Преобразование Френеля с четным количеством точек for (int i = 0; i < w1; i++) // Амплитуду в главное окно { for (int j = 0; j < h1; j++) { zArrayPicture.array[i, j] = zComplex_rab.array[i, j].Magnitude; } } zArrayPicture = Furie.Invers_Double(zArrayPicture); sw.Stop(); TimeSpan ts = sw.Elapsed; MessageBox.Show("PSI+Frenel Время Минут: " + ts.Minutes + " Время сек: " + ts.Seconds + " Время миллисек: " + ts.Milliseconds); //MessageBox.Show(" Lambda= " + lambda + " d= " + d + " dx= " + xmax); return(zArrayPicture); }
public static ZComplexDescriptor ATAN_8_11(int k1, int k2, int k3, int k4, ZArrayDescriptor[] zArrayPicture, double[] fzz, double amplit = 255) { // 8, 9, 10, 11 -> Complex[1] int w1 = zArrayPicture[k1].width; int h1 = zArrayPicture[k1].height; // MessageBox.Show("width= " + w1 + "height= " + h1); ZComplexDescriptor faza = new ZComplexDescriptor(w1, h1); int n_sdv = 4; // Число фазовых сдвигов double[] i_sdv = new double[4]; double[] k_sin = new double[4]; double[] k_cos = new double[4]; for (int i = 0; i < n_sdv; i++) { k_sin[i] = Math.Sin(fzz[i]); k_cos[i] = Math.Cos(fzz[i]); } double[] sin_orto = Vector_orto(k_sin); // Ортогональные вектора double[] cos_orto = Vector_orto(k_cos); double znmt = Math.Abs(Vector_Mul(sin_orto, k_cos)); //ZArrayDescriptor amp = new ZArrayDescriptor(zArrayPicture[1 * 4 + 2]); //ZArrayDescriptor ampf = new ZArrayDescriptor(zArrayPicture[1 * 4 + 3]); for (int i = 0; i < w1; i++) { for (int j = 0; j < h1; j++) { i_sdv[0] = zArrayPicture[k1].array[i, j]; i_sdv[1] = zArrayPicture[k2].array[i, j]; i_sdv[2] = zArrayPicture[k3].array[i, j]; i_sdv[3] = zArrayPicture[k4].array[i, j]; //double[] v_sdv = Vector_orto(i_sdv); // ------ Формула расшифровки фазы //double fz1 = Vector_Mul(v_sdv, k_sin); //double fz2 = Vector_Mul(v_sdv, k_cos); double fz1 = Vector_Mul(i_sdv, sin_orto); double fz2 = Vector_Mul(i_sdv, cos_orto); double a = Math.Atan2(fz2, fz1); //double[] cos_orto = Vector_orto(k_cos); // ------ Формула расшифровки амплитуды //double znmt = Vector_Mul(sin_orto, k_cos); double am = Math.Sqrt(fz1 * fz1 + fz2 * fz2) / znmt; //am = am / (2 * amplit); //a= ampf.array[i, j]; // am = amp.array[i, j]; //am = 255; faza.array[i, j] = Complex.FromPolarCoordinates(am, a); } } return(faza); }
// Определение амплитуды и фазы по 4 картинам (PSI), записанным в 9, 10, 11, и 12 окнах public static ZComplexDescriptor ATAN_891011(ZArrayDescriptor[] zArrayPicture, ProgressBar progressBar1, double[] fzz, double amplit = 0.5) { // 8, 9, 10, 11 -> Complex[1] int w1 = zArrayPicture[8].width; int h1 = zArrayPicture[8].height; // MessageBox.Show("width= " + w1 + "height= " + h1); //MessageBox.Show("fzz[i]= " + fzz[0] + " " + fzz[1] + " " + fzz[2] + " " + fzz[3]); //double Ar = SumClass.getAverage(zArrayPicture[8]); double Ar = amplit; ZComplexDescriptor faza = new ZComplexDescriptor(w1, h1); int n_sdv = 4; // Число фазовых сдвигов double[] i_sdv = new double[4]; double[] k_sin = new double[4]; double[] k_cos = new double[4]; for (int i = 0; i < n_sdv; i++) { k_sin[i] = Math.Sin(fzz[i]); k_cos[i] = Math.Cos(fzz[i]); } double[] sin_orto = Vector_orto(k_sin); // Ортогональные вектора double[] cos_orto = Vector_orto(k_cos); double znmt = Math.Abs(Vector_Mul(k_cos, sin_orto)); //ZArrayDescriptor amp = new ZArrayDescriptor(zArrayPicture[1 * 4 + 2]); //ZArrayDescriptor ampf = new ZArrayDescriptor(zArrayPicture[1 * 4 + 3]); progressBar1.Visible = true; progressBar1.Minimum = 1; progressBar1.Maximum = w1 - 1; progressBar1.Value = 1; progressBar1.Step = 1; for (int i = 0; i < w1; i++) { for (int j = 0; j < h1; j++) { i_sdv[0] = zArrayPicture[8].array[i, j]; i_sdv[1] = zArrayPicture[9].array[i, j]; i_sdv[2] = zArrayPicture[10].array[i, j]; i_sdv[3] = zArrayPicture[11].array[i, j]; double[] i_sdv_orto = Vector_orto(i_sdv); // Ортогональные вектора double[] v_sdv = Vector_orto(i_sdv); // ------ Формула расшифровки фазы double fz1 = Vector_Mul(v_sdv, k_sin); double fz2 = Vector_Mul(v_sdv, k_cos); //double fz1 = Vector_Mul(i_sdv, sin_orto); //double fz2 = Vector_Mul(i_sdv, cos_orto);] double f = Math.Atan2(fz2, fz1); //double[] cos_orto = Vector_orto(k_cos); // ------ Формула расшифровки амплитуды //double znmt = Vector_Mul(sin_orto, k_cos); double am = Math.Sqrt(fz1 * fz1 + fz2 * fz2) / znmt; //am = am / (2 * amplit); am = am / (2 * Ar); faza.array[i, j] = Complex.FromPolarCoordinates(am, f); } progressBar1.PerformStep(); } progressBar1.Value = 1; return(faza); }