# Question:Computation of sliding average of a signal

## Question:Computation of sliding average of a signal

Maple

I'm trying to compute a sliding average for a pulse width modulated signal. The code starts with an example for a signal x.

---

`x:=10+1.5*t+3*sin(30*t+2);   #This is an example signal`

`X_avg:=1/0.5*int( eval(x,t=tau), tau=(t-0.5)..t );   #This is the computation of the sliding average over a period of 0.5`

---

This works fine as in the following figure.

Now I try to create a pulse width modulated (PWM) signal with a duty cycle D_ and a triangular carrier signal as in the following

---

`with(DynamicSystems):`

`s__TR := Triangle(1, 20e3, 1/2, 0, 0, hertz = true); `

`s__PWM := 1/2*( 1+signum( D_ - s__TR ) );`

---

This creates the PWM signal as expected and seen in the following figure.

However, when I ask Maple to compute the sliding average of s__PWM as in the following, it gives me an answer based on the integral. But then when I ask it to plot the result it starts computation and never stops.

---

`s__avg := evalf( f*Int( evalf(eval(s,[t=tau])) , tau = (t-1/f)..(t) ) );`

`plot([ eval(s__TR,[f=20e3]), eval(s__SQ1,[f=20e3,D_=0.2]), eval(s__avg,[f=20e3,D_=0.2]), 0.2], t=0..200e-6, color=[blue,red,green, cyan], legend=["Triangular carrier","PWM signal", "Sliding average", "Duty cycle"]);`

---

I've attached a file with the Maple code.

Anybody could help me with suggestions/corrections?

﻿