# Sampling and Filtering

In my system I measure signals with interesting bandwith from DC to 2 kHz. I have an analog low-pass filter with 200 kHz cutoff frequency in order to filter noise. The ADC samples the signal with 500 kHz. The signals are then used for a feedback controller that runs in a task with 20 kHz. So my questions are the following:

Can I expect alias on the signals used in the control task of 20 kHz?

Should in this case a digital filter at the sampling rate of 500 kHz applied that has a maximal cutoff frequency of 10 kHz (Half of control task rate)?

Would it be possible to apply a further low pass filter with 10 kHz cutoff frequency in the 20 kHz program task?

• How much aliasing depends on filter order and resolution you need. A first order filter has 6dB per octave so it would have barely effect at 250kHz after which aliasing happens. So what kind of filter you have? Sep 27 '20 at 21:46
• When you re-sample the 500kHz input signal for use with 20kHz control task, there can be aliasing. So, just before passing the 500kHz sampled signal to control task, ensure via (digital or analogue) filtering that frequencies above 10kHz are well attenuated.
– AJN
Sep 28 '20 at 1:19
• @Justme : It is a first order analog LP filter. On the computer side, a digital filter is not yet implemented. Sep 28 '20 at 4:49
• If it is a first order filter, see the comment from @Justme . There might not be enough attenuation at 250kHz from where the the aliasing starts.
– AJN
Sep 28 '20 at 12:17
• Indeed. Even if the RC filter 3dB point is set at 20kHz, the attenuation will only be 20dB at 200kHz. 20×log(0.1)=-20 dB. If the filter 3dB point is set at 2kHz, thats -40dB or 0.01 at 200 kHz. Sep 28 '20 at 12:29

Can I expect alias on the signals used in the control task of 20 kHz?

Yes. The 500kHz signal could have have signals up to 200kHz in it. It would get aliased when re-sampled for feeding into 20kHz.

Should in this case a digital filter at the sampling rate of 500 kHz applied that has a maximal cutoff frequency of 10 kHz (Half of control task rate)?

Yes. You can have a digital anti-aliasing filter running at 500kHz sitting upstream of the 20kHz control task.

Would it be possible to apply a further low pass filter with 10 kHz cutoff frequency in the 20 kHz program task?

(Emphasis mine). By the time you are inside the 20kHz, task, the aliasing would have already occured. (Unless you passed multiple, consecutive samples of the 500kHz signal inside the task, in which case the information loss hasn't occured yet). So, the digital anti-aliasing filter should be sitting upstream of the task.

• One approach is to pass 25 of the 500kHz samples to the 20kHz task, and compute their average (add them all and multiply by 1/25) in the 20kHz task. This is a crude but workable form of anti-alias filter, equivalent to a "Sinc filter". Sep 28 '20 at 12:25
• Thanks for the comprehensive explanations. I control a motor with a PWM. Is the situation the same when the ADCs are triggered in such a way that only at the center of the high level of the PWM is measured? Sep 28 '20 at 14:29
• What are you measuring ? The PWM voltage ? If you sample only at high of PWM, won't the ADC be measuring the same value (with some noise) always then ? I think more context is required to answer the question. Perhaps a new question with the details of the system.
– AJN
Sep 28 '20 at 15:28
• I measure the phase current of an electric machine. The PWM is for the input voltage. Yes, a new question may be better. Sep 28 '20 at 20:53