public unsafe Resampler(double inputSampleRate, double outputSampleRate, int tapsPerPhase = 160, double protectedPassband = 0.45) { Resampler.DoubleToFraction(outputSampleRate / inputSampleRate, out this._interpolationFactor, out this._decimationFactor); this._tapsPerPhase = tapsPerPhase; int num = tapsPerPhase * this._interpolationFactor; this._firKernelBuffer = UnsafeBuffer.Create(num, 4); this._firKernel = (float *)(void *)this._firKernelBuffer; double cutoffFrequency = Math.Min(inputSampleRate, outputSampleRate) * protectedPassband; float[] array = FilterBuilder.MakeLowPassKernel(inputSampleRate * (double)this._interpolationFactor, num - 1, cutoffFrequency, WindowType.BlackmanHarris4); float[] array2 = array; fixed(float *ptr = array2) { for (int i = 0; i < array.Length; i++) { ptr[i] *= (float)this._interpolationFactor; } Utils.Memcpy(this._firKernel, ptr, (num - 1) * 4); this._firKernel[num - 1] = 0f; } this._firQueueBuffer = UnsafeBuffer.Create(num, 4); this._firQueue = (float *)(void *)this._firQueueBuffer; }
private unsafe void Configure() { this._osc->SampleRate = this._sampleRate; this._osc->Frequency = 57000.0; int i; for (i = 0; this._sampleRate >= 20000.0 * Math.Pow(2.0, (double)i); i++) { } this._decimator = new IQDecimator(i, this._sampleRate, true, false); this._decimationFactor = (int)Math.Pow(2.0, (double)i); this._demodulationSampleRate = this._sampleRate / (double)this._decimationFactor; float[] coefficients = FilterBuilder.MakeLowPassKernel(this._demodulationSampleRate, 200, 2500.0, WindowType.BlackmanHarris4); this._baseBandFilter.SetCoefficients(coefficients); this._pll->SampleRate = (float)this._demodulationSampleRate; this._pll->DefaultFrequency = 0f; this._pll->Range = 12f; this._pll->Bandwidth = 1f; this._pll->Zeta = 0.707f; this._pll->LockTime = 0.5f; this._pll->LockThreshold = 3.2f; int length = (int)(this._demodulationSampleRate / 1187.5) | 1; coefficients = FilterBuilder.MakeSin(this._demodulationSampleRate, 1187.5, length); this._matchedFilter.SetCoefficients(coefficients); this._syncFilter->Init(IirFilterType.BandPass, 1187.5, this._demodulationSampleRate, 500); }
private void Configure() { _osc->SampleRate = _sampleRate; _osc->Frequency = PllDefaultFrequency; var decimationStageCount = 0; while (_sampleRate >= 20000 * Math.Pow(2.0, decimationStageCount)) { decimationStageCount++; } _decimator = new IQDecimator(decimationStageCount, _sampleRate, true, false); _decimationFactor = (int)Math.Pow(2.0, decimationStageCount); _demodulationSampleRate = _sampleRate / _decimationFactor; var coefficients = FilterBuilder.MakeLowPassKernel(_demodulationSampleRate, 200, 2500, WindowType.BlackmanHarris4); _baseBandFilter.SetCoefficients(coefficients); _pll->SampleRate = (float)_demodulationSampleRate; _pll->DefaultFrequency = 0; _pll->Range = PllRange; _pll->Bandwidth = PllBandwith; _pll->Zeta = PllZeta; _pll->LockTime = PllLockTime; _pll->LockThreshold = PllLockThreshold; var matchedFilterLength = (int)(_demodulationSampleRate / RdsBitRate) | 1; coefficients = FilterBuilder.MakeSin(_demodulationSampleRate, RdsBitRate, matchedFilterLength); _matchedFilter.SetCoefficients(coefficients); _syncFilter->Init(IirFilterType.BandPass, RdsBitRate, _demodulationSampleRate, 500); }
private unsafe void Configure() { this._osc.SampleRate = this._sampleRate; this._osc.Frequency = 57000.0; int i; for (i = 0; this._sampleRate >= (double)(20000 << i); i++) { } this._decimationFactor = 1 << i; this._demodulationSampleRate = this._sampleRate / (double)this._decimationFactor; this._decimator = new DownConverter(this._demodulationSampleRate, this._decimationFactor); float[] coefficients = FilterBuilder.MakeLowPassKernel(this._demodulationSampleRate, 200, 2500.0, WindowType.BlackmanHarris4); this._baseBandFilter = new IQFirFilter(coefficients, 1); this._pll->SampleRate = (float)this._demodulationSampleRate; this._pll->DefaultFrequency = 0f; this._pll->Range = 12f; this._pll->Bandwidth = 1f; this._pll->Zeta = 0.707f; this._pll->LockTime = 0.5f; this._pll->LockThreshold = 3.2f; int length = (int)(this._demodulationSampleRate / 1187.5) | 1; coefficients = FilterBuilder.MakeSin(this._demodulationSampleRate, 1187.5, length); this._matchedFilter = new FirFilter(coefficients, 1); this._syncFilter->Init(IirFilterType.BandPass, 1187.5, this._demodulationSampleRate, 500.0); }
public static float[] MakeBandPassKernel(double sampleRate, int filterOrder, double cutoff1, double cutoff2, WindowType windowType) { double num = (cutoff2 - cutoff1) / 2.0; double num2 = cutoff2 - num; double num3 = 6.2831853071795862 * num2 / sampleRate; float[] array = FilterBuilder.MakeLowPassKernel(sampleRate, filterOrder, num, windowType); for (int i = 0; i < array.Length; i++) { int num4 = i - filterOrder / 2; array[i] *= (float)(2.0 * Math.Cos(num3 * (double)num4)); } return(array); }
private void InitFilters() { int cutoff1 = 0; int cutoff2 = 10000; var iqBW = _bandwidth / 2; int iqOrder = _actualDetectorType == DetectorType.WFM ? 60 : _filterOrder; var coeffs = FilterBuilder.MakeLowPassKernel(_sampleRate / (1 << _baseBandDecimationStageCount), iqOrder, iqBW, _windowType); if (_iqFilter == null || _decimationModeHasChanged) { _iqFilter = new IQFirFilter(coeffs, _actualDetectorType == DetectorType.WFM, 1); } else { _iqFilter.SetCoefficients(coeffs); } switch (_actualDetectorType) { case DetectorType.AM: cutoff1 = MinBCAudioFrequency; cutoff2 = Math.Min(_bandwidth / 2, MaxBCAudioFrequency); break; case DetectorType.CW: cutoff1 = Math.Abs(_cwToneShift) - _bandwidth / 2; cutoff2 = Math.Abs(_cwToneShift) + _bandwidth / 2; break; case DetectorType.USB: case DetectorType.LSB: cutoff1 = MinSSBAudioFrequency; cutoff2 = _bandwidth; break; case DetectorType.DSB: cutoff1 = MinSSBAudioFrequency; cutoff2 = _bandwidth / 2; break; case DetectorType.NFM: cutoff1 = MinNFMAudioFrequency; cutoff2 = _bandwidth / 2; break; } coeffs = FilterBuilder.MakeBandPassKernel(_sampleRate / (1 << (_baseBandDecimationStageCount + _audioDecimationStageCount)), _filterOrder, cutoff1, cutoff2, _windowType); _audioFilter.SetCoefficients(coeffs); }
public static Complex[] MakeComplexKernel(double sampleRate, int filterOrder, double bandwidth, double offset, WindowType windowType) { double num = -6.2831853071795862 * offset / sampleRate; float[] array = FilterBuilder.MakeLowPassKernel(sampleRate, filterOrder, bandwidth * 0.5, windowType); Complex[] array2 = new Complex[array.Length]; for (int i = 0; i < array2.Length; i++) { int num2 = i - array2.Length / 2; double num3 = num * (double)num2; array2[i].Real = (float)((double)array[i] * Math.Cos(num3)); array2[i].Imag = (float)((double)(0f - array[i]) * Math.Sin(num3)); } return(array2); }
public static Complex[] MakeComplexKernel(double sampleRate, double passband, double transition, double ripple, double attenuation, double offset) { double num = -6.2831853071795862 * offset / sampleRate; passband *= 0.5; float[] array = FilterBuilder.MakeLowPassKernel(sampleRate, passband, passband + transition, ripple, attenuation); if (array == null) { return(null); } Complex[] array2 = new Complex[array.Length]; for (int i = 0; i < array2.Length; i++) { int num2 = i - array2.Length / 2; double num3 = num * (double)num2; array2[i].Real = (float)((double)array[i] * Math.Cos(num3)); array2[i].Imag = (float)((double)(0f - array[i]) * Math.Sin(num3)); } return(array2); }
public Resampler(double inputSampleRate, double outputSampleRate, int taps) { DoubleToFraction(outputSampleRate / inputSampleRate, out _interpolationFactor, out _decimationFactor); var filterLenght = (int)(500.0 / 32000 * inputSampleRate) / _interpolationFactor * _interpolationFactor; _tapsPerPhase = filterLenght / _interpolationFactor; _firKernelBuffer = UnsafeBuffer.Create(filterLenght, sizeof(float)); _firKernel = (float *)_firKernelBuffer; var cutoff = Math.Min(inputSampleRate, outputSampleRate) * ProtectedPassband; var kernel = FilterBuilder.MakeLowPassKernel(inputSampleRate * _interpolationFactor, filterLenght - 1, cutoff, WindowType.BlackmanHarris4); fixed(float *ptr = kernel) { for (var i = 0; i < kernel.Length; i++) { ptr[i] *= _interpolationFactor; } Utils.Memcpy(_firKernel, ptr, filterLenght * sizeof(float)); } _firQueueBuffer = UnsafeBuffer.Create(filterLenght, sizeof(float)); _firQueue = (float *)_firQueueBuffer; }
private void initFilters() { int num = this._bandwidth / 2; int filterOrder = (this._actualDetectorType == DetectorType.WFM) ? 60 : this._filterOrder; float[] coefficients = FilterBuilder.MakeLowPassKernel(this._sampleRate / Math.Pow(2.0, (double)this._baseBandDecimationStageCount), filterOrder, (double)num, this._windowType); if (this._realIqFilter == null) { this._realIqFilter = new IQFirFilter(coefficients, this._actualDetectorType == DetectorType.WFM, 1); } else { this._realIqFilter.SetCoefficients(coefficients); } if (this._cpxIqFilter == null) { this._cpxIqFilter = new CpxFirFilter(coefficients); } else { this._cpxIqFilter.SetCoefficients(coefficients); } this._envFilter.MakeCoefficients(this._sampleRate / Math.Pow(2.0, (double)this._envelopeDecimationStageCount), 6000, num, this._windowType, false); if (this._notch >= 0) { this._notchFilter[this._notch].MakeCoefficients(this._sampleRate / Math.Pow(2.0, (double)this._baseBandDecimationStageCount), this._notchFrequency, this._notchWidth, this._windowType, true); this._notch = -1; } int num2 = 0; int num3 = 10000; switch (this._actualDetectorType) { case DetectorType.AM: case DetectorType.SAM: num2 = 20; num3 = Math.Min(this._bandwidth / 2, 16000); break; case DetectorType.CW: num2 = this._cwToneShift - this._bandwidth / 2; num3 = this._cwToneShift + this._bandwidth / 2; break; case DetectorType.LSB: case DetectorType.USB: num2 = 400; num3 = this._bandwidth; break; case DetectorType.DSB: num2 = 400; num3 = this._bandwidth / 2; break; case DetectorType.NFM: num2 = 300; num3 = this._bandwidth / 2; break; } coefficients = FilterBuilder.MakeBandPassKernel(this._sampleRate / Math.Pow(2.0, (double)(this._baseBandDecimationStageCount + this._audioDecimationStageCount)), this._filterOrder, (double)num2, (double)num3, this._windowType); this._audioFilter.SetCoefficients(coefficients); this._rFilter.SetCoefficients(coefficients); this._lFilter.SetCoefficients(coefficients); }
public static float[] MakeHighPassKernel(double sampleRate, int filterOrder, double cutoffFrequency, WindowType windowType) { return(FilterBuilder.InvertSpectrum(FilterBuilder.MakeLowPassKernel(sampleRate, filterOrder, cutoffFrequency, windowType))); }