public static void RotateAndAdd(
            float[] cosMap,
            uint bits,
            ref ComplexFloat source,
            ref ComplexFloat target,
            uint arg)
        {
            FPGA.Const <uint> mask = GeneratorTools.Mask(bits);

            if (bits == 0)
            {
                target.Re = source.Re;
                target.Im = source.Im;
            }
            else
            {
                float cos = 0.0f, sin = 0.0f;

                uint cosIdx = arg & mask;
                cos = cosMap[cosIdx];

                if (bits > 1)
                {
                    uint sinIdx = (uint)(cosIdx + (cosMap.Length >> 2)) & mask;
                    sin = cosMap[sinIdx];
                }

                target.Re += source.Re * cos - source.Im * sin;
                target.Im += source.Re * sin + source.Im * cos;
            }
        }
        public static void CopyAndNormalize(
            uint bits,
            ComplexFloat[] source,
            ComplexFloat[] target,
            Direction direction,
            ref ComplexFloat tmpBuff)
        {
            FPGA.Const <float> nFloat = GeneratorTools.FloatArrayLength(bits);

            for (uint i = 0; i < source.Length; i++)
            {
                FPGA.Config.SetInclusiveRange(0, source.Length, i);

                tmpBuff = source[i];

                if (direction == Direction.Forward)
                {
                    tmpBuff.Re = tmpBuff.Re / nFloat;
                    tmpBuff.Im = tmpBuff.Im / nFloat;
                }

                target[i] = tmpBuff;
            }
        }
Example #3
0
        public static void Transform(
            uint bits,
            ComplexFloat[] source,
            ComplexFloat[] target,
            Direction direction)
        {
            FPGA.Const <uint> length = GeneratorTools.ArrayLength(bits);
            float[]           cosMap = GeneratorTools.CosArray(length, direction);
            FPGA.Config.NoSync(cosMap, target);

            var eK      = new ComplexFloat();
            var oK      = new ComplexFloat();
            var rotated = new ComplexFloat();
            var tmp     = new ComplexFloat();

            for (uint i = 0; i < source.Length; i++)
            {
                uint j = FPGA.Runtime.Reverse(i, bits);
                tmp       = source[i];
                target[j] = tmp;
            }

            uint m         = 1;
            uint groupSize = length;

            for (uint i = 0; i < bits; i++)
            {
                FPGA.Config.SetInclusiveRange(0, bits, i);

                groupSize = groupSize >> 1;

                for (uint group = 0; group < m; group++)
                {
                    FPGA.Config.SetInclusiveRange(0, bits, i);

                    uint arg = groupSize * group;
                    for (uint idx = group; idx < length; idx += m * 2)
                    {
                        FPGA.Config.SetInclusiveRange(0, bits, i);

                        eK = target[idx];
                        oK = target[idx + m];

                        FTTools.Rotate(cosMap, bits, ref oK, ref rotated, arg);

                        tmp.Re = eK.Re + rotated.Re;
                        tmp.Im = eK.Im + rotated.Im;

                        target[idx] = tmp;

                        tmp.Re = eK.Re - rotated.Re;
                        tmp.Im = eK.Im - rotated.Im;

                        target[idx + m] = tmp;
                    }
                }
                m = m << 1;
            }

            FTTools.CopyAndNormalize(bits, target, target, direction, ref tmp);
        }