Ejemplo n.º 1
0
        public void IQ_Process(short[] ar, short[] ai)
        {
            DataAndFreq data = new DataAndFreq();

            data.Ar_Data = ar;
            data.Ai_Data = ai;
            m_queue.Enqueue(data);
        }
Ejemplo n.º 2
0
        void m_queue_TEvent(DataAndFreq t)
        {
            IQDataAndFreq nIQDataAndFreq = null;

            int dataLength = t.Ai_Data.Length / 20 * 2;
            //(重要)保持多线程数据一致行所做的必要处理
            int mm_Resolution = m_Resolution, Resolution_length = mm_Resolution * 512;

            if (Resolution_length != IQDataResolution.Length)
            {
                ResolutionIndex     = 0;
                IQDataResolution    = new double[Resolution_length];
                IQDataResolutionOrg = new double[Resolution_length];
            }

            int BaseIndex = dataLength * ResolutionIndex;

            for (int i = 0; i < dataLength / 2; ++i)
            {
                IQDataResolutionOrg[BaseIndex + 2 * i]     = (double)t.Ar_Data[i];
                IQDataResolutionOrg[BaseIndex + 2 * i + 1] = (double)t.Ai_Data[i];
            }

            if (++ResolutionIndex < mm_Resolution)//凑包个数计数
            {
                return;
            }
            ResolutionIndex = 0;

            //对不同分辨率(长度)的数据进行加窗处理
            int mm_Resolution_Index = (int)Math.Log(mm_Resolution, 2);

            for (int i = 0; i < IQDataResolution.Length / 2; i++)
            {
                IQDataResolution[2 * i]     = IQDataResolutionOrg[2 * i] * Window[mm_Resolution_Index][i];
                IQDataResolution[2 * i + 1] = IQDataResolutionOrg[2 * i + 1] * Window[mm_Resolution_Index][i];
            }

            nIQDataAndFreq      = new IQDataAndFreq(t.StartFreq, t.StopFreq, t.Type, t.RF_Gain, t.Digital_Gain);//构造结构体
            nIQDataAndFreq.Data = IQDataResolution;

            ///分发至时域处理类
            DataIQWaveform.PushData(IQDataResolutionOrg);

            //进入此处必然处理下一包 需要为下一包申请指向新空间
            IQDataResolution    = new double[Resolution_length];
            IQDataResolutionOrg = new double[Resolution_length];

            ///分发至频域处理类
            DataFrequencySpectrum.PushData(nIQDataAndFreq);
        }
Ejemplo n.º 3
0
 public void IQ_Process(byte[] t)
 {
     if (dataType == 0 && BitConverter.ToInt32(t, 4) == (uint)DATA_TYPE.DT_NB_DDC) //前4字节是ID 屏蔽网络上的非命令包
     {
         int channel  = BitConverter.ToInt32(t, 16);
         int DATA_LEN = 512 * 2 * 2;
         if (NB_Filter != channel)
         {
             return;
         }
         int    NB_DataMode = BitConverter.ToInt32(t, 92);
         byte[] fData       = new byte[DATA_LEN];
         Array.Copy(t, 104, fData, 0, DATA_LEN);
         //switch ((DataAndFreq.NB_DATA_MODE)NB_DataMode)
         //{
         //    case DataAndFreq.NB_DATA_MODE.NB_MODE_IQ:
         //    case DataAndFreq.NB_DATA_MODE.NB_MODE_ISB:
         //    {
         //        Array.Copy(t, 104, fData, 0, DATA_LEN);
         //        break;
         //    }
         //    case DataAndFreq.NB_DATA_MODE.NB_MODE_AM:
         //    case DataAndFreq.NB_DATA_MODE.NB_MODE_USB:
         //    case DataAndFreq.NB_DATA_MODE.NB_MODE_CW:
         //    case DataAndFreq.NB_DATA_MODE.NB_MODE_LSB:
         //    {
         //        Array.Copy(t, 104, fData, 0, DATA_LEN / 2);
         //        break;
         //    }
         //}
         DataAndFreq nDataAndFreq = new DataAndFreq(t, fData, 1, null, null, NB_DataMode);
         m_queue.Enqueue(nDataAndFreq);
     }
     else if (dataType == 1 && BitConverter.ToInt32(t, 4) == (uint)DATA_TYPE.DT_WB_FFT)
     {
         FFT_Data fft_Data = FFT_Data.DataProcessFFT(t);
         byte[]   fData    = fft_Data?.data;
         if (fData != null && fft_extract++ == 1)
         {
             fft_extract = 0;
             DataAndFreq nDataAndFreq = new DataAndFreq(t, fData, 3, null, null);
             m_queue.Enqueue(nDataAndFreq);
         }
     }
 }
        void m_queue_TEvent(DataAndFreq t)
        {
            double[] outData;
            outData = new double[t.m_Data.Length];
            int    mm_SmoothNum = m_SmoothNum;
            double offset       = 0;
            int    m_RFGain;
            int    m_DigitalGain;

            if (t.Type == 3)
            {
                Array.Copy(t.m_Data, 0, outData, 0, t.m_Data.Length);
                for (int k = 0; k < outData.Length; k++)
                {
                    IQdata[k][SmoothIndex] = outData[k];
                }
                offset = 0;
            }
            else
            {
                hdin  = GCHandle.Alloc(t.m_Data, GCHandleType.Pinned);
                hdout = GCHandle.Alloc(outData, GCHandleType.Pinned);
                dplan = fftw.dft_1d(t.m_Data.Length / 2, hdin.AddrOfPinnedObject(), hdout.AddrOfPinnedObject(), fftw_direction.Forward, fftw_flags.Measure);
                fftw.execute(dplan);
                fftw.destroy_plan(dplan);
                hdin.Free();
                hdout.Free();

                switch (t.NB_DataMode)
                {
                case DataAndFreq.NB_DATA_MODE.NB_MODE_IQ:
                case DataAndFreq.NB_DATA_MODE.NB_MODE_ISB:
                {
                    hdin  = GCHandle.Alloc(t.m_Data, GCHandleType.Pinned);
                    hdout = GCHandle.Alloc(outData, GCHandleType.Pinned);
                    dplan = fftw.dft_1d(t.m_Data.Length / 2, hdin.AddrOfPinnedObject(), hdout.AddrOfPinnedObject(), fftw_direction.Forward, fftw_flags.Measure);
                    fftw.execute(dplan);
                    fftw.destroy_plan(dplan);
                    hdin.Free();
                    hdout.Free();
                    break;
                }

                case DataAndFreq.NB_DATA_MODE.NB_MODE_AM:
                case DataAndFreq.NB_DATA_MODE.NB_MODE_USB:
                case DataAndFreq.NB_DATA_MODE.NB_MODE_CW:
                {
                    for (int k = outData.Length / 2 - 1; k >= 0; k--)
                    {
                        t.m_Data[2 * k]     = t.m_Data[k];
                        t.m_Data[2 * k + 1] = 0;
                    }
                    hdin  = GCHandle.Alloc(t.m_Data, GCHandleType.Pinned);
                    hdout = GCHandle.Alloc(outData, GCHandleType.Pinned);
                    dplan = fftw.dft_1d(t.m_Data.Length / 2, hdin.AddrOfPinnedObject(), hdout.AddrOfPinnedObject(), fftw_direction.Forward, fftw_flags.Measure);
                    fftw.execute(dplan);
                    fftw.destroy_plan(dplan);
                    hdin.Free();
                    hdout.Free();
                    break;
                }

                case DataAndFreq.NB_DATA_MODE.NB_MODE_LSB:
                {
                    for (int k = outData.Length / 2 - 1; k >= 0; k--)
                    {
                        t.m_Data[2 * k + 1] = t.m_Data[k];
                        t.m_Data[2 * k]     = 0;
                    }
                    hdin  = GCHandle.Alloc(t.m_Data, GCHandleType.Pinned);
                    hdout = GCHandle.Alloc(outData, GCHandleType.Pinned);
                    dplan = fftw.dft_1d(t.m_Data.Length / 2, hdin.AddrOfPinnedObject(), hdout.AddrOfPinnedObject(), fftw_direction.Forward, fftw_flags.Measure);
                    fftw.execute(dplan);
                    fftw.destroy_plan(dplan);
                    hdin.Free();
                    hdout.Free();
                    break;
                }

                default: break;
                }
                for (int k = 0; k < outData.Length / 2; k++)
                {
                    IQdata[k][SmoothIndex] = Math.Pow(Math.Pow(outData[k * 2], 2.0) + Math.Pow(outData[k * 2 + 1], 2.0), 0.5);
                }

                int Resolution_Offset = (int)(6 * (Math.Log(t.m_Data.Length, 2) - 10));
                if (t.Type == 2)
                {
                    offset = 133 - 7 + Resolution_Offset;
                }
                else if (t.Type == 1)
                {
                    offset = 133 - 3.14 + Resolution_Offset;
                }
            }

            double[] power = null;

            if (t.Type == 3)
            {
                power = new double[outData.Length];
                for (int i = 0; i < outData.Length; i++)
                {
                    double sum = 0;
                    for (int j = 0; j < mm_SmoothNum; j++)
                    {
                        sum += IQdata[i][j];
                    }
                    sum          /= mm_SmoothNum;
                    m_DigitalGain = 0; //Convert.ToInt32(t.Digital_Gain[i * 57 / outData.Length]);
                    m_RFGain      = 0; // Convert.ToInt32(t.RF_Gain[i / outData.Length]);
                    power[i]      = sum / 10 - offset;
                }
            }
            else if (t.Type == 2)
            {
                power = new double[outData.Length / 2];
                for (int i = 0; i < outData.Length / 2; i++)
                {
                    double sum = 0;
                    for (int j = 0; j < mm_SmoothNum; j++)
                    {
                        sum += IQdata[i][j];
                    }
                    sum          /= mm_SmoothNum;
                    m_DigitalGain = Convert.ToInt32(t.Digital_Gain[i * 40 / outData.Length]);
                    m_RFGain      = Convert.ToInt32(t.RF_Gain[0]);
                    power[i]      = Math.Log10(sum) * 20 - offset + m_DigitalGain + m_RFGain;
                }
            }
            else
            {
                power = new double[outData.Length / 2];
                for (int i = 0; i < outData.Length / 2; i++)
                {
                    double sum = 0;
                    for (int j = 0; j < mm_SmoothNum; j++)
                    {
                        sum += IQdata[i][j];
                    }
                    sum     /= mm_SmoothNum;
                    power[i] = Math.Log10(sum) * 20 - offset;
                }
            }

            //平滑处理
            if (++SmoothIndex >= mm_SmoothNum)
            {
                SmoothIndex = 0;
            }

            //数据传递
            PowerAndFreq nPowerAndFreq = new PowerAndFreq();

            power.Reverse <double>();//倒谱处理
            long powerLength = power.Length / 2;

            if (t.Type == 3)
            {
                nPowerAndFreq.Power = power;
            }
            else
            {
                nPowerAndFreq.Power = new double[power.Length];
                Array.Copy(power, powerLength, nPowerAndFreq.Power, 0, powerLength);
                Array.Copy(power, 0, nPowerAndFreq.Power, powerLength, powerLength);
            }

            switch (t.Type)
            {
            case 1:
            {
                nPowerAndFreq.StartFreq = t.StartFreq;
                nPowerAndFreq.StopFreq  = t.StopFreq;
                break;
            }

            case 2:
            {
                nPowerAndFreq.StartFreq = t.StartFreq - 0.07 - 0.640 / power.Length;
                nPowerAndFreq.StopFreq  = t.StopFreq + 0.07;
                break;
            }

            case 3:
            {
                nPowerAndFreq.StartFreq = t.StartFreq;
                nPowerAndFreq.StopFreq  = t.StopFreq;
                break;
            }
            }
            SaveFrequencySpectrum(nPowerAndFreq.Power);
            if (passPowerAndFreq != null)
            {
                passPowerAndFreq(nPowerAndFreq);
            }
        }
 public void PushData(DataAndFreq t)
 {
     m_queue.Enqueue(t);
 }
Ejemplo n.º 6
0
        void m_queue_TEvent(DataAndFreq t)
        {
            int dataLength;

            double[] fftData;
            if (t.Type == 3)
            {
                dataLength = t.Data.Length / 2;
                fftData    = new double[dataLength];
                for (int i = 0; i < dataLength; ++i)
                {
                    fftData[i] = (double)BitConverter.ToInt16(t.Data, 2 * i);//每2个字节IQ数据转换为一个32位有符号整数的数组LX
                }
                t.m_Data = fftData;
            }
            else
            {
                dataLength = t.Data.Length / 2;
                //(重要)保持多线程数据一致行所做的必要处理
                int mm_Resolution = m_Resolution, Resolution_length = mm_Resolution * 1024;

                if (Resolution_length != IQDataResolution.Length)
                {
                    ResolutionIndex     = 0;
                    IQDataResolution    = new double[Resolution_length];
                    IQDataResolutionOrg = new double[Resolution_length];
                }

                int BaseIndex = dataLength * ResolutionIndex;

                //for (int i = 0; i < dataLength; ++i)
                //{
                //    IQDataResolutionOrg[BaseIndex + i] = (double)BitConverter.ToInt16(t.Data, 2 * i);
                //}

                switch (t.NB_DataMode)
                {
                case DataAndFreq.NB_DATA_MODE.NB_MODE_IQ:
                case DataAndFreq.NB_DATA_MODE.NB_MODE_ISB:
                {
                    for (int k = 0; k < dataLength; ++k)
                    {
                        IQDataResolutionOrg[BaseIndex + k] = (double)BitConverter.ToInt16(t.Data, 2 * k);
                    }
                    break;
                }

                case DataAndFreq.NB_DATA_MODE.NB_MODE_AM:
                case DataAndFreq.NB_DATA_MODE.NB_MODE_USB:
                case DataAndFreq.NB_DATA_MODE.NB_MODE_CW:
                {
                    for (int k = dataLength / 2 - 1; k >= 0; k--)
                    {
                        IQDataResolutionOrg[2 * k] = (double)BitConverter.ToInt16(t.Data, 2 * k);
                    }
                    break;
                }

                case DataAndFreq.NB_DATA_MODE.NB_MODE_LSB:
                {
                    for (int k = dataLength / 2 - 1; k >= 0; k--)
                    {
                        IQDataResolutionOrg[2 * k + 1] = (double)BitConverter.ToInt16(t.Data, 2 * k);
                    }
                    break;
                }

                default: break;
                }

                if (++ResolutionIndex < mm_Resolution)//凑包个数计数
                {
                    return;
                }
                ResolutionIndex = 0;

                //对不同分辨率(长度)的数据进行加窗处理
                int mm_Resolution_Index = (int)Math.Log(mm_Resolution, 2);
                for (int i = 0; i < IQDataResolution.Length / 2; i++)
                {
                    IQDataResolution[2 * i]     = IQDataResolutionOrg[2 * i] * Window[mm_Resolution_Index][i];
                    IQDataResolution[2 * i + 1] = IQDataResolutionOrg[2 * i + 1] * Window[mm_Resolution_Index][i];
                }
                t.m_Data = IQDataResolution;

                ///分发至时域处理类
                DataIQWaveform.PushData(IQDataResolutionOrg);

                //进入此处必然处理下一包 需要为下一包申请指向新空间
                IQDataResolution    = new double[Resolution_length];
                IQDataResolutionOrg = new double[Resolution_length];
            }
            ///分发至频域处理类
            DataFrequencySpectrum.PushData(t);
        }