I am working on some waveform generation software and I am trying to figure out what the best type of filter would be to use a an Anti Aliasing filter for my algorithm. I am generating my waves in a "Raw" mathematical way, meaning that i am creating a ramp for a saw wave and my square wave consists of pure 1's and 0's. The issue is that this technique is inherently not band limited. I would like to implement low pass filter into the algorithm in order to filter of the harmonic being generated that are higher than the nyquist limit.
What would be the ideal filter design for this? What kind of roll of would i need?
I am doing this in c++ but i don't neccesarily need an answer in c++. just an equation or some resources would be good as well.
Thanks
edit: I am not changing the sampling rate at any point in the chain. But i am still experiencing some aliasing somehow.
here is my code:
double _DSP::Saw_Wave(double* _frequency,_DSP::Saw_Data* _data){
double _val = _data->_phasor;
_data->_phasor += 2.0*(1.0/(_DSP::Sample_Rate::Samples_Per_Second()/ *_frequency));
if (_data->_phasor>_data->_tolerance) {
_data->_phasor-=2.0;
}
return _val ;
}
typedef struct Saw_Data{
double _phasor = 0.0;
double _tolerance = 1.0;
}Saw_Data;
where _DSP::SampleRate::Samples_Per_Second() is the sampling rate.
the code generates the proper wave and frequency but has unwanted low frequency information when played at higher frequencies.