Use oscillator to generate band limited signal


#1

Anybody know how to use the Oscillator class to generate a band limited square wave?

I’m using the following function?

auto squareFunc = [&] (float in) -> float
{
    if (bandLimited)
    {
        double sum = 0;
        for (int i = 1; i < 10; i++)
            sum += sin ((2 * i - 1) * in) / ((2 * i - 1));
        return 4.0f / float_Pi * sum;
    }
    return in < 0 ? -1 : 1;
};

But how do I know how many terms are safe to sum before I start generating frequencies higher than sample rate / 2?


#2

Max number of harmonics = floor (Fs / 2F)

Where F is the base frequency of your oscillator.