Electronic – How to calculate, *for a square wave input*, the cut-off frequency point for a basic RC low pass filter with

bode plotcapacitorfilterpcbpcb-design

I am applying low pass filter for a pcb circuit I am trying to design (picture below).
I have managed to calculate the cutoff for a sine wave input since I can insert a frequency (i.e. f_c = 720 Hz ) and get RC out of the equation:
f_c = 1/(2*\pi*RC).

My question is:

How to do the same analysis as above (i.e. finding cutoff point) for a square input. I mean, what should I insert as f_c? doesn't square wave contain all frequencies?

I need to know how my circuit will behave with square input. What will be the time delay created by the filter under different square-wave inputs.

Thanks!
enter image description here

Best Answer

I think this question has some merit. Even though it is asked from the standpoint of not understading harmonic Fourier decomposition, it serves for a few mental exercises. First of all, to address the true goal of the question:

I need to know how my circuit will behave with square input.

Square waves can be given by the summation of all odd harmonics of a fundamental sine wave. If the square wave is input to a linear system, then superposition principle applies, and the output signal can be reconstructed with the appropriate gain/attenuation and phase shift of each individual harmonic component.

For a matlab example, here is how to build a square wave using harmonic components up to 99th order:

t = 0:.01:20;
x = zeros(1,length(t));
for i = 1:2:99
    h = (1/i)*sin(i*t);
    x = x+h;
end
plot(t,x)

enter image description here

To find the output signal, if this wave is to be input of a RC filter, one could use the bode plot of the filter, find the attenuation and phase delay for every single harmonic component, and reconstruct the signal. A bode plot for an example filter:

sys = zpk([],-1,1);
bode(sys)

enter image description here

And the related system output:

lsim(sys,x,t)

enter image description here

Let's attempt to reconstruct the output using data from the bode diagram:

y = zeros(1,length(t));
for i = 1:2:99
    [MAG,PHASE] = bode(sys,i);
    PHASE = pi*PHASE/180;
    h = (MAG/i)*sin(i*t+PHASE);
    y = y+h;
end
plot(t,y)

enter image description here

Hope this covers the aspects of Fourier decomposition and Bode analysis. Now, to explain why the question has more merit than first meets the eye:

How to do the same analysis as above (i.e. finding cutoff point) for a square input. I mean, what should I insert as f_c? Doesn't square wave contain all frequencies?

Cutoff point can be defined as the frequency in which the output signal has half the power of the input signal. For sine inputs, this equals the -3dB frequency. Sine power is proportional to amplitude squared, and -3dB equals a \$.707\$ attenuation, which when squared equals \$.5\$. But what is the power of a square wave? And at which frequency is the output signal half the power of the input? This stands as a separate question which is tangential to the problem, but can serve as a "fun" mathematical exercise.