当前位置: 首页>>代码示例>>C#>>正文


C# Complex.GetLength方法代码示例

本文整理汇总了C#中Complex.GetLength方法的典型用法代码示例。如果您正苦于以下问题:C# Complex.GetLength方法的具体用法?C# Complex.GetLength怎么用?C# Complex.GetLength使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Complex的用法示例。


在下文中一共展示了Complex.GetLength方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: GetCorners

        private static Complex[,] GetCorners(Complex[,] signal, bool isFromCenter, double lim1, double lim2, IProgress progress, ref CancellationToken ct)
        {
            int M = signal.GetLength(0);
            int N = signal.GetLength(1);
            int M2 = (M + 1) / 2;
            int N2 = (N + 1) / 2;
            int MN2 = M2 * N2;
            double lengthMN = Math.Sqrt(M2 * M2 + N2 * N2);
            double length1 = lim1 * lengthMN;
            double length2 = lim2 * lengthMN;
            double lengthGrad = length2 - length1;

            Complex c1 = new Complex(1, 0);
            Complex[,] filter = new Complex[M, N];

            for (int x = 0; x < M2; x++)
                for (int y = 0; y < N2; y++)
                {
                    double length = Math.Sqrt(x * x + y * y);
                    double factor = 1;
                    if (length < length1)
                        factor = 0;
                    else if (length < length2)
                        factor = (length - length1) / lengthGrad;
                    if (!isFromCenter)
                        factor = 1 - factor;
                    filter[x, y] = filter[M - 1 - x, y] = filter[x, N - 1 - y] = filter[M - 1 - x, N - 1 - y] = factor * c1;
                    // application process functionality
                    progress.Progress = (x * N + y) / MN2;
                    if (ct.IsCancellationRequested)
                        return null;
                }

            return filter;
        }
开发者ID:gpatho,项目名称:Fourier,代码行数:35,代码来源:Filter.cs

示例2: ISTFT

        //-------------------------------------------------------------------------------------
        //ISTFT(逆短時間フーリエ変換)
        public static double[] ISTFT(Complex[,] stft, int window_size)
        {
            int F_step = stft.GetLength(0);
            int T_step = stft.GetLength(1);
            double window_power = powerOfwindow(window_size); //窓関数のパワー WN
            double[] output = new double[(int)window_power * T_step + window_size]; //output
            double[] total_window = new double[output.Length]; //オーバーラップした窓関数の和

            double[] window = Hamming_Window(window_size);
            double[] ifft;
            Complex[] stft_t = new Complex[F_step];
            for (int i = 0; i < T_step; i++)
            {
                for (int f = 0; f < F_step; f++)
                    stft_t[f] = stft[f, i];
                Real_IFFT(stft_t, out ifft);

                for (int j = 0; j < window_size; j++)
                {
                    total_window[j + (int)window_power * i] += window[j];
                    output[j + (int)window_power * i] += ifft[j];
                }
            }
            for (int i = 0; i < output.Length; i++)
            {
                if (total_window[i] != 0)
                    output[i] /= total_window[i];
            }
            return output;
        }
开发者ID:yusukeinyos,项目名称:constant-Q-transform,代码行数:32,代码来源:SP.cs

示例3: Copy

 /// <summary>
 ///     Copy arrays
 /// </summary>
 /// <param name="input">Input array</param>
 /// <param name="output">Output array</param>
 private static void Copy(Complex[,,] input, Complex[,,] output)
 {
     var n0 = input.GetLength(0);
     var n1 = input.GetLength(1);
     var n2 = input.GetLength(2);
     var m0 = output.GetLength(0);
     var m1 = output.GetLength(1);
     var m2 = output.GetLength(2);
     var ex0 = Math.Min(n0, m0)/2;
     var ex1 = Math.Min(n1, m1)/2;
     var ex2 = Math.Min(n2, m2);
     Debug.Assert(n2 == m2);
     for (var k = 0; k < ex2; k++)
     {
         for (var i = 0; i <= ex0; i++)
         {
             for (var j = 0; j <= ex1; j++)
             {
                 var ni = n0 - i - 1;
                 var nj = n1 - j - 1;
                 var mi = m0 - i - 1;
                 var mj = m1 - j - 1;
                 output[i, j, k] = input[i, j, k];
                 output[mi, j, k] = input[ni, j, k];
                 output[i, mj, k] = input[i, nj, k];
                 output[mi, mj, k] = input[ni, nj, k];
             }
         }
     }
 }
开发者ID:0x0all,项目名称:FFTTools,代码行数:35,代码来源:StretchBuilder.cs

示例4: CmatToPowermat

 //-------------------------------------------------------------
 //複素行列 ⇒ パワー行列
 public static double[,] CmatToPowermat(Complex[,] c)
 {
     double[,] d = new double[c.GetLength(0), c.GetLength(1)];
     for (int i = 0; i < c.GetLength(0); i++)
         for (int j = 0; j < c.GetLength(1); j++)
             d[i, j] = c[i, j].Magnitude * c[i, j].Magnitude;
     return d;
 }
开发者ID:yusukeinyos,项目名称:constant-Q-transform,代码行数:10,代码来源:SP.cs

示例5: DFT2

		public static void DFT2(Complex[,] data, FourierDirection direction) {
			double num3;
			double num4;
			double num5;
			int length = data.GetLength(0);
			int num2 = data.GetLength(1);
			Complex[] complexArray = new Complex[Math.Max(length, num2)];
			for (int i = 0; i < length; i++) {
				for (int k = 0; k < num2; k++) {
					complexArray[k] = Complex.Zero;
					num3 = (((((double)-((int)direction)) * 2.0) * 3.1415926535897931) * k) / ((double)num2);
					for (int m = 0; m < num2; m++) {
						num4 = Math.Cos(m * num3);
						num5 = Math.Sin(m * num3);
						complexArray[k].Re += (float)((data[i, m].Re * num4) - (data[i, m].Im * num5));
						complexArray[k].Im += (float)((data[i, m].Re * num5) + (data[i, m].Im * num4));
					}
				}
				if (direction == FourierDirection.Forward) {
					for (int n = 0; n < num2; n++) {
						data[i, n].Re = complexArray[n].Re / ((float)num2);
						data[i, n].Im = complexArray[n].Im / ((float)num2);
					}
				} else {
					for (int num10 = 0; num10 < num2; num10++) {
						data[i, num10].Re = complexArray[num10].Re;
						data[i, num10].Im = complexArray[num10].Im;
					}
				}
			}
			for (int j = 0; j < num2; j++) {
				for (int num12 = 0; num12 < length; num12++) {
					complexArray[num12] = Complex.Zero;
					num3 = (((((double)-((int)direction)) * 2.0) * 3.1415926535897931) * num12) / ((double)length);
					for (int num13 = 0; num13 < length; num13++) {
						num4 = Math.Cos(num13 * num3);
						num5 = Math.Sin(num13 * num3);
						complexArray[num12].Re += (float)((data[num13, j].Re * num4) - (data[num13, j].Im * num5));
						complexArray[num12].Im += (float)((data[num13, j].Re * num5) + (data[num13, j].Im * num4));
					}
				}
				if (direction == FourierDirection.Forward) {
					for (int num14 = 0; num14 < length; num14++) {
						data[num14, j].Re = complexArray[num14].Re / ((float)length);
						data[num14, j].Im = complexArray[num14].Im / ((float)length);
					}
				} else {
					for (int num15 = 0; num15 < length; num15++) {
						data[num15, j].Re = complexArray[num15].Re;
						data[num15, j].Im = complexArray[num15].Im;
					}
				}
			}
		}
开发者ID:GodLesZ,项目名称:svn-dump,代码行数:54,代码来源:FourierTransform.cs

示例6: ReverseTransform

 public static Complex[,] ReverseTransform(Complex[,] F, FourierType type, IProgress progress, CancellationToken ct)
 {
     switch (type)
     {
         case FourierType.SlowCalculation:
             return SlowCalculation(F, 1, progress, ct);
         case FourierType.MatrixCalculation:
             if ((phicC == null) || (phirC == null) || (phicC.GetLength(0) != F.GetLength(0)) || (phirC.GetLength(0) != F.GetLength(1)))
                 CreateMatrixes(F.GetLength(0), F.GetLength(1), ct);
             return MatrixCalculation(phicC, F, phirC, progress, ct);
     }
     throw new NotImplementedException("Transformation type is not implemented.");
 }
开发者ID:gpatho,项目名称:Fourier,代码行数:13,代码来源:FourierTransform.cs

示例7: Transform

 public static Complex[,] Transform(Complex[,] f, FourierType type, IProgress progress, CancellationToken ct)
 {
     switch (type)
     {
         case FourierType.SlowCalculation:
             return SlowCalculation(f, -1, progress, ct);
         case FourierType.MatrixCalculation:
             if ((phic == null) || (phir == null) || (phic.GetLength(0) != f.GetLength(0)) || (phir.GetLength(0) != f.GetLength(1)))
                 CreateMatrixes(f.GetLength(0), f.GetLength(1), ct);
             return MatrixCalculation(phic, f, phir, progress, ct);
     }
     throw new NotImplementedException("Transformation type is not implemented.");
 }
开发者ID:gpatho,项目名称:Fourier,代码行数:13,代码来源:FourierTransform.cs

示例8: SaveComplexArrayAsHSV

        public static void SaveComplexArrayAsHSV(Complex[,] data, string path)
        {
            int X = data.GetLength(0);
            int Y = data.GetLength(1);
            var bmp = new Bitmap(X, Y);
            for (int x = 0; x < X; x++)
            {
                for (int y = 0; y < Y; y++)
                {
                    var HV = data[x, y];
                    var V = Math.Round(HV.Magnitude * 100);
                    var H = (int)(HV.Phase * 180 / Math.PI);
                    if (H < 0) H += 360;
                    var hi = H / 60;
                    var a = V * (H % 60) / 60.0d;
                    var vInc = (int)(a * 2.55d);
                    var vDec = (int)((V - a) * 2.55d);
                    var v = (int)(V * 2.55d);
                    Color c;
                    switch (hi)
                    {
                        case 0:
                            c = Color.FromArgb(v, vInc, 0);
                            break;
                        case 1:
                            c = Color.FromArgb(vDec, v, 0);
                            break;
                        case 2:
                            c = Color.FromArgb(0, v, vInc);
                            break;
                        case 3:
                            c = Color.FromArgb(0, vDec, v);
                            break;
                        case 4:
                            c = Color.FromArgb(vInc, 0, v);
                            break;
                        case 5:
                            c = Color.FromArgb(v, 0, vDec);
                            break;
                        default:
                            c = Color.Black;
                            break;
                    }
                    bmp.SetPixel(x, y, c);
                }
            }

            bmp.Save(path, ImageFormat.Png);
        }
开发者ID:Cool2Feel,项目名称:cuda-fingerprinting,代码行数:49,代码来源:ImageHelper.cs

示例9: IsUnitary2x2

        public static bool IsUnitary2x2(Complex[,] matrix)
        {
            double epsilon = Quantum.QuantumComputer.Epsilon;

            if(matrix == null ||
                matrix.GetLength(0) != 2 ||
                matrix.GetLength(1) != 2)
            {
                return false;
            }

            bool isUnitary = false;

            Complex[,] conjugate = new Complex[2, 2];
            conjugate[0, 0] = Complex.Conjugate(matrix[0, 0]);
            conjugate[0, 1] = Complex.Conjugate(matrix[1, 0]);
            conjugate[1, 0] = Complex.Conjugate(matrix[0, 1]);
            conjugate[1, 1] = Complex.Conjugate(matrix[1, 1]);

            Complex[,] con_x_mat = new Complex[2, 2];
            Complex[,] mat_x_con = new Complex[2, 2];

            con_x_mat[0, 0] = conjugate[0, 0] * matrix[0, 0] + conjugate[0, 1] * matrix[1, 0];
            con_x_mat[0, 1] = conjugate[0, 0] * matrix[0, 1] + conjugate[0, 1] * matrix[1, 1];
            con_x_mat[1, 0] = conjugate[1, 0] * matrix[0, 0] + conjugate[1, 1] * matrix[1, 0];
            con_x_mat[1, 1] = conjugate[1, 0] * matrix[0, 1] + conjugate[1, 1] * matrix[1, 1];

            mat_x_con[0, 0] = matrix[0, 0] * conjugate[0, 0] + matrix[0, 1] * conjugate[1, 0];
            mat_x_con[0, 1] = matrix[0, 0] * conjugate[0, 1] + matrix[0, 1] * conjugate[1, 1];
            mat_x_con[1, 0] = matrix[1, 0] * conjugate[0, 0] + matrix[1, 1] * conjugate[1, 0];
            mat_x_con[1, 1] = matrix[1, 0] * conjugate[0, 1] + matrix[1, 1] * conjugate[1, 1];

            if ((con_x_mat[0, 0] - 1).Magnitude < epsilon &&
                (con_x_mat[1, 1] - 1).Magnitude < epsilon &&
                (con_x_mat[0, 1]).Magnitude < epsilon &&
                (con_x_mat[1, 0]).Magnitude < epsilon &&
                (mat_x_con[0, 0] - 1).Magnitude < epsilon &&
                (mat_x_con[1, 1] - 1).Magnitude < epsilon &&
                (mat_x_con[0, 1]).Magnitude < epsilon &&
                (mat_x_con[1, 0]).Magnitude < epsilon)
            {
                isUnitary = true;
            }
            else
            {
                isUnitary = false;
            }
            return isUnitary;
        }
开发者ID:wupeng78,项目名称:QuIDE-source-code,代码行数:49,代码来源:MatrixValidator.cs

示例10: GetBitmap

        public static Bitmap GetBitmap(Complex[,] signal)
        {
            Bitmap bitmap = new Bitmap(signal.GetLength(0), signal.GetLength(1), PixelFormat.Format24bppRgb);

            BitmapData bitmapData = bitmap.LockBits(new Rectangle(0, 0, bitmap.Width, bitmap.Height), ImageLockMode.ReadWrite, bitmap.PixelFormat);
            int bytes = Math.Abs(bitmapData.Stride) * bitmap.Height;
            byte[] pixels = new byte[bytes];
            Marshal.Copy(bitmapData.Scan0, pixels, 0, bytes);

            GetPixels(signal, pixels, bitmapData.Width, bitmapData.Height, bitmapData.Stride);

            Marshal.Copy(pixels, 0, bitmapData.Scan0, bytes);
            bitmap.UnlockBits(bitmapData);

            return bitmap;
        }
开发者ID:gpatho,项目名称:Fourier,代码行数:16,代码来源:ImageHelper.cs

示例11: FBSubstitution

        public static Complex[] FBSubstitution(Complex[][] L,Complex[][]U, Complex[] y )
        {
            var length = L.GetLength(0);
            var interm  = new Complex[length];
            var x = new Complex[length];
            Complex sum = 0;
            //Substitute y values into L to get the intermediate vector
            for (int i = 0; i < length; i++)
            {
                for (int j = 0; j < i; j++)
                {
                    sum += y[j] * L[i][j];
                }
                interm[i] = y[i] - sum;
            }

            //Substitute intermediate vector values into U to get x
            for (int i = length - 1; i >= 0; i--)
            {
                for (int j = i; j < i; j++)
                {
                    sum += y[j] * L[i][j];
                }
                interm[i] = y[i] - sum;
 
            }
            return y;
        }
开发者ID:tonyju,项目名称:DSMviewer,代码行数:28,代码来源:MatrixSolvers.cs

示例12: FastTransform

        /// <summary>
        /// Двумерное прямое быстрое преобразование фурье
        /// </summary>
        /// <param name="source">входная матрица</param>
        /// <returns>Выходной ряд</returns>
        public static Complex[,] FastTransform(Complex[,] source)
        {
            int m = source.GetLength(0);    //строк
            int n = source.GetLength(1);    //столбцов

            int size = n;
            if (m > n)
                size = m;

            double log = Math.Log(size, 2);
            Complex[,] x;

            if (log - Math.Round(log) != 0)
                size = (int)Math.Pow(2, (int)log + 1);
            x = new Complex[size, size];
            for (int i = 0; i < m; i++)
                for (int j = 0; j < n; j++)
                    x[i, j] = source[i, j];

            Complex[,] outC = new Complex[size, size];

            //преобразуем строки
            for (int i = 0; i < size; i++) //проходим по строкам
            {
                Complex[] str = new Complex[size];
                for (int j = 0; j < size; j++) //проходим внутри строки, собирая её
                    str[j] = x[i, j];
                str = Fourier.UnsafeFastTransform(str);   //получаем фурье образ строки
                for (int j = 0; j < size; j++) //записываем его в массив
                    outC[i, j] = str[j];
            }

            //преобразуем столбцы
            for (int i = 0; i < size; i++) //проходим по столбцам
            {
                Complex[] raw = new Complex[size];
                for (int j = 0; j < size; j++) //проходим внутри столбца, собирая его
                    raw[j] = outC[j, i];
                raw = Fourier.UnsafeFastTransform(raw);   //получаем фурье образ столбца
                for (int j = 0; j < size; j++) //записываем его в массив
                    outC[j, i] = raw[j];
            }

            return outC;
        }
开发者ID:Kovnir,项目名称:ImageEditor,代码行数:50,代码来源:Fourier.cs

示例13: LUDecomposition

        static public Tuple<Complex[][],Complex[][]> LUDecomposition(Complex[][] B, Complex[] Y)
        {
            var  length = Y.GetLength(0);
            if (length != B.GetLength(0) || B.GetLength(1) != length)
            {
                throw new Exception("The matrix and vector do not have the same dimension");
            }
            
            var U = new Complex[length][];
            var L = new Complex[length][];
            Complex sum1;
            Complex sum2;
            Complex b0i = 0;
            //Initialize the Jagged arrays for Doolittle L and U
            for (int i = 0; i < length; i++)
            {
                L[i] = new Complex[length];
                U[i] = new Complex[length];
                b0i = B[0][i];
                U[0][i] = b0i;
                L[i][0] = B[i][0] / b0i;
                L[i][i] = 1;
            }
            //Perform the decomposition - currently no pivoting, very computationally intensive
            for (int i = 1; i < length; i++)
            {
                for (int j = i; j < length; j++)
                {
                    sum1 = 0;
                    sum2 = 0;
                    for (int k = 0; k < j; k++)
                    {
                        sum1 += L[i][k] * U[k][j];
                        sum2 += L[j][k] * U[k][i];
                    }
                    U[i][j] = B[i][j] - sum1;
                    L[j][i] = (B[j][i] - sum2) / U[i][j];
                }
                                
            }

            return new Tuple<Complex[][], Complex[][]>(L, U);
 
        }
开发者ID:tonyju,项目名称:DSMviewer,代码行数:44,代码来源:MatrixSolvers.cs

示例14: ApplyFilter

        public static Complex[,] ApplyFilter(Complex[,] signal, Complex[,] filter, IProgress progress, CancellationToken ct)
        {
            int M = signal.GetLength(0);
            int N = signal.GetLength(1);
            int MN = M * N;
            Complex[,] result = new Complex[M, N];

            for (int x = 0; x < M; x++)
                for (int y = 0; y < N; y++)
                {
                    result[x, y] = signal[x, y] * filter[x, y];
                    progress.Progress = (x * N + y) / MN;
                    // application process functionality
                    if (ct.IsCancellationRequested)
                        return null;
                }

            return result;
        }
开发者ID:gpatho,项目名称:Fourier,代码行数:19,代码来源:Filter.cs

示例15: Multiply

        public static Complex[,] Multiply(Complex[,] mat1, Complex[,] mat2)
        {
            Complex[,] mat3 = new Complex[mat1.GetLength(0), mat2.GetLength(1)];
            if (mat1.GetLength(1) != mat2.GetLength(0))
                return null;

            for (int i = 0; i < mat1.GetLength(0); i++)//rows
            {
                for (int j = 0; j < mat2.GetLength(1); j++)//columns
                {
                    Complex sum = new Complex();
                    for (int k = 0; k < mat2.GetLength(1); k++)
                    {
                        sum += mat1[i, k] * mat2[k, j];
                    }
                    mat3[i, j] = sum;
                }
            }
            return mat3;
        }
开发者ID:stefan-j,项目名称:DotNetLearn,代码行数:20,代码来源:Complex.cs


注:本文中的Complex.GetLength方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。