//---------------------------------------------------------------------------------------------- // Двухмерное быстрое преобразование Фурье с произвольным числом точек (Четное число) //---------------------------------------------------------------------------------------------- public static ZComplexDescriptor BPF2_Line(ZComplexDescriptor zarray) // По строкам { int nx = zarray.width; int ny = zarray.height; // int nx = 5120; // int ny = 3328; ZComplexDescriptor resultArray = new ZComplexDescriptor(nx, ny); // ---------------------------------------------------------- По строкам if (nx % 2 != 0) { nx = nx - 1; // n - должно быть четным } int m = M(nx); // Определение нечетного делителя числа int l = L(nx); // Определение четного делителя числа int t = T(l); // Определение показателя степени l = 2**t Complex[] array_exp = new Complex[t + 1]; // Экспонента для BPF array_exp = P_EXP(t + 1); int[] array_inv = Invers(t, nx); // Инверсия элементов массива для БПФ Complex[] Array = new Complex[nx]; // Выходной массив int n = Convert.ToInt32(Math.Pow(2.0, t)); if (n == nx) // N=2**t { for (int j = 0; j < ny; j++) // --------------------------------------------------Обычное BPF { for (int i = 0; i < nx; i++) { Array[i] = zarray.array[i, j]; } Array = BPF_Q(Array, t, array_exp, array_inv); for (int i = 0; i < nx; i++) { resultArray.array[i, j] = Array[i]; } } } else // ---------------------------------------------------Для произвольного числа точек { Complex[,] array_exp2 = new Complex[nx, m]; // Экспонента для второго прохода array_exp2 = P_EXP2(nx, m, l); for (int j = 0; j < ny; j++) { for (int i = 0; i < nx; i++) { Array[i] = zarray.array[i, j]; } Array = BPF_N(Array, nx, m, l, t, array_exp, array_exp2, array_inv); for (int i = 0; i < nx; i++) { resultArray.array[i, j] = Array[i]; } } } return(resultArray); }
public static ZComplexDescriptor ATAN_OLD4(ZArrayDescriptor[] zArrayPicture, double[] fzz) { // 8, 9, 10, 11 -> Complex[1] int w1 = zArrayPicture[8].width; int h1 = zArrayPicture[8].height; ZComplexDescriptor faza = new ZComplexDescriptor(w1, h1); for (int i = 0; i < w1; i++) { for (int j = 0; j < h1; j++) { double i1 = zArrayPicture[8].array[i, j]; // 0 double i2 = zArrayPicture[9].array[i, j]; // 90 double i3 = zArrayPicture[10].array[i, j]; // 180 double i4 = zArrayPicture[11].array[i, j]; // 270 // ------ Формула расшифровки faza.array[i, j] = new Complex(i1 - i2, i2 - i4); } } return(faza); }
// dx микрометрах // Углы в радианах public static ZComplexDescriptor Model_pl(double am, double AngleX, double AngleY, double Lambda, int NX, int NY, double dx) { ZComplexDescriptor cmpl = new ZComplexDescriptor(NX, NY); // Первый фронт перпендикулярный к плоскости наблюдения ZComplexDescriptor cmpl1 = new ZComplexDescriptor(NX, NY); // Второй фронт double kx = dx / NX; double ky = dx / NY; for (int i = 0; i < NX; i++) { for (int j = 0; j < NY; j++) { cmpl.array[i, j] = new Complex(am, 0.0); cmpl1.array[i, j] = Complex.FromPolarCoordinates(am, 2 * Math.PI * (Math.Sin(AngleX) * kx * i + Math.Sin(AngleY) * ky * j) / Lambda); } } for (int i = 0; i < NX; i++) { for (int j = 0; j < NY; j++) { cmpl.array[i, j] += cmpl1.array[i, j]; } } return(cmpl); }
// // Добавление фазового сдвига fz и получение голограммы // public static ZArrayDescriptor Model_pl_PSI(double am, ZComplexDescriptor cmpl0, double AngleX, double AngleY, double Lambda, double dx, double noise, double fz) { int NX = cmpl0.width; int NY = cmpl0.height; double kx = dx / NX; double ky = dx / NY; ZArrayDescriptor cmpl = new ZArrayDescriptor(NX, NY); // Результирующий фронт am = SumClass.getAverage(cmpl0); // Амплитуда опорного пучка равна средней амплитуды объектного //MessageBox.Show("am = " + am + " fz= " + fz); Random rnd = new Random((int)DateTime.Now.Ticks & 0x0000FFFF); for (int i = 0; i < NX; i++) { for (int j = 0; j < NY; j++) { double fz1 = 2 * Math.PI * (Math.Sin(AngleX) * kx * i + Math.Sin(AngleY) * ky * j) / Lambda; double fa = rnd.NextDouble() * 2.0 * Math.PI - Math.PI; double f0 = fz1 + fa * noise + fz; double Ap = cmpl0.array[i, j].Magnitude; // амплитуда объектного пучка double Fp = cmpl0.array[i, j].Phase; // Фаза объектного пучка cmpl.array[i, j] = Ap * Ap + am * am + 2 * Ap * am * Math.Cos(Fp - f0); // Интенсивность } } return(cmpl); }
// Сложение с плоской волной => интенсивность в центральное окно public static ZArrayDescriptor Model_pl_ADD_I(double am, ZComplexDescriptor cmpl0, double AngleX, double AngleY, double Lambda, double dx, double noise, double fzr) { MessageBox.Show("am = " + am); int NX = cmpl0.width; int NY = cmpl0.height; //ZComplexDescriptor cmpl1 = new ZComplexDescriptor(NX, NY); // Фронт под углом AngleX, AngleY ZArrayDescriptor cmpl = new ZArrayDescriptor(NX, NY); // Результирующая интенсивность double kx = dx / NX; double ky = dx / NY; // a = (a - min) * 2.0 * Math.PI / (max - min); -pi +pi //am = SumClass.getAverage(cmpl0); // Средняя интенсивность комплексного массива Random rnd = new Random((int)DateTime.Now.Ticks & 0x0000FFFF); for (int i = 0; i < NX; i++) { for (int j = 0; j < NY; j++) { double fz = 2 * Math.PI * (Math.Sin(AngleX) * kx * i + Math.Sin(AngleY) * ky * j) / Lambda; double fa = rnd.NextDouble() * 2.0 * Math.PI - Math.PI; double f0 = fz + fa * noise + fzr; //Complex Pl = Complex.FromPolarCoordinates(am, f0); //cmpl.array[i, j] = cmpl0.array[i, j] + Pl; double a = cmpl0.array[i, j].Magnitude; double f = cmpl0.array[i, j].Phase; cmpl.array[i, j] = a * a + am * am + 2 * a * am * Math.Cos(f - f0); } } cmpl = SumClass.Range_Array1(cmpl, am); // Приведение к диапазону от 0 до am return(cmpl); }
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// // Интерференция сферических волн ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// public static ZComplexDescriptor Model_Sp(double am, double Lambda, int NX, int NY, double dx, double d) { ZComplexDescriptor cmpl1 = new ZComplexDescriptor(NX, NY); // Второй фронт double kx = dx / NX; double ky = dx / NY; for (int i = 0; i < NX; i++) { for (int j = 0; j < NY; j++) { int i1 = i - NX / 2; int j1 = j - NY / 2; double x2 = kx * kx * i1 * i1; double y2 = ky * ky * j1 * j1; double sqr1 = Math.Sqrt(x2 + y2 + d * d); // cmpl.array[i, j] = new Complex(am , 0.0); //cmpl1.array[i, j] = Complex.FromPolarCoordinates(am / sqr1, 2 * Math.PI * sqr1 / Lambda); double c = am * Math.Cos(2 * Math.PI * sqr1 / Lambda + Math.PI) / sqr1; double s = -am *Math.Sin(2 *Math.PI *sqr1 / Lambda + Math.PI) / sqr1;; cmpl1.array[i, j] = new Complex(c, s); } } cmpl1.array[NX / 2, NY / 2] = cmpl1.array[NX / 2 - 1, NY / 2 - 1]; return(cmpl1); }
// // Умножение на фазовый фронт // public static ZComplexDescriptor Model_pl_MUL(double am, ZComplexDescriptor cmpl0, double AngleX, double AngleY, double Lambda, double dx, double fz = 0) { int NX = cmpl0.width; int NY = cmpl0.height; am = 1; //ZComplexDescriptor cmpl1 = new ZComplexDescriptor(NX, NY); // Фронт под углом AngleX, AngleY ZComplexDescriptor cmpl = new ZComplexDescriptor(NX, NY); // Результирующий фронт double kx = dx / NX; double ky = dx / NY; // a = (a - min) * 2.0 * Math.PI / (max - min); -pi +pi for (int i = 0; i < NX; i++) { for (int j = 0; j < NY; j++) { Complex a = Complex.FromPolarCoordinates(am, 2 * Math.PI * (Math.Sin(AngleX) * kx * i + Math.Sin(AngleY) * ky * j) / Lambda + fz); cmpl.array[i, j] = cmpl0.array[i, j] * a; } } return(cmpl); }
// Параксиальное приближение (Гауссов пучок) public static ZComplexDescriptor Model_Sp1(double am, double Lambda, int NX, int NY, double dx, double d) { ZComplexDescriptor cmpl1 = new ZComplexDescriptor(NX, NY); // Второй фронт double kx = dx / (NX); double ky = dx / (NY); for (int i = 0; i < NX; i++) { for (int j = 0; j < NY; j++) { int i1 = i - NX / 2; int j1 = j - NY / 2; double x2 = kx * kx * i1 * i1; double y2 = ky * ky * j1 * j1; double sqr1 = x2 + y2; double c = am * Math.Cos(Math.PI * sqr1 / (Lambda * d) + Math.PI); double s = -am *Math.Sin(Math.PI *sqr1 / (Lambda *d) + Math.PI); cmpl1.array[i, j] = new Complex(c, s); } } cmpl1.array[NX / 2, NY / 2] = cmpl1.array[NX / 2 - 1, NY / 2 - 1]; return(cmpl1); }
public static ZComplexDescriptor Model_pl_ADD(double am, ZComplexDescriptor cmpl0, double AngleX, double AngleY, double Lambda, double dx, double noise) { int NX = cmpl0.width; int NY = cmpl0.height; //ZComplexDescriptor cmpl1 = new ZComplexDescriptor(NX, NY); // Фронт под углом AngleX, AngleY ZComplexDescriptor cmpl = new ZComplexDescriptor(NX, NY); // Результирующий фронт double kx = dx / NX; double ky = dx / NY; // a = (a - min) * 2.0 * Math.PI / (max - min); -pi +pi Random rnd = new Random((int)DateTime.Now.Ticks & 0x0000FFFF); for (int i = 0; i < NX; i++) { for (int j = 0; j < NY; j++) { double fz = 2 * Math.PI * (Math.Sin(AngleX) * kx * i + Math.Sin(AngleY) * ky * j) / Lambda; double fa = rnd.NextDouble() * 2.0 * Math.PI - Math.PI; Complex a = Complex.FromPolarCoordinates(am, fz + fa * noise); cmpl.array[i, j] = cmpl0.array[i, j] + a; } } return(cmpl); }
// -------------------------------------------------------------------------------------------------------------------------- public static void saveZComplex(ZComplexDescriptor arrayDescriptor) { SaveFileDialog saveFileDialog = new SaveFileDialog(); saveFileDialog.Filter = "complex files (*.zcmp)|*.zcmp|All files (*.*)|*.*"; saveFileDialog.FilterIndex = 1; saveFileDialog.RestoreDirectory = true; if (saveFileDialog.ShowDialog() == DialogResult.OK) { try { Stream stream; if ((stream = saveFileDialog.OpenFile()) != null) { BinaryFormatter serializer = new BinaryFormatter(); serializer.Serialize(stream, arrayDescriptor); stream.Close(); } } catch (Exception ex) { System.Windows.Forms.MessageBox.Show("Ошибка при записи файла complex : " + ex.Message); } } }
public static ZComplexDescriptor loadZComplex() { OpenFileDialog openFileDialog = new OpenFileDialog(); openFileDialog.Filter = "array files (*.zcmp)|*.zcmp|All files (*.*)|*.*"; openFileDialog.FilterIndex = 1; openFileDialog.RestoreDirectory = true; if (openFileDialog.ShowDialog() == DialogResult.OK) { try { Stream myStream; if ((myStream = openFileDialog.OpenFile()) != null) { using (myStream) { BinaryFormatter deserializer = new BinaryFormatter(); ZComplexDescriptor savedArray = (ZComplexDescriptor)deserializer.Deserialize(myStream); myStream.Close(); return(savedArray); } } } catch (Exception ex) { System.Windows.Forms.MessageBox.Show("Ошибка при чтении файла double :" + ex.Message); return(null); } } return(null); }
public static void Mul_C(int k3, int k4, int k5, ProgressBar progressBar1) // Умножить два комплексных массива { k3--; k4--; k5--; // Массив 1 -> 0 //MessageBox.Show("k3= " + k3 + " - k4= " + k4 + " = k5= " + k5); if (Form1.zComplex[k3] == null) { MessageBox.Show("Mul_C zComplex[" + k3 + "] == NULL"); return; } if (Form1.zComplex[k4] == null) { MessageBox.Show("Mul_C zComplex[" + k4 + "] == NULL"); return; } int nx = Form1.zComplex[k3].width; int ny = Form1.zComplex[k3].height; int nx1 = Form1.zComplex[k4].width; int ny1 = Form1.zComplex[k4].height; if ((nx != nx1) || (ny != ny1)) { MessageBox.Show("Mul_C Размеры массивов не согласованы"); return; } //ZComplexDescriptor a = new ZComplexDescriptor(nx, nx); // Результирующая матрица ZComplexDescriptor b = new ZComplexDescriptor(nx, ny); for (int i = 0; i < nx; i++) // Транспонирование второго массива { for (int j = 0; j < ny; j++) { b.array[i, j] = Form1.zComplex[k3].array[i, j] * Form1.zComplex[k4].array[i, j]; } } /* * progressBar1.Visible = true; * progressBar1.Minimum = 1; * progressBar1.Maximum = nx; * progressBar1.Value = 1; * progressBar1.Step = 1; * * Complex s0 = new Complex(0, 0); * for (int i = 0; i < nx; i++) * { * for (int j = 0; j < ny; j++) * { * Form1.zComplex[k3].array[i, j]= b.array[j, i] * } * progressBar1.PerformStep(); * } * progressBar1.Value = 1; */ Form1.zComplex[k5] = b; ComplexPictureImage(k5); }
/// <summary> /// BPF от реального массива по строкам /// </summary> /// <param name="zarray"></param> /// <param name="sdvig"></param> Сдвиг /// <returns></returns> public static ZComplexDescriptor BPF_Real(ZArrayDescriptor zarray, int sdvig) { int nx = zarray.width; int ny = zarray.height; int m = 1; int nn = 2; for (int i = 1; ; i++) { nn = nn * 2; if (nn > nx) { m = i; break; } } int n = Convert.ToInt32(Math.Pow(2.0, m)); // N=2**m // MessageBox.Show("nx: " + nx + " m: " + m + " n: " + n); //Complex[] array_exp = P_EXP(m + 1); // Экспонента для BPF //int[] array_inv = Invers(m, nx); // Инверсия элементов массива для БПФ Complex[] Array = new Complex[n]; // Выходной массив Complex[] ArrayX = new Complex[n]; // Комплексный массив экспоненты сдвига for (int i = 0; i < n; i++) { double a = 2 * Math.PI * sdvig * i / n; ArrayX[i] = new Complex(Math.Cos(a), -Math.Sin(a)); } ZComplexDescriptor resultArray = new ZComplexDescriptor(n, ny); // Re=zArrayPicture Im=0 for (int j = 0; j < ny; j++) { for (int i = 0; i < n; i++) { Array[i] = new Complex(zarray.array[i, j], 0.0); } for (int i = 0; i < n; i++) { Array[i] = Array[i] * ArrayX[i]; } //Array = BPF_Q(Array, m, array_exp, array_inv); Array = Furie.GetFourierTransform(Array, m); for (int i = 0; i < n; i++) { resultArray.array[i, j] = Array[i]; } } return(resultArray); }
//---------------------------------------------------------------------------------------------- // Cuda Френель из k1 в k2 //---------------------------------------------------------------------------------------------- public static ZComplexDescriptor Fr_CUDA(ZComplexDescriptor zarray, double lambda, double d, double dx) { int nx = zarray.width; int ny = zarray.height; ZComplexDescriptor resultArray = new ZComplexDescriptor(nx, ny); Complex[] Array_с2x = FurieN.fexp2(lambda, d, nx, dx); // Умножение на экспоненту Complex[] Array_с2y = FurieN.fexp2(lambda, d, ny, dx); for (int j = 0; j < ny; j++) { for (int i = 0; i < nx; i++) { resultArray.array[i, j] = zarray.array[i, j] * Array_с2x[i] * Array_с2y[j]; } } //Array_с2 = FurieN.fexp2(lambda, d, ny, dx); //for (int i = 0; i < nx; i++) // for (int j = 0; j < ny; j++) resultArray.array[i, j] = resultArray.array[i, j] * Array_с2[j]; ComplexNumber[] Cud_array = ComplexMatrix.ToArrayByRows(resultArray); // Из двухмерного в одномерный -> Массив комплексных (Struct)чисел [nx*ny] ComplexNumber[] Cud_array1 = CUDA_FFT.CudaFFT(Cud_array, nx, ny); // БПФ int k = 0; for (int i = 0; i < nx; i++) // Из одномерного в двухмерный { for (int j = 0; j < ny; j++) { resultArray.array[i, j] = Complex.FromPolarCoordinates(Cud_array1[k].Real, Cud_array1[k].Imaginary); // Преобразование из одномерного в [ , ] k++; } } double[] phase_y = FurieN.fexp1(lambda, d, ny, dx); // Умножение на экспоненту double[] phase_x = FurieN.fexp1(lambda, d, nx, dx); for (int i = 0; i < nx; i++) { for (int j = 0; j < ny; j++) { resultArray.array[i, j] = Complex.FromPolarCoordinates(resultArray.array[i, j].Magnitude, resultArray.array[i, j].Phase + phase_y[j] + phase_x[i]); } } // phase = FurieN.fexp1(lambda, d, nx, dx); // for (int j = 0; j < ny; j++) // for (int i = 0; i < nx; i++) // { resultArray.array[i, j] = Complex.FromPolarCoordinates(resultArray.array[i, j].Magnitude, resultArray.array[i, j].Phase + phase[i]); } return(resultArray); }
//---------------------------------------------------------------------------------------------- // Циклический сдвиг Смещение изображения в центр //---------------------------------------------------------------------------------------------- public static ZComplexDescriptor Invers(ZComplexDescriptor zarray) { int nx = zarray.width; int ny = zarray.height; if (nx != ny) { MessageBox.Show("Invers nx != ny"); } Complex[] Array = new Complex[nx]; Complex[] Array1 = new Complex[nx]; ZComplexDescriptor resultArray = new ZComplexDescriptor(nx, ny); int n2 = nx / 2; for (int j = 0; j < ny; j++) { for (int i = 0; i < nx; i++) { Array[i] = zarray.array[i, j]; } for (int i = 0; i < n2; i++) { Array1[i] = Array[i + n2]; Array1[i + n2] = Array[i]; } for (int i = 0; i < nx; i++) { resultArray.array[i, j] = Array1[i]; } } for (int i = 0; i < nx; i++) { for (int j = 0; j < ny; j++) { Array[j] = resultArray.array[i, j]; } for (int j = 0; j < n2; j++) { Array1[j] = Array[j + n2]; Array1[j + n2] = Array[j]; } for (int j = 0; j < ny; j++) { resultArray.array[i, j] = Array1[j]; } } return(resultArray); }
public ComplexMatrix(ZComplexDescriptor ampl) { this.rowCount = ampl.width; this.columnCount = ampl.height; this.dataArray = new Complex[this.rowCount, this.columnCount]; for (int row = 0; row < rowCount; row++) { for (int column = 0; column < columnCount; column++) { this.dataArray[row, column] = Complex.FromPolarCoordinates(ampl.array[row, column].Magnitude, ampl.array[row, column].Phase); } } }
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// // Конструктор для заполения реальной части и мнимой части // k=0 Re // k=1 Im // k=2 re im=0 // value.Real, value.Imaginary public ZComplexDescriptor(ZArrayDescriptor descriptorToCopy, ZComplexDescriptor a, int k) { if (descriptorToCopy == null) { MessageBox.Show("ZArrayDescriptor == NULL"); return; } if (a == null) { MessageBox.Show("ZComplexDescriptor == NULL"); return; } width = a.width; height = a.height; int w1 = descriptorToCopy.width; int h1 = descriptorToCopy.height; MessageBox.Show("k= " + k + "width= " + width + "height = " + height + "w1 = " + w1 + "h1 = " + h1); if (w1 > width || h1 > height) { MessageBox.Show("ZComplexDescriptor.cs ZArrayDescriptor > ZComplexDescriptor"); return; } int x1 = (width - w1) / 2; int y1 = (height - h1) / 2; array = new Complex[width, height]; //MessageBox.Show("width =" + Convert.ToString(width) + "height =" + Convert.ToString(height)); for (int i1 = 0; i1 < w1; i1++) { for (int j1 = 0; j1 < h1; j1++) { int i = i1 + x1; int j = j1 + y1; //Double c = descriptorToCopy.array[i, j]; if (k == 0) { array[i, j] = new Complex(descriptorToCopy.array[i1, j1], a.array[i1, j1].Imaginary); } if (k != 0) { array[i, j] = new Complex(a.array[i1, j1].Real, descriptorToCopy.array[i1, j1]); } } } }
public static ZArrayDescriptor Re(ZComplexDescriptor zComplex) { int nx = zComplex.width; int ny = zComplex.height; ZArrayDescriptor amp1 = new ZArrayDescriptor(nx, ny); for (int i = 0; i < nx; i++) { for (int j = 0; j < ny; j++) { amp1.array[i, j] = zComplex.array[i, j].Real; } } return(amp1); }
//---------------------------------------------------------------------------------------------- // Двухмерное быстрое преобразование Фурье //---------------------------------------------------------------------------------------------- public static ZComplexDescriptor FourierTransform(ZComplexDescriptor zarray, int powerOfTwo) { int nx = zarray.width; int ny = zarray.height; Complex[] Array = new Complex[nx]; Complex[] Array1 = new Complex[nx]; ZComplexDescriptor resultArray = new ZComplexDescriptor(nx, ny); //for (int i = 0; i < nx; i++) Array[i] = new Complex(0.0, 0.0); //Complex[] Array_exp = new Complex[nx]; //for (int i = 0; i < nx; i++) Array_exp[i] = new Complex(Math.Cos(i * Math.PI ), -Math.Sin(i * Math.PI )); for (int j = 0; j < ny; j++) { //for (int i = 0; i < nx; i++) Array[i] = zarray.array[i, j] * Array_exp[i]; for (int i = 0; i < nx; i++) { Array[i] = zarray.array[i, j]; } Array1 = GetFourierTransform(Array, powerOfTwo); for (int i = 0; i < nx; i++) { resultArray.array[i, j] = Array1[i]; } } for (int i = 0; i < nx; i++) { //for (int j = 0; j < ny; j++) Array[j] = resultArray.array[i, j]*Array_exp[j]; for (int j = 0; j < ny; j++) { Array[j] = resultArray.array[i, j]; } Array1 = GetFourierTransform(Array, powerOfTwo); for (int j = 0; j < ny; j++) { resultArray.array[i, j] = Array1[j]; } } return(resultArray); }
//---------------------------------------------------------------------------------------------- // Двухмерное быстрое преобразование Френеля //---------------------------------------------------------------------------------------------- public static ZComplexDescriptor FrenelTransformN(ZComplexDescriptor zarray, double lambda, double d, double dx) { int nx = zarray.width; int ny = zarray.height; //if (nx != ny) { MessageBox.Show("Frenel nx != ny"); } ZComplexDescriptor resultArray = new ZComplexDescriptor(nx, ny); Complex[] Array_с2x = fexp2(lambda, d, nx, dx); Complex[] Array_с2y = fexp2(lambda, d, ny, dx); for (int j = 0; j < ny; j++) { for (int i = 0; i < nx; i++) { resultArray.array[i, j] = zarray.array[i, j] * Array_с2x[i] * Array_с2y[j]; } } // Array_с2 = fexp2(lambda, d, ny, dx); // for (int i = 0; i < nx; i++) // for (int j = 0; j < ny; j++) resultArray.array[i, j] = resultArray.array[i, j] * Array_с2[j]; resultArray = BPF2(resultArray); // Преобразование Фурье с произвольным количеством точек double[] phase_y = fexp1(lambda, d, ny, dx); double[] phase_x = fexp1(lambda, d, nx, dx); for (int i = 0; i < nx; i++) { for (int j = 0; j < ny; j++) { resultArray.array[i, j] = Complex.FromPolarCoordinates(resultArray.array[i, j].Magnitude, resultArray.array[i, j].Phase + phase_y[j] + phase_x[i]); } } // phase = fexp1(lambda, d, nx, dx); // for (int j = 0; j < ny; j++) // for (int i = 0; i < nx; i++) // { resultArray.array[i, j] = Complex.FromPolarCoordinates(resultArray.array[i, j].Magnitude, resultArray.array[i, j].Phase + phase[i]); } return(resultArray); }
public ZComplexDescriptor(ZComplexDescriptor descriptorToCopy) { if (descriptorToCopy == null) { return; } array = new Complex[descriptorToCopy.width, descriptorToCopy.height]; width = descriptorToCopy.width; height = descriptorToCopy.height; for (int i = 0; i < width; i++) { for (int j = 0; j < height; j++) { array[i, j] = descriptorToCopy.array[i, j]; } } }
public static double getAverage(ZComplexDescriptor newDescriptor) { if (newDescriptor == null) { return(0); } double a = 0; for (int i = 0; i < newDescriptor.width; i++) { for (int j = 0; j < newDescriptor.height; j++) { a = a + newDescriptor.array[i, j].Magnitude; } } a = a / (newDescriptor.width * newDescriptor.height); return(a); }
//---------------------------------------------------------------------------------------------- // Cuda FFT из главного окна из k1 в k2 //---------------------------------------------------------------------------------------------- public static ZComplexDescriptor Fur_CUDA1(ZComplexDescriptor zarray) // Прямое преобразование Фурье (CUDA) { int nx = zarray.width; int ny = zarray.height; ZComplexDescriptor resultArray = new ZComplexDescriptor(nx, ny); ComplexNumber[] Cud_array = ComplexMatrix.ToArrayByRows(zarray); // Из двухмерного в одномерный -> Массив комплексных (Struct)чисел [nx*ny] ComplexNumber[] Cud_array1 = CUDA_FFT.CudaFFT(Cud_array, nx, ny); int k = 0; for (int i = 0; i < nx; i++) { for (int j = 0; j < ny; j++) { resultArray.array[i, j] = Complex.FromPolarCoordinates(Cud_array1[k].Real, Cud_array1[k].Imaginary); // Преобразование из одномерного в [ , ] k++; } } return(resultArray); }
public static ZComplexDescriptor InverseFourierTransform(ZComplexDescriptor zarray, int powerOfTwo) { int nx = zarray.width; int ny = zarray.height; Complex[] Array = new Complex[nx]; Complex[] Array1 = new Complex[nx]; ZComplexDescriptor resultArray = new ZComplexDescriptor(nx, ny); for (int j = 0; j < ny; j++) { for (int i = 0; i < nx; i++) { Array[i] = zarray.array[i, j]; } Array1 = GetInverseFourierTransform(Array, powerOfTwo); for (int i = 0; i < nx; i++) { resultArray.array[i, j] = Array1[i]; } } for (int i = 0; i < nx; i++) { for (int j = 0; j < ny; j++) { Array[j] = resultArray.array[i, j]; } Array1 = GetInverseFourierTransform(Array, powerOfTwo); for (int j = 0; j < ny; j++) { resultArray.array[i, j] = Array1[j]; } } return(resultArray); }
public static void Add_C(int k3, int k4, int k5) // Сложить два комплексных массива { k3--; k4--; k5--; // Массив 1 -> 0 MessageBox.Show("k3= " + k3 + " - k4= " + k4 + " = k5= " + k5); if (Form1.zComplex[k3] == null) { MessageBox.Show("zComplex[" + k3 + "] == NULL"); return; } if (Form1.zComplex[k4] == null) { MessageBox.Show("zComplex[" + k4 + "] == NULL"); return; } int nx = Form1.zComplex[k3].width; int ny = Form1.zComplex[k3].height; int nx1 = Form1.zComplex[k4].width; int ny1 = Form1.zComplex[k4].height; if ((nx != nx1) || (ny != ny1)) { MessageBox.Show("Размеры массивов не равны"); return; } ZComplexDescriptor a = new ZComplexDescriptor(nx, ny); for (int i = 0; i < nx; i++) { for (int j = 0; j < ny; j++) { a.array[i, j] = Form1.zComplex[k3].array[i, j] + Form1.zComplex[k4].array[i, j]; } } //zComplex[k5] = new ZComplexDescriptor(nx, ny); Form1.zComplex[k5] = a; ComplexPictureImage(k5); }
public static void Diapazon_С(double a1, double a2) // Привести к диапазону комплексный кадр { if (Form1.zComplex[Form1.regComplex] == null) { MessageBox.Show("Diapazon zComplex[" + Form1.regComplex + "] == NULL"); return; } int nx = Form1.zComplex[Form1.regComplex].width; int ny = Form1.zComplex[Form1.regComplex].height; ZArrayDescriptor rez = new ZArrayDescriptor(nx, ny); for (int i = 0; i < nx; i++) { for (int j = 0; j < ny; j++) { rez.array[i, j] = Form1.zComplex[Form1.regComplex].array[i, j].Magnitude; } } double min = SumClass.getMin(rez); double max = SumClass.getMax(rez); for (int i = 0; i < nx; i++) { for (int j = 0; j < ny; j++) { double d = rez.array[i, j]; rez.array[i, j] = (d - min) * (a2 - a1) / (max - min) + a1; } } ZComplexDescriptor rezc = new ZComplexDescriptor(Form1.zComplex[Form1.regComplex], rez); // Амплитуда в rez, фаза старая Form1.zComplex[Form1.regComplex] = rezc; ComplexPictureImage(Form1.regComplex); }
public static void Div_C(int k3, int k4, int k5) // Разделить два комплексных массива поэлементно Form1.zComplex[k] { k3--; k4--; k5--; // Массив 1 -> 0 //MessageBox.Show("k3= " + k3 + " - k4= " + k4 + " = k5= " + k5); if (Form1.zComplex[k3] == null) { MessageBox.Show("zComplex[" + k3 + "] == NULL"); return; } if (Form1.zComplex[k4] == null) { MessageBox.Show("zComplex[" + k4 + "] == NULL"); return; } int nx = Form1.zComplex[k3].width; int ny = Form1.zComplex[k3].height; int nx1 = Form1.zComplex[k4].width; int ny1 = Form1.zComplex[k4].height; if ((nx != nx1) || (ny != ny1)) { MessageBox.Show("Размеры массивов не равны"); return; } ZComplexDescriptor a = new ZComplexDescriptor(nx, ny); for (int i = 0; i < nx; i++) { for (int j = 0; j < ny; j++) { a.array[i, j] = Div(Form1.zComplex[k3].array[i, j], Form1.zComplex[k4].array[i, j]); // a.array[i, j] = Complex.Divide( Form1.zComplex[k3].array[i, j] , Form1.zComplex[k4].array[i, j] ); } } Form1.zComplex[k5] = a; ComplexPictureImage(k5); }
public static void ROL_C(int k1) // Циклический сдвиг влево комплексных чисел { if (Form1.zComplex[Form1.regComplex] == null) { MessageBox.Show("ROR_C: zComplex[Form1.regImage] == NULL"); return; } int nx = Form1.zComplex[Form1.regComplex].width; int ny = Form1.zComplex[Form1.regComplex].height; ZComplexDescriptor zArray = new ZComplexDescriptor(nx, ny); for (int i = 0; i < nx - k1; i++) { for (int j = 0; j < ny; j++) { zArray.array[i, j] = Form1.zComplex[Form1.regComplex].array[k1 + i, j]; } } for (int i = k1; i > 0; i--) { for (int j = 0; j < ny; j++) { zArray.array[nx - i, j] = Form1.zComplex[Form1.regComplex].array[k1 - i, j]; } } for (int i = 0; i < nx; i++) { for (int j = 0; j < ny; j++) { Form1.zComplex[Form1.regComplex].array[i, j] = zArray.array[i, j]; } } //VisualRegImage(Form1.regImage); ComplexPictureImage(Form1.regComplex); }
public static ZComplexDescriptor ADD_PHASE(ZComplexDescriptor cmpl0, double kx) // Фаза - пила { //MessageBox.Show("kx = " + kx); int NX = cmpl0.width; int NY = cmpl0.height; ZComplexDescriptor cmpl = new ZComplexDescriptor(NX, NY); // Фронт под углом kx, 2PI double[] pf = new double[NX]; double dx = 2 * Math.PI / kx; double s = 0; for (int i = 0; i < NX; i++, s += dx) { pf[i] = s; } int n2 = NX / 2; for (int i = 0; i < n2; i++) { pf[i] = pf[i + n2]; pf[i + n2] = pf[i]; } // Инверсия for (int i = 0; i < NX; i++) { for (int j = 0; j < NY; j++) { double f0 = cmpl0.array[i, j].Phase; double r0 = cmpl0.array[i, j].Real; f0 = f0 + pf[i]; cmpl.array[i, j] = Complex.FromPolarCoordinates(r0, f0); } } return(cmpl); }
public static void TRNS_С() // Транспонирование zComplex[Form1.regComplex] { if (Form1.zComplex[Form1.regComplex] == null) { MessageBox.Show(" ROR_TRNS zComplex [" + Form1.regComplex + "] == NULL"); return; } int nx = Form1.zComplex[Form1.regComplex].width; int ny = Form1.zComplex[Form1.regComplex].height; ZComplexDescriptor zArray = new ZComplexDescriptor(nx, ny); for (int i = 0; i < ny; i++) { for (int j = 0; j < nx; j++) { zArray.array[i, j] = Form1.zComplex[Form1.regComplex].array[j, i]; } } Form1.zComplex[Form1.regComplex] = zArray; ComplexPictureImage(Form1.regComplex); }