示例#1
0
//! Band stop: sample rate, lower frequency, upper frequency, window
std::vector<double> sincBSF(const size_t numTaps, const double Fl, const double Fu)
{
    std::vector<double> taps(numTaps);
    const auto lambda = M_PI * Fl / (0.5);
    const auto phi = M_PI * Fu / (0.5);

    for (size_t n = 0; n < numTaps; n++)
    {
        const double mm = n - (numTaps - 1.0) / 2.0;
        if( mm == 0.0 ) taps[n] = 1.0 - (phi - lambda) / M_PI;
        else taps[n] = -(   sin( mm * phi ) -
                             sin( mm * lambda )   ) / (mm * M_PI);
    }
    return taps;
}
示例#2
0
static std::vector<Real> createPolyphaseLowPass(
	int phaseSteps,
	double gain,
	double sampleRateHz,
	double cutoffFreqHz,
	double transitionWidthHz,
	double oobAttenuationdB)
{
	int ntaps = (int)(oobAttenuationdB * sampleRateHz / (22.0 * transitionWidthHz));
	if((ntaps % 2) != 0)
		ntaps++;
	ntaps *= phaseSteps;

	std::vector<float> taps(ntaps);
	std::vector<float> window(ntaps);

	for(int n = 0; n < ntaps; n++)
		window[n] = 0.54 - 0.46 * cos ((2 * M_PI * n) / (ntaps - 1));

	int M = (ntaps - 1) / 2;
	double fwT0 = 2 * M_PI * cutoffFreqHz / sampleRateHz;
	for(int n = -M; n <= M; n++) {
		if(n == 0) taps[n + M] = fwT0 / M_PI * window[n + M];
			else taps[n + M] =  sin (n * fwT0) / (n * M_PI) * window[n + M];
	}

	double max = taps[0 + M];
	for(int n = 1; n <= M; n++)
		max += 2.0 * taps[n + M];

	gain /= max;

	for(int i = 0; i < ntaps; i++)
		taps[i] *= gain;

	return taps;
}