# Square wave autocorrelation integral

Given the following square wave signal g(t) :

I'm trying to find the $$\R(\tau)\$$ of this signal, but I'm confused about how to solve the integral. In the signal above, the red square wave is the shifted signal $$\g(t-\tau)\$$. I understand the autocorrelation function will be periodic because g(t) is periodic, and will be a triangular waveform.

$$R(\tau) = \int_{-T/2}^{T/2}g(t)g(t-\tau)dt$$

Trying to find the first integral for $$\\tau < T/2\$$ (first picture) I have: $$R_1(\tau) = \int_{-T/4}^{-T/4+\tau} -dt + \int_{-T/4+\tau}^{T/4} dt + \int_{T/4}^{T/4+\tau} -dt + \int_{T/4+\tau}^{3T/4}dt = (-\tau) + (T/2 - \tau) + (-\tau) + (T/2 - \tau) = T - 4\tau$$

For $$\T/2 < \tau < T\$$ I would have the inverse I suppose since it must be symetric.

I'm confused on the first integral. I'm not exactly sure I'm correct. I think I must calculate both integrals (in the picture) on one period i.e. so that the combined integral interval for $$\R_1(\tau)\$$ is on one period. Or is it on a half period? In which case $$\R_1(\tau)\$$ would be $$\ R_1(\tau) = T/2 - 2\tau\$$. The fact the signal is periodic is what is confusing me. I want ultimately to get one period of $$\R(\tau)\$$. So my question simply is: is the expression I got for $$\R_{1}(\tau)\$$ correct or not?

Any help will be greatly appreciated.

## 1 Answer

It should not be difficult to verify that $$\R(\alpha) \$$ is periodic with period $$\T\$$. Here, the value of $$\ R_1(\alpha) = T- 4\alpha \$$ looks correct, for $$\ R_2(\alpha) \$$ I calculate it to be $$\4\alpha - 3T\$$. Both $$\R_1,\ R_2\$$ define $$\R(\alpha)\$$ over one period, as $$\R_1\$$ is defined for $$\0<\alpha whereas $$\R_2\$$ is for $$\T/2<\alpha.

EDIT: Here, let $$\T_p\$$ is the period of the your signal $$\g(t)\$$. Using Wikipedia, we get $$R(\alpha)=\lim _{T\to \infty}T^{-1} \int_0^{T} g(t)g(t-\alpha)dt.$$ Now this can simplified by the periodicity of the your signal $$\g(t)\$$ to give $$R(\alpha) =\lim _{T\to \infty}T^{-1}\sum_{k=0}^{k=T/T_p-1} \int_{k T_p}^{(k+1)T_p} g(t)g(t-\alpha)dt.$$ Now since the integral is periodic over a period $$\T_p\$$ we get $$R(\alpha) = T_p^{-1} \int_0^{T_p}g(t)g(t-\alpha)dt.$$

Upto a constant factor this matches with the definition you used.

• But, more importantly, I wonder if it's even the correct way to calculate the autocorrelation of a periodic function. I'm not even sure. I wonder if it's not more appropriate to use fourier series. After all, autocorrelation by convolution I think applies to energy signals, I'm not sure it works for power signals. This is mostly the clarification I seek. – Yannick Oct 1 '18 at 0:52
• I believe yes. Read here, en.wikipedia.org/wiki/Autocorrelation#Signal_processing . NB: The $T$ in your question is a time period and not the $T$ used in Wikipedia. – MUB Oct 1 '18 at 3:07
• That's interesting because in their derivation for a periodic signal, they take the limit as T -> infinity, i.e. $\lim_{T\to \infty} \frac{1}{T} \int_{0}^{T} f(t)f(t\pm \tau) dt$ But you said something here that raises another question. Do you mean T is not considered as a period in this equation? How should I interpret it? Sorry for asking so much... just wish to understand. – Yannick Oct 2 '18 at 4:53