0

$$ \Pi(t/A) * \Pi(t/B) $$

where

$$ \Pi(t) = \begin{cases} 1,\ -1/2 \leq t \leq 1/2 \\ 0,\ \text{otherwise} \end{cases} $$

How to compute? Derivation/steps optional but welcome.

Note: I'm aware of classic and simple solutions to this problem, but my context is this question, where $C, D$ can be any real non-zero, and the result should not include conditionals (but functions that say the same thing are allowed).

OverLordGoldDragon
  • 8,912
  • 5
  • 23
  • 74

3 Answers3

4

Up till Revision 3 of the OP's question, the function $\Pi(t)$ was defined as a centered rectangular pulse of duration $2$, or effectively, $\operatorname{rect}\left(\frac t2\right)$. The definition has now been changed so that now $\Pi(t)$ is $\operatorname{rect}\left(t\right)$, making my comments on the OP's original self-answer no longer relevant. In my opinion, the OP's self-answer is still unduly cumbersome and so here goes.

Let $\Pi(t)$ be defined as $\operatorname{rect}\left(t\right)$, a unit-height pulse of unit duration, centered at the origin. It is straightforward to verify that $$\left(\Pi * \Pi\right)(t) = \begin{cases}1-|t|, & -1 < t < 1,\\ 0, & |t| \geq 1 \end{cases}$$ which is the familiar triangle function $\operatorname{tri}(t)$ that increases linearly (with slope $1$) from value $0$ at $t=-1$ to value $1$ at $t=0$ and then decreases linearly (with slope $-1$) to value $0$ at $t=1$.

The OP wishes to find a simple expression for $\left(\Pi_A * \Pi_B\right)(t)$ where $\Pi_A(t)$ and $\Pi_B(t)$ denote $\Pi\left(\frac tA\right)$ and $\Pi\left(\frac tB\right)$ respectively for arbitrary nonzero real numbers $A$ and $B$, and promises to excoriate all answers that do not consider the possibility that and/or might be negative. What the OP fails to realize is that sinc $\operatorname{rect}(t)$ is an even function of $t$, $\Pi_A(t) = \Pi_{-A}(t)$ and $\Pi_B(t) = \Pi_{-B}(t)$. Thus, without loss of any generality, we can write $$\left(\Pi_A * \Pi_B\right)(t) = \left(\Pi_{|A|} * \Pi_{|B|}\right)(t)$$ which is a trapezoidal function increasing linearly (slope $1$) from value $0$ at $$t= -\left.\left.\frac 12\right(\max(|A|,|B|)+\min(|A|,|B|)\right)=-\frac 12\big(|A|+|B|\big) $$ to value $\min(|A|,|B|) = \big|\,|A|-|B|\,\big|$ at $$t = -\left.\left.\frac 12\right(\max(|A|,|B|)-\min(|A|,|B|)\right) = -\frac 12 \big(|A-B|\big),$$ then remaining at constant at $\min(|A|,|B|)$ till
$$t = + \left.\left.\frac 12\right(\max(|A|,|B|-\min(|A|,|B|)\right)= +\frac 12 \big(|A-B|\big),$$ at which point it starts decreasing linearly with slope $-1$ till it reaches $0$ again at $$t = +\left.\left.\frac 12\right(\max(|A|,|B|)+\min(|A|,|B|)\right)= +\frac 12\big(|A|+|B|\big).$$ This is indeed a function that would be described by a multiline formula, which doesn't work for OP, and so let's write it in in terms of the triangle function. Note that for any $C > 0$, the convolution of $\Pi_C(t)$ with itself is $$(\Pi_C * \Pi_C)(t) = C\cdot\operatorname{tri}\left(\frac tC\right)$$ and it is straightforward to verify that $\left(\Pi_{A} * \Pi_{B}\right)(t)$ is the difference of two triangle functions, namely \begin{align}\left(\Pi_{A} * \Pi_{B}\right)(t) &= \bigr(|A|+|B|\bigr)\operatorname{tri}\bigg(\frac{t}{|A|+|B|}\bigg)-\bigr(|A -B|\bigr) \operatorname{tri}\bigg(\frac{t}{|A-B|}\bigg)\tag{1} \end{align} or, more prolixly, \begin{align} \left(\Pi_{A} * \Pi_{B}\right)(t)&= \bigr(\max(|A|,|B|)+\min(|A|,|B|)\bigr)\operatorname{tri}\bigg(\frac{t}{\max(|A|,|B|)+\min(|A|,|B|)}\bigg)\\ &\hspace{.1in}-\bigr(\max(|A|,|B|)-\min(|A|,|B|)\bigr)\operatorname{tri}\left(\frac{t}{\max(|A|,|B|)-\min(|A|,|B|)}\right).\tag{2} \end{align}

Dilip Sarwate
  • 20,349
  • 4
  • 48
  • 94
2

I'll give this a whirl. Let's define the causal rectangular function $R(t)$ to be

$$ R(t) = \left\{\begin{matrix} 1 & 0 < t < 1 \\ 0 & else\\ \end{matrix}\right.$$

Let's find $Y(t) = R(t/C) * R(t/D)$, where $*$ denotes convolution. Without loss of generality we can assume that $C \leq D$ and we simply get

$$ R(t) = \left\{\begin{matrix} t & 0 < t <= C \\ C & C <= t <= D \\ t-C & D <= t <= D+C \\ 0 & else\\ \end{matrix}\right.$$

In order to find the answer to the original question as asked we can use the relationships

$$\Pi(t) = R((t+1)/2), \\ R(t) = \Pi(2t-1)$$

Hilmar
  • 44,604
  • 1
  • 32
  • 63
  • "without loss of generality" isn't true for this question's purpose, also this answer assumes positive $C, D$. It also uses conditionals, which cannot readily be plugged into other calculations. I'm well-aware of classic solutions to this problem, but my context is this question, where $C, D$ can be any real non-zero. I should've been more explicit in the question. – OverLordGoldDragon Jun 09 '22 at 17:29
0

Apply convolution theorem: $$ |A||B|\ \mathrm{sinc}(A\omega/2) \ \mathrm{sinc}(B\omega/2) $$

WA gives for $\mathcal{F}^{-1}$, disregarding constants,

$$ \begin{align} && (A + B - 2t) \ \mathrm{sgn}(A + B - 2t) & - (A - B + 2t)\ \mathrm{sgn}(A/2 - B/2 + t) + \\ && (A - B - 2t)\ \mathrm{sgn}(-A/2 + B/2 + t) & + (A + B + 2t)\ \mathrm{sgn}(A/2 + B/2 + t) \end{align} $$

With constants, we multiply all above by

$$ \frac{|A||B|}{4AB} = \frac{1}{4}\mathrm{sgn}(AB) $$

Plotted in desmos. This is the primary solution.

Validating

Comparing sampling the function against FFT convolution:

def formula(t, A, B):
    s = lambda x: np.sign(x)
    p, m = A + B, A - B
o0 = (p - 2*t)*s(p - 2*t)  - (m + 2*t)*s(m/2 + t)
o1 = (m - 2*t)*s(-m/2 + t) + (p + 2*t)*s(p/2 + t)
return (o0 + o1) * (1/4)*s(A*B)

Now for discrete and comparing:

N, A, B = 4096, 10, 4
t = np.linspace(-A*B, A*B, N, 0)  # span long enough interval, A*B

boxcar = lambda A: ((t >= -A/2) * (t <= A/2)).astype(int) x0, x1 = boxcar(A), boxcar(B)

o_fftconv = fft_conv_and_center(x0, x1) * abs(2 * A * B) / N o_formula = out(t, A, B)

Full code -- we also need to scale the discrete result by $2|AB|/N$, and have a sufficiently high $N$ (something with bandlimiting maybe?). Result:

enter image description here

Good enough for me.

Time-domain derivation

Did this first but then scrapped because the expression in terms of $A, B$ is too complicated. This isn't the primary solution, only an alt demo.

Total support is $T=A + B$, of which the flattop part is $T_\text{top}=\max(A, B) - \min(A, B)$, all centered at $x= c = a + b$ (if we did $\Pi(t/A - a) ...$), and let $T_\text{ramp} = T - T_\text{top}$. We have

which is, and let us define "ramp flat ramp",

$$ \begin{align} RFR^{*}(T, T_\text{top}, T_\text{ramp}, c) = \ & r(t - (c - T/2))\ - \\ & r(t - (c - T/2 + T_\text{ramp}/2))\ - \\ & r(t - (c - T/2 + T_\text{ramp}/2 + T_\text{top}))\ + \\ & r(t - (c - T/2 + T_\text{ramp} + T_\text{top})) \end{align} $$

and

$$ \begin{align} RFR(A, B, a, b) = RFR^{*}( & A + B, \max(A, B) - \min(A, B), \\ & A + B - \max(A, B) + \min(A, B), a + b ) \end{align} $$

Then flattop's value (hence output max) is

$$ \begin{align} T_\text{ramp}/2 &= \frac{1}{2}[A + B - \max(A, B) + \min(A, B)] \\ &= \min(A, B) \end{align} $$

We also have $\max(A, B) - \min(A, B) = |A - B|$ (for real $A, B$), and we can simplify to

$$ RFR^{*}(A + B, |A - B|, 2 \min (A, B), a + b) $$

NOTES:

  • $A$ and $B$ are assumed to be non-negative (only in this solution)
  • $*$ isn't complex conjugation (as is seen from the first invocation)
  • $r(t) = (t \geq 0)$, ramp
OverLordGoldDragon
  • 8,912
  • 5
  • 23
  • 74
  • 6
    That seems needless complicated and convoluted (pun a little intended). The convolution of two rectangles of width A and B is a symmetric trapeze. Assuming A is shorter, the length of the slopes is A and the length of the flat part is B-A.. For $A=B$ you get a triangle since $B-A = 0$. That's all there is to it. – Hilmar Jun 07 '22 at 13:10
  • @Hilmar But writing it mathematically won't be any simpler than the above result? Also for discrete we can derive the answer exactly and easier, yes. – OverLordGoldDragon Jun 07 '22 at 23:38
  • 3
    "simple" is a matter of personal preference, I guess. In my personal opinion, my description can be easily turned into a simple piece-wise definition which seems (to me) easier to use for subsequent operations like convolution, integration, differentiation, etc. But that's just me. Also, your result appears to be wrong: the magnitude of the flat part should be $min(A,B)$, i.e. 3 in your case. Not sure how something related to $\pi$ snuck in there. That's another advantage of a verbal description: you can use it to double check the math. – Hilmar Jun 08 '22 at 12:58
  • @Hilmar I agree the derivation is simpler, but the final expression in terms of $A, B$ not so much. Thanks for pointing out $\min(A, B)$, think I missed the $1/(2\pi)$ in FT inversion, fixed. – OverLordGoldDragon Jun 09 '22 at 08:13
  • 1
    This answer has too many incorrect statements in its details. The function $\Pi (t)$ is related to $\operatorname{rect}(t)$ as $\Pi(t) =\operatorname{rect}\left(\frac t2\right)$ and so the convolution under consideration is of two even rectangular pulses of durations $2A$ and $2B$ respectively, not $A$ and $B$ as both the OP and @Hilmar are assuming. Thus, their convolution is a trapezium of base $2A+2B$ and altitude $2\min{A,B}$, while the flat top is of duration $2*(\max{A,B}-\min{A,B})$. This accounts for the $t \to t/2$ phenomenon encountered by the OP. – Dilip Sarwate Jun 09 '22 at 13:30
  • @DilipSarwate Right, thanks. Any other statements ("too many")? – OverLordGoldDragon Jun 09 '22 at 14:10
  • 2
    When the only tool you have in your toolbox is a hammer, everything looks like a nail. The FFT is not the tool to use in solving this problem; the signals are nonzero for $t<0$, while the FFT can deal only with causal signals. So you have to drag the signals to the positive axis, and then re-drag the answer back to put it in its proper place. The changing definitions don't help either. There is a reference to a related question and parameters $C$ and $D$ therein, but looking at the related question shows a complete absence of $C$ and $D$. -1 for the answer and -1 on the question too. – Dilip Sarwate Jun 09 '22 at 18:21
  • @DilipSarwate This Q&A is about the convolution in question without constraining signs of $A, B$ and without using conditionals, to which I have provided two solutions, and optional numeric verification, so I don't see any relevance of your comments in justifying the votes. You also confuse my notation with Hilmar's, no $C, D$. You're welcome to show how my answer is wrong. – OverLordGoldDragon Jun 10 '22 at 11:10
  • Also the FFT requires no such thing. What you may be describing is akin to "DFT assumes input is periodic" i.e. DFT<->DTFT, but it's also directly at odds with it... frankly I've no clue what you intend and it's the first time I hear it. – OverLordGoldDragon Jun 10 '22 at 12:05
  • I will remove my downvote if you edit your answer once again to specify clearly what the function $r(\cdot)$ is, and also state explicitly that the $$ in your $RFR^$ function does not mean complex conjugate of the $RFR$ fun action, and that your time-domain derivation is valid regardless of the signs of $A$ and $B$, assuming, of course, that these statements are true. You say that $A+B$ is the length of the base of the trapezoid which is suspect when $A$ and $B$ have opposite or negative signs. Did you mean to write $|A|+|B|$ as the length of the base? – Dilip Sarwate Apr 08 '23 at 13:56
  • @DilipSarwate The other stuff's a bit redundant but good point on signs - one could infer it from $T = A + B$ but explicit is better. – OverLordGoldDragon Apr 08 '23 at 14:08