Thursday, March 2, 2017

Digital Anti Aliasing Filter For Waveform Band Limiting


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.



Answer




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.



You can't do this. You've already aliased the frequencies when you generated the waves in that way. You can't remove them with a filter.



You're essentially sampling the pure mathematical signal without using an antialiasing filter first. It's not possible to add the antialiasing filter after sampling. You will just filter the already-aliased signal. Bandlimiting has to occur before sampling. You need to change the way you generate the waveforms if you want them to be bandlimited. You could generate them using additive synthesis, as I've demonstrated here, or you could generate them the simple way at a much higher sampling rate to minimize the aliasing, then antialias filter, then decimate. Or you could use BLIT or BLEP, etc. (I think those are both "reduced-aliasing" not 100% eliminated, but I'm not sure.)


No comments:

Post a Comment

periodic trends - Comparing radii in lithium, beryllium, magnesium, aluminium and sodium ions

Apparently the of last four, $\ce{Mg^2+}$ is closest in radius to $\ce{Li+}$. Is this true, and if so, why would a whole larger shell ($\ce{...