You are on page 1of 62

See

discussions, stats, and author profiles for this publication at: https://www.researchgate.net/publication/264541246
Convolution Integrals with Nspire CAS
Conference Paper · July 2014
DOI: 10.13140/2.1.3153.2166
CITATIONS READS
0 2,532
2 authors, including:
Michel Beaudin
École de Technologie Supérieure
17 PUBLICATIONS 9 CITATIONS
SEE PROFILE
All content following this page was uploaded by Michel Beaudin on 07 August 2014.
The user has requested enhancement of the downloaded file.
ACA 2014
Applications of Computer Algebra
Session: Integration: implementation and applications
Fordham University
New York, NY, USA, July 9-12
Overview

• Introduction
• Convolution of two functions :
• Case of Laplace transforms
• Continuous LTI systems
• Computing the convolution
• Symbolic Convolution in Nspire CAS
• Conclusion

2
Introduction

Why this subject?


At the last ACA conference, we showed how
useful it was for a Computer Algebra System
(CAS) to perform symbolic integration of
Piecewise Continuous Functions (PCF) and
expressions containing such functions.
Sadly, Texas Instruments computer algebra
system Nspire CAS is able to deal with PCF but
presents some limitations.
3
Introduction

Let a PCF be defined over an interval (or the


entire real line) and be continuous over each sub-
interval. Here is what Nspire CAS does well :
• The symbolic derivative, the symbolic
indefinite integral and the symbolic definite
integral.
• The system correctly checks the endpoints
for the derivative and adjusts the constants
of integration for each sub-interval for the
integral. 4
Introduction

Here is an example.

Constants are added


to obtain a continuous
antiderivative.

Exact value.

5
Introduction

Function f(x) and definite integral:

6
Introduction

Important: a continuous antiderivative!

∫ f ( x) dx

y = f ( x)

7
Introduction

We just saw that Nspire CAS uses templates to


define piecewise functions.

These templates are attractive but some


limitations appear if one wants to perform more
complicated symbolic operations.

8
Introduction

As an example, we continue with our earlier


function y = f(x) and try to compute ∫ x f ( x) dx .
2

Unable to compute!

No exact value!

9
Introduction

Nspire CAS built-in integrator is unable to


perform the symbolic integration of a product of
a single expression with a piecewise function.

Furthermore, it only returns a floating point


approximation for the definite integral.

10
Introduction

This is why Frédérick Henri has programmed


some functions (showed last year at ACA).

With these functions (included in a special


library used by us at ETS), Nspire CAS is now
able to do all of this correctly!

11
Introduction

Here is a brief recap of how it works:


1. We group into a single piecewise function
an expression using the function
grouper_fct(ex, var) where ex is
an expression in variable var.

12
Introduction

Example of grouper_fct :

1, x > 3 − x, x > 0 sin( x), 0 < x < 2π


 × +
0, Else  x, Else cos( x), Else
 sin( x ) − x , 3 < x < 2π
 cos( x ) − x , 2π ≤ x < ∞


 sin( x ), 0 < x ≤ 3
cos( x ), −∞ < x ≤ 0 13
Introduction

2. We use the built-in integrator of Nspire


CAS to perform the integral.
Note that in the upcoming slide:
• kit_ETS_fh\integral_mcx(ex,
var) stands for the indefinite integral of
ex wrt to var.
• kit_ETS_fh\integral_mcx_d(ex,
var, lo, up) stands for the definite
integral of ex wrt var from lo to up.
14
Introduction

Nspire CAS built-in integrator.

Only a floating point approximation.

Symbolic piecewise antiderative!

Exact value!

15
Convolution of Two Functions

 Case of Laplace transforms


Usually, students are introduced to Laplace
transforms inside an ODE course.
Functions f(t) are defined for t ≥ 0 and the
Laplace transform of f is the function F defined
by the improper integral

F ( s ) = ∫ f (t ) e − st dt
0

16
Convolution of Two Functions

 Case of Laplace transforms


Let’s use the notation f (t ) ↔ F ( s) for the
correspondence between the function f(t) and its
transform F(s).
Note that f(t) is in fact f(t) u(t) where u(t) is the
unit-step function (Heaviside function):
0, t < 0
u (t ) = 
1, t > 0
17
Convolution of Two Functions

 Case of Laplace transforms


Then we have the “convolution property”
t
F ( s) G ( s) ↔ f (t ) ∗ g (t ) ≡ ∫ f (τ ) g (t − τ ) dτ
0

This last integral is called the convolution (in the


sense of Laplace transforms) of f and g.

18
Convolution of Two Functions

 Case of Laplace transforms


Note that it can be written in the more general
form

∫ x(τ ) h(t − τ ) dτ
−∞

if x(t) = f(t)u(t) and h(t) = g(t)u(t).

19
Convolution of Two Functions

 Case of Laplace transforms


Unfortunately, in a classical ODE course, few
words are said about convolution or the reasons
why it is important.

For simplicity, let’s take a linear second order,


constant coefficients ODE
a y′′(t ) + b y′(t ) + c y (t ) = x(t ) ⋅ u (t ), y (0) = 0, y′(0) = 0

20
Convolution of Two Functions

 Case of Laplace transforms


Then the solution of
a y′′(t ) + b y′(t ) + c y (t ) = x(t ) ⋅ u (t ), y (0) = 0, y′(0) = 0
is given by the convolution y (t ) = x(t ) ∗ h(t )
where 1
h(t ) ↔ H ( s ) ≡
a s2 + b s + c
h(t) is known as the impulse response and H(s)
as the transfer function.
21
Convolution of Two Functions

 Case of Laplace transforms


Usually, the ODE represents a damped mass-
spring problem or a RLC circuit problem.
In this case, the coefficients a, b and c are
positive and there is no loss of generality taking
zero initial conditions since the transient solution
dies out.
So, the convolution solves the ODE.

22
Convolution of Two Functions

 Continuous LTI systems


We now consider a (continuous) system
x(t) SYSTEM y(t)

where an input x(t) enters the system and an


output y(t) is produced. Some examples:
y (t ) = x 4 (t ), y (t ) = 5 x(2t + 1) + 10
d
y (t ) = cos( x(t )), y (t ) = ( x(t ) )
dt
t
y (t ) = ∫ x(τ ) dτ
−∞ 23
Convolution of Two Functions

 Continuous LTI systems


Another example is a mass-spring system: the
external force f(t) is the input (f(t) = 0 if t < 0)
and the position y(t) of the object at time t is the
output.
The following ODE is the model used:
m ⋅ y′′(t ) + b ⋅ y′(t ) + k ⋅ y (t ) = f (t ), y (0) = 0, y′(0) = 0

Constant of friction
Mass of the object
Spring constant 24
Convolution of Two Functions

 Continuous LTI systems


Let the input x1 (t ) produce the output y1 (t ) and let
the input x2 (t ) produce the output y2 (t ) .
The system is linear if the linearly combined
input
x(t ) = a ⋅ x1 (t ) + b ⋅ x2 (t )
produces the linear combined output
y (t ) = a ⋅ y1 (t ) + b ⋅ y2 (t )
25
Convolution of Two Functions

 Continuous LTI systems


Let the input x(t) produces the output y(t), let a
be any real number.
The system is time-invariant if the shifted output
y(t − a) is the same as the output produced by the
shifted input x(t − a).
That is:
S(x(t)) = y(t) S(x(t − a)) = y(t − a)

26
Convolution of Two Functions

 Continuous LTI systems


The system is said linear, time-invariant (LTI) if
both conditions are satisfied.
Example: consider again the capacitor as a
system. When a current i(t) passes through the
capacitor C, the voltage across the capacitor is
t
1
v(t ) = ∫ i (τ ) dτ
C −∞
27
Convolution of Two Functions

 Continuous LTI systems


This is a linear system because of the linearity
of the integral. The system is also time-invariant
as a change of variable shows it.

t t −a
1 1

C −∞
i (τ − a ) dτ =
C ∫ i(τ ) dτ = v(t − a)
−∞

28
Convolution of Two Functions

 Computing the convolution


In signal analysis courses, students learn how to
compute by hand the convolution of two signals.
They are introduced to important functions such
as unit step function u(t) and unit-impulse (Dirac
delta) “function” δ(t). But there is no need to
deal with the theory of generalized functions.

29
Convolution of Two Functions

 Computing the convolution


Instead, they are using limiting process. The
Dirac delta “function” is replaced by an
approximate unit-impulse function:
 1
δ (t ) = ( u (t ) − u (t − ∆) )

In Derive, this is nothing else than
1 1
( STEP(t ) − STEP(t − ∆) ) = CHI ( 0, t , ∆ )
∆ ∆
30
Convolution of Two Functions

 Computing the convolution


Given a system, the output to the unit-impulse
δ(t) is called the system impulse response h(t).
Fact: in a continuous LTI system, the output y(t)
to the input x(t) is given by the convolution

y (t ) = ∫ x(τ )h(t − τ ) dτ
−∞

31
Convolution of Two Functions

 Computing the convolution


This is easy to justify. The signal x(t) is replaced
by a staircase approximation and a limit:

x (t ) = ∑ x(k ∆) δ (t − k ∆) ∆
k =−∞

x(t ) = lim x (t ) =
∆→0 ∫ x(τ ) δ (t − τ ) dτ
−∞

If h (t ) is the output to δ (t ) , then the linearity of


the integral and time invariance yields the result. 32
Convolution of Two Functions

 Computing the convolution


Suppose you want to perform a convolution:

y (t ) = ∫ x(τ )h(t − τ ) dτ
−∞
Then, 4 steps must be completed :
• reverse the time in the signal h;
• shift the variable;
• multiply by the signal x;
• integrate over all values of τ, doing this for
every value of t. 33
Convolution of Two Functions

 Computing the convolution


For example, the convolution of two rectangular
pulses of finite (but different) duration is a
trapezoidal signal: Convolution of
x(t) and h(t).

Let’s switch to Nspire CAS and show an


animation of this. 34
Convolution of Two Functions

 Computing the convolution


Derive can easily perform the last convolution
because of its ability to integrate piecewise
functions.
Even though the Dirac delta function has never
been implemented into Derive, we can compute
symbolic limits involving indicator functions.
So we can use impulse functions!

35
Convolution of Two Functions

 Computing the convolution


Let us show a Derive screen where the
convolution is defined.
Then we will show the convolution of the two
rectangular pulses x(t) = CHI(0, t, 1) and h(t) =
1.5CHI(0, t, 2).
In Derive, CHI(a, x, b) is the indicator function
of the open interval a < x < b. The notation is
χ(a, x, b).
36
Convolution of Two Functions

 Computing the convolution


Finally, we will illustrate the fact that the
convolution with the shifted Dirac delta function
δ(t − a) produces a translation on a signal x(t):

x(t ) ∗ δ (t − a ) = x(t − a )

The next slide shows this with a = 1.

37
Convolution of Two Functions

It is so easy to define a convolution of 2


signals in Derive!

We take 2 rectangular pulses, using the


indicator function χ of Derive.

Here is the
result and the
graph.

Now we convolve the « output » with δ(t − 1),


using a limit of indicator function: this produces, as
expected, a translation of the signal « output ». 38
Symbolic Convolution in Nspire CAS

We know Nspire CAS can’t simplify the product


of a piecewise expression with another
expression.
So, if x(t) is piecewise with compact support, the
integral of x(t) with another expression only
yields a floating point value. The next slide
illustrates this.

39
Symbolic Convolution in Nspire CAS

Here is, again, an example.

No exact value.

Exact value!

Now let’s try to perform the convolution of x(t)


and h(t). 40
Symbolic Convolution in Nspire CAS

Nspire CAS built-in integrator won’t succeed …

Oups…!

41
Symbolic Convolution in Nspire CAS

… neither will Frédérick’s function!

42
Symbolic Convolution in Nspire CAS

So, what can we do?

Our goal is to find a way for Nspire CAS to


compute the symbolic convolution without
giving up the use of templates.

As far as integration is concerned, endpoints of


each subinterval are irrelevant.
43
Symbolic Convolution in Nspire CAS

Here is what we will do:


1. Convert a piecewise function into a linear
combination of signum functions.
2. Import from Derive a very important rule:

44
Symbolic Convolution in Nspire CAS

3. Perform the symbolic integration of each


term.
4. Convert the result into a piecewise
expression (if applicable).
5. Moreover, if one needs to use a Dirac delta
function, it should be possible to achieve,
using limit of indicator functions.

45
Symbolic Convolution in Nspire CAS

Note : the rule

yields a continuous antiderivative. Here is why.


Let G(x) be an antiderivative of F(x). Consider
the function “Albert”:
  b 
Albert( x) := SIGN(ax + b)  G ( x) − G  −  
  a 
This function is everywhere continuous and
differentiable except at the point x = −b/a. 46
Symbolic Convolution in Nspire CAS

The derivative of SIGN(ax + b) is 0 except at x =


−b/a. So, for x ≠ −b/a,
d   b 
Albert( x) = 0 ⋅  G ( x) − G  −   + SIGN(ax + b) ( F ( x) − 0 ) = SIGN(ax + b) F ( x).
dx   a 
For x ≠ −b/a, Albert(x) is continuous
everywhere because SIGN and G are continuous.
If x = −b/a, it is also continuous because SIGN is
a bounded function:
  b 
lim SIGN(ax + b)  G ( x) − G  −   = 0
x →−
b
  a 
a
47
Symbolic Convolution in Nspire CAS

New functions were defined and saved in an


updated version of the library Kit_ETS_FH.

Frédérick Henri took care of the programming


side of the job and Michel Beaudin took care of
the mathematical requests.

Here is a description of the principal functions.


48
Symbolic Convolution in Nspire CAS

The sign function is already implemented into


Nspire CAS. We have defined the unit step function
and the piecewise indicator function of the interval
]a, b[:
1 + sign( x)
step( x) :=
2
chi(a, x, b) := step( x − a ) − step( x − b)
Frédérick’s function unpiece transforms a
piecewise function into a linear combination of
indicator functions. The inverse is achieved with the
function signtopiece.

49
Symbolic Convolution in Nspire CAS

Here are some examples:


We add the « step » function.

We add the indicator function and


call it « chi ».
We « unpiece ».

We« convert »
to piecewise.

« grouper_fct »
finishes the job.
50
Symbolic Convolution in Nspire CAS

Nspire CAS is now able to do as Derive when


comes time to integrate a product of sign with
another expression. In fact, Frédérick has
programmed the function integral_sign in
order to compute the integral of expressions as
sign(ax + b)·f(x).
For more complicated examples, expansion is
used and the function integral2 does the job.
Let’s take a look at an example.
51
Symbolic Convolution in Nspire CAS

Nspire built-in integrator.

Frédérick’s function!

It is the same!

Derive built-in integrator.

The answer would be different if sign(2x−5) was


factored out first; the 2 answers would differ by
a constant, as for primitives.
52
Symbolic Convolution in Nspire CAS

Now, let be given 2 piecewise continuous


signals, say x(t) and h(t). We “unpiece” the
product x(τ)h(t − τ). This become a linear
combination of sign functions and we integrate
it using the new integral2 function. The
antiderivative is then evaluated between ∞ and
−∞. This yields the convolution of x and h. The
function convol_gen does the job.

53
Symbolic Convolution in Nspire CAS

If the answer is a linear combination of absolute


values expressions, our function
conv_abs_to_p converts it into a piecewise
function. Let’s give a concrete example, taking
the two earlier rectangular pulses:
0, t < 0
0, t < 0 3
 
x(t ) = 1, 0 < t < 1, h(t ) =  , 0 < t < 2
0, t > 1 2
 0, t > 2
54
Definition of
both signals.
Convolution of
both signals.
Conversion to a
piecewise function.

Simplification of the
answer and its graph.

55
Symbolic Convolution in Nspire CAS

Finally, the convolution of this output


trapezoidal signal with δ(t − 1) should produce a
translation of one unit on the right: that is the last
trapezoidal output should move one unit to the
right.
Again, we will use a limit of indicator function
in order to use a Dirac delta function.

56
Symbolic Convolution in Nspire CAS

The 2 signals.

We call the convolution of


the 2 signals « output ».

We take an approximate
unit-impulse.

The convolution of « output » with the


approximate unit-impulse is a huge expression!
But we know we will take the limit of this.
57
Symbolic Convolution in Nspire CAS

And the limit is exactly what we are expecting.


The graph is the trapezoidal signal moved one
unit to the right.

58
Conclusion

In 2006, at the beginning of Nspire CAS,


Bernhard Kutzler proclaimed it as the “true
successor of Derive”. Albert Rich would have
disagreed…

Michel Beaudin, with the help of Frédérick


Henri, wants to make Bernhard’s affirmation
come true. But there is a lot more to be done, as
far as the CAS part of the system is concerned.
59
Conclusion

This represents a fantastic opportunity to do


mathematics and to discover, day after day, how
Derive was special.

Helping Nspire CAS to become more powerful


(in the CAS sense) represents my contribution to
a product that gave me a lot of enthusiasm for
the past 15 years!
60
61
View publication stats

You might also like