2
\$\begingroup\$

I have an Arduino Nano-based function (sine, sawtooth, triangular, square) generator. Basically it is an Arduino Nano connected to a MCP4802 DAC, whose output is connected to an RC lowpass filter. Currently I have a cut-off frequency of 150 Hz.

The DAC will output 4 V, then it is connected to the RC filter, where R = 100 Ω and C = 10 μF.

The problem is that I can filter out noise on sine wave, however, this filter distorts the square, sawtooth, and triangular signal (which is obvious, since we filter out high-frequency harmonics from sawtooth, triangular, and square wave signals).

Is there a proper way to design an RC filter on the output and at the same time not distort other waveforms (but instead filter out the noise)?

\$\endgroup\$
7
  • 1
    \$\begingroup\$ There is, but you need to know where the noise comes from and what you want to filter out and what bandwidth you need to pass. In theory, a square wave has infinitely fast edges, so it has infinite bandwidth requirement. \$\endgroup\$
    – Justme
    Commented Nov 26, 2022 at 13:48
  • \$\begingroup\$ What noise are you trying to remove? You do know that the MCP4802 is not designed for speed, right? You can probably get audio range signals out of it, but not much more. \$\endgroup\$
    – JRE
    Commented Nov 26, 2022 at 14:02
  • \$\begingroup\$ How quickly (microseconds) does the Nano send the next waveform sample to MCP4802? This update-rate must be much higher than the period of the output waveform you're trying to generate...(you mention a waveform period of 1/150 seconds). \$\endgroup\$
    – glen_geek
    Commented Nov 26, 2022 at 14:26
  • \$\begingroup\$ @glen_geek if only I could know that speed :), I have no idea how quickly it does that. 150 Hz I've simply put without any special purpose. I mean, I have just decided that I want to pass under 150Hz signals and attenuate over 150 Hz signals, however 150 Hz is so low frequency which will very heavily destroy the square waveform, for example, where we have infinite number of high freq. harmonics... so that was my problem. I wish to filter out noise (if there is a sudden signal over 150 Hz but at the same time preserve all 4 waveforms I've been mentioned (saw, triangle, square, sine)) \$\endgroup\$ Commented Nov 26, 2022 at 14:43
  • \$\begingroup\$ How many data points of your sine wave are you sending per second? You should be able to see the individual steps on an oscilloscope. Say you measure the steps as 1 millisecond long. That means you are putting out one thousand steps per second. From that you could work out the maximum reasonable cut off frequency for your filter. \$\endgroup\$
    – JRE
    Commented Nov 26, 2022 at 15:16

1 Answer 1

3
\$\begingroup\$

Is there a proper way to design an RC filter on the output and at the same time not distort other waveforms (but instead filter out the noise)?

No there isn't. If you want to have a sinewave low-pass filter set a little higher than the sinewave frequency then sure, it will be a benefit for sinewave purity but, given the harmonic content of triangle and square waves it will be an absolute killer. Harmonic content of non-sine-waves: -

enter image description here

Image from HyperPhysics. The base (fundamental) frequency is the left-side vertical bar and note, that for a sinewave, only this bar appears in the spectrum hence, applying any linear filter will not alter the sinewave shape (only the amplitude). Here's how a square wave is made up of harmonics (a gif file demonstration): -

enter image description here

Image from here.

So, I suggest that you activate the filter (using a MOSFET) when generating a sinewave and, when producing other waveforms (square, triangle etc.) you deactivate the filter so it has very little effect on the wave-shape.

\$\endgroup\$
12
  • \$\begingroup\$ This is the clearest explanation! I only left with the question about noise. I mean the purpose of RC filter there was to smooth the output signal (due to the Capacitor response) and to attenuate any high frequency noise (from environment etc). While sine wave is filtered, other signals remain stepped and non-defended from noise. Is there some way to smooth the other signals though and secure them from noise? \$\endgroup\$ Commented Nov 27, 2022 at 13:13
  • \$\begingroup\$ What is your question? @ojacomarket \$\endgroup\$
    – Andy aka
    Commented Nov 27, 2022 at 13:14
  • \$\begingroup\$ updated the question \$\endgroup\$ Commented Nov 27, 2022 at 13:18
  • 1
    \$\begingroup\$ You are correct @ojacomarket \$\endgroup\$
    – Andy aka
    Commented Nov 27, 2022 at 13:40
  • 1
    \$\begingroup\$ Accepted and upvoted, thank you very much! \$\endgroup\$ Commented Nov 27, 2022 at 13:46

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.