Okay, now let's see how you can use those building blocks to perform

a very simple operation, on a sequence, computing the moving average.

The simple average of two numbers, well we don't need to define it,

it's simply the sum, of the two numbers, divided by two.

A moving average, is a local average,

that you perform, every step of the way in a sequence.

So you take the current sample, you take the previous sample,

you sum them together, and you divide by two.

How would you implement this?

So here we could write some lines of code in your favorite programming languages but

instead, we will use the graphical notation that we have introduced before.

We will use these building blocks these mechaniblocks so

that the structure shows you an abstract implementation of the algorithm

that you can then convert to your favorite language.

This is a very powerful descriptive paradigm for

signal processing that we will use all through the course.

So here's how we would represent the moving average with building blocks.

Remember y of n is equal to x of n + x of n- 1, divided by two.

So here we have x of n, okay?

Here we have an adder.

We need to get x of n minus one.

We get that by a delay operator.

So outside here, so x of n c goes in here.

Here we get x of n- 1.

We put it here, x of n also goes through here.

Here is the sum of the two.

And here we multiply by 1/2 and here we have the output.

Okay, so this is the representation with building blocks of the moving average.

Let's apply this to a signal and see how that works.

Let's pick the simplest possible discreet time signal, the delta sequence,

which is 0 everywhere except for N = 0, where the value is one.

If we apply the moving average to the signal, well nothing really happens before

N reaches zero because for all negative values of N, the input is zero and

the average of two zeros will be zero.

When N is equal to zero, then we have that y of zero

will be equal to x of zero + x of zero- 1 divided by 2.

So, x of zero, we know is equal to one, x of minus one is equal to zero, and so

this is equal to 1/2 and end 0., the output would be equal to 1/2.

In 1, y of 1 will be equal to x of 1 plus

x of 1 minus 1, 0 divided by 2.

And again this is equal to 0, this is equal to 1 and

this will be equal to one half.

And then for all values of n greater than one,

we will have the two inputs that we use in the average are zero and

so the output will be identical to zero for eternity.

Another example the unit step.

What happens here is that again nothing happens for

the negative values of the index.

The first time something moves is when n is equal to 0 at which point the first

output sample will be exactly like in the case of the delta sequence.

The average of 0 here and 1 here.

And we will get one half.

Then for n equal to 1 onwards, we will be averaging two equal values and

so of course the average will be equal to the value itself.

And we will have one for all values of the index greater than one.

Let's now try to compute the moving average of a sinozoid,

here we have cos(omega n) with omega = pi/10.

But the frequency is in, to see what the moving average of this signal is,

we will have to use a little bit of trigonometry.

In general, the output will be equal to cos of omega n- cos omega( n- 1) / 2.

We can use trigonometric formulas to show that this is equal to

show that this is equal to cos(omega n) + face term theta.

So surprisingly, the output of the moving average applied to a sinusoid is

a sinusoid at the same frequency of the, just a phase turn is added.

This is actually a general result that holds whenever we apply a linear

transformation to a sinusoidal input.

Another sequence could be the alternating sequence where we switch continuously

between plus one and minus one.

At this point, when we average,

we're always doing a local average of two values with opposite signs so they're

average will be zero and therefore the output sequence will be identically zero.

Okay, so the moving average is a very simple piece of circuitry.

But remember it's like the Meccano toy, so we can take these pieces and

change the way we combine them.

So a legitimate question is, what happens if here we reverse the loop?

You can see here in the flow of signals in the moving average circuitry,

everything moves forward, okay?