1
00:00:00,880 --> 00:00:03,240
This might have all sounded
a little bit dry so far,

2
00:00:03,240 --> 00:00:05,730
so let's become much more concrete.

3
00:00:05,730 --> 00:00:08,780
So before delving into
the mathematics of signal processing,

4
00:00:08,780 --> 00:00:12,500
we are going to construct
a simple motivating example.

5
00:00:12,500 --> 00:00:17,160
So a way to do this, is we are going to
look at simple operators, like sums and

6
00:00:17,160 --> 00:00:21,220
multiplications, and the elements that
we're going to build together to build,

7
00:00:21,220 --> 00:00:24,680
for example, a moving average or
a recursive filter.

8
00:00:24,680 --> 00:00:27,840
So recursive filter, it turns out,
is exactly what happens into your

9
00:00:27,840 --> 00:00:30,830
bank account as you only need
to have some money left.

10
00:00:30,830 --> 00:00:32,680
After we have these simple operators,

11
00:00:32,680 --> 00:00:36,940
we are going to build a music synthesizer
based on the corpus strong algorithm and

12
00:00:36,940 --> 00:00:39,109
actually going to listen
to some computer music.

13
00:00:41,550 --> 00:00:45,870
Before delving into the mathematics of
signal processing, let us do a simple and

14
00:00:45,870 --> 00:00:46,910
motivational exam.

15
00:00:46,910 --> 00:00:49,860
We will see that there
are simple primitives

16
00:00:49,860 --> 00:00:53,390
that can be used to build interesting
signal processing devices.

17
00:00:54,670 --> 00:00:59,690
After building up the basic blocks,
based on usual notions like averages,

18
00:00:59,690 --> 00:01:03,330
moving average, and bank account returns,

19
00:01:03,330 --> 00:01:07,710
yes indeed we shall construct
a simple music synthesizer

20
00:01:07,710 --> 00:01:11,740
know as the Karplus-Strong Algorithm,
and then listen to it.

21
00:01:13,190 --> 00:01:15,530
The menu is therefore the following.

22
00:01:15,530 --> 00:01:21,000
First, we look at digital signal
processing as Lego blocks.

23
00:01:21,000 --> 00:01:25,410
So we'll see fundamental building
blocks and how to put them together.

24
00:01:25,410 --> 00:01:28,300
From there we go to moving averages,

25
00:01:28,300 --> 00:01:32,720
which is an extension of the usual
averages that we all know.

26
00:01:32,720 --> 00:01:35,330
Then we shall look at recursion, and

27
00:01:35,330 --> 00:01:40,240
the best way to learn about it,
is to revisit your bank account and

28
00:01:40,240 --> 00:01:45,710
how it wells goes up and
down depending on returns.

29
00:01:45,710 --> 00:01:50,220
With this example in hand, we can
build a simple recursive synthesizer.

30
00:01:51,340 --> 00:01:54,380
Once built,
we can actually listen to actual sounds.

31
00:01:55,580 --> 00:01:56,160
Okay.

32
00:01:56,160 --> 00:02:00,250
So, let's think as digital
signal processing as a Lego set.

33
00:02:01,310 --> 00:02:04,100
So we have blocks, various colors,
various shapes, but

34
00:02:04,100 --> 00:02:07,120
they all fit together as
seen on the left side.

35
00:02:08,340 --> 00:02:14,580
On the right side, you see a block diagram
of a basic signal processing device.

36
00:02:14,580 --> 00:02:18,430
This will turn out to be a filter,
but this you'll see later.

37
00:02:18,430 --> 00:02:19,950
You can see there are blocks,

38
00:02:19,950 --> 00:02:24,920
there are arrows, there are adders,
there are multipliers, and so on.

39
00:02:24,920 --> 00:02:30,900
And in input x[n], a sequence of
numbers gets transformed in to y[n],

40
00:02:30,900 --> 00:02:32,410
another sequence of numbers.

41
00:02:33,480 --> 00:02:37,430
So, what is a basic building
block like an adder?

42
00:02:37,430 --> 00:02:42,120
It takes two signals, two sequences,

43
00:02:42,120 --> 00:02:45,690
x and y absent together x + y.

44
00:02:45,690 --> 00:02:47,100
In the diagrammatic forms,

45
00:02:47,100 --> 00:02:52,550
we see two signals at the bottom left,
added together they add to a constant,

46
00:02:52,550 --> 00:02:56,730
because one goes down linearly,
the other one grows linearly.

47
00:02:57,840 --> 00:02:59,940
How about the multiplier?

48
00:02:59,940 --> 00:03:07,810
It is denoted simply by variable, in this
case alpha, that is put next to an arrow.

49
00:03:07,810 --> 00:03:11,550
So X gets transformed into alpha times X.

50
00:03:11,550 --> 00:03:12,690
Again, an example.

51
00:03:12,690 --> 00:03:17,180
We have the same descending
signal multiplied by one half.

52
00:03:18,220 --> 00:03:21,358
It has the same shape but
it is scaled by one half.

53
00:03:21,358 --> 00:03:25,140
So delay is denoted by Z minus 1.

54
00:03:25,140 --> 00:03:29,220
We will see why is this
notation shows up later but for

55
00:03:29,220 --> 00:03:35,350
now simply think that a sequence
XN is shifted in time.

56
00:03:35,350 --> 00:03:41,592
Shifted to the right,
therefore it is denoted as X of N minus 1.

57
00:03:41,592 --> 00:03:46,566
Again, we take our usual signal,
the descending linear signal, and

58
00:03:46,566 --> 00:03:48,220
shift it by one.

59
00:03:48,220 --> 00:03:50,460
Sure enough,
instead of starting at the origin,

60
00:03:50,460 --> 00:03:53,740
it will start at time instant number one.

61
00:03:55,500 --> 00:03:59,930
If we know how to delay by one,
we can certainly also delay by N.

62
00:03:59,930 --> 00:04:05,200
This is denoted by x[n] becoming x[n- N].

63
00:04:05,200 --> 00:04:11,640
Let us look at our usual signal and
delayed by an integer N is equal to 4.

64
00:04:11,640 --> 00:04:16,830
Now, instead of starting at the origin, it
will start at the integer N is equal to 4.

65
00:04:16,830 --> 00:04:21,680
No that we have building blocks
let's create some operators.

66
00:04:21,680 --> 00:04:25,570
So, first operator that we
shall look at is the average.

67
00:04:25,570 --> 00:04:28,920
Or is a simple average that
everybody is familiar with.

68
00:04:28,920 --> 00:04:35,065
For example in Switzerland, the average
number of children per woman is 1.42.

69
00:04:35,065 --> 00:04:40,710
You probably have to worry about the
famous infamous GPA, Grade point average.

70
00:04:40,710 --> 00:04:43,283
Here we are concerned
about moving averages.

71
00:04:43,283 --> 00:04:48,480
That these we compute the local average
of a sequence as we go along the simple

72
00:04:48,480 --> 00:04:55,160
case is 2 point moving average
denoted by XN plus Xn minus one

73
00:04:55,160 --> 00:05:00,480
divided my two so we take two
neighboring samples of the sequence and

74
00:05:00,480 --> 00:05:06,570
we take their average which now will
changed over time as it depends on end.

75
00:05:06,570 --> 00:05:10,490
We can build this using
the Lego blocks from earlier.

76
00:05:10,490 --> 00:05:13,660
So on the left we have the input Xn.

77
00:05:13,660 --> 00:05:16,250
It is delayed by Z minus one.

78
00:05:16,250 --> 00:05:21,760
It is added and then multiplied by one
half to result in the moving average

79
00:05:21,760 --> 00:05:28,050
Y N is equal to X N plus X N minus
one Is the sum divided by two.

80
00:05:28,050 --> 00:05:29,430
Let's look at this.

81
00:05:29,430 --> 00:05:33,990
For a very simple signal, this is
the delta sequence, which is equal to one.

82
00:05:33,990 --> 00:05:35,100
That's the origin.

83
00:05:35,100 --> 00:05:37,220
Zero everywhere else.

84
00:05:37,220 --> 00:05:41,720
So moving average will be zero
everywhere except at the origin and

85
00:05:41,720 --> 00:05:45,520
at location one,
where it is equal to one half.

86
00:05:45,520 --> 00:05:52,150
Another typical signal is the step
sequence, which is zero for negative time,

87
00:05:52,150 --> 00:05:57,230
equal to 1 for n is equal to
zero to infinity, denoted by un.

88
00:05:58,820 --> 00:06:00,940
What will the moving average look like?

89
00:06:00,940 --> 00:06:03,970
For negative indices, it will be zero.

90
00:06:03,970 --> 00:06:09,910
For 0 it will be one-half,
because it's the average of 0 and 1.

91
00:06:09,910 --> 00:06:13,840
For 1 it is the average of 0 and
1, so it is equal to 1.

92
00:06:13,840 --> 00:06:17,040
And ever after it is
equal to the constant 1.

93
00:06:17,040 --> 00:06:21,810
If we take a more complex signal,
like a cosine function,

94
00:06:21,810 --> 00:06:25,770
cosine omega of n,
where omega is picked here as pi over 10.

95
00:06:25,770 --> 00:06:31,780
Then, you can see the signal on the left,
and its average on the right.

96
00:06:31,780 --> 00:06:33,740
It doesn't seem to have changed very much.

97
00:06:33,740 --> 00:06:37,950
If you look carefully,
you will see that the 0 crossing

98
00:06:37,950 --> 00:06:42,580
at n is equal to 5 has disappeared,
because of the moving average.

99
00:06:42,580 --> 00:06:47,100
But, the basic frequency, as we shall
discover, is actually still present.

100
00:06:47,100 --> 00:06:49,200
It is pi over ten.

101
00:06:49,200 --> 00:06:53,640
Now, if we take a very high frequency,
omega is equal to pi.

102
00:06:53,640 --> 00:06:59,340
So, cosine of omega times n or
cosine of pi times n.

103
00:06:59,340 --> 00:07:03,430
The sequence is alternating
between plus one and

104
00:07:03,430 --> 00:07:05,930
minus one as you can see on the left side.

105
00:07:07,020 --> 00:07:10,130
If we take the average, nothing comes out.

106
00:07:10,130 --> 00:07:13,325
Because every time you take an average,
it's the average between plus and

107
00:07:13,325 --> 00:07:15,265
minus one, which is zero.

108
00:07:15,265 --> 00:07:19,255
Therefore, here we have a very different
behavior from the previous cause line,

109
00:07:19,255 --> 00:07:21,915
thinks an input that
is different from zero

110
00:07:21,915 --> 00:07:26,715
is resulting in an output that
is exactly equal to zero.

111
00:07:26,715 --> 00:07:32,495
Now, a natural question will be what if we
reverse the loop of the moving average?

112
00:07:32,495 --> 00:07:38,770
So, let's look at the block diagram again,
and turn around the arrow

113
00:07:38,770 --> 00:07:43,990
instead of going forward, going backwards
still is a factor alpha and an other.

114
00:07:45,160 --> 00:07:48,300
This turns out to be
a very different object.

115
00:07:48,300 --> 00:07:53,290
At first, it looks very similar,
but it will be obvious that

116
00:07:53,290 --> 00:07:59,060
a single input different from zero
will in generate an infinite output.

117
00:07:59,060 --> 00:08:02,260
Which is certainly not
the case of a moving average.

118
00:08:02,260 --> 00:08:06,710
To study this, we will go back to
something we are all very familiar with.

119
00:08:06,710 --> 00:08:13,420
It's a simple equation that will describe
the value present in your bank account.

120
00:08:13,420 --> 00:08:15,240
Let's assume the following things.

121
00:08:15,240 --> 00:08:19,350
You have a constant interest
rate of 5% per year.

122
00:08:19,350 --> 00:08:24,160
Assume you put or take money
only once a year on January 1st.

123
00:08:25,590 --> 00:08:28,490
Interest for
a positive balance or charges for

124
00:08:28,490 --> 00:08:31,995
a negative balance
are calculated on December 31st.

125
00:08:31,995 --> 00:08:35,255
They are added January 1st
of the following year.

126
00:08:35,255 --> 00:08:38,660
So call x[n] as input, adding or

127
00:08:38,660 --> 00:08:42,780
subtracting from the bank
account no January 1 of year n.

128
00:08:42,780 --> 00:08:47,610
Call y[n] the content of your
account on December 31st of year n.

129
00:08:48,670 --> 00:08:56,483
Then it is not hard to see that
y[n] is equal to 1.05y[n-1].

130
00:08:56,483 --> 00:09:00,620
That is, so 5% is your borrowing rate or

131
00:09:00,620 --> 00:09:05,665
interest rate on the content of your
bank account the previous year plus

132
00:09:05,665 --> 00:09:11,400
xn which is what you put in at
the first of January of the year.

133
00:09:11,400 --> 00:09:17,450
This recursive equation can be depicted
in a block diagram as shown now.

134
00:09:17,450 --> 00:09:19,750
So xn enters.

135
00:09:19,750 --> 00:09:21,550
It is added to 1.05.

136
00:09:21,550 --> 00:09:26,470
The previous content
which is y of n minus 1.

137
00:09:26,470 --> 00:09:30,740
This is a feedback loop which
is a delay element z minus 1.

138
00:09:30,740 --> 00:09:34,070
This added together indeed
gives the output yn.

139
00:09:35,250 --> 00:09:42,960
So to make clear, y n is equal
to 1.05 y of n minus 1 plus x n.

140
00:09:42,960 --> 00:09:44,910
Let's look at a few examples.

141
00:09:44,910 --> 00:09:47,050
Let's take a one time investment.

142
00:09:47,050 --> 00:09:53,130
So x n is equal to 100 times 0 and
0 everywhere else.

143
00:09:53,130 --> 00:09:56,020
So we can calculate this by
hand just to get the feeling.

144
00:09:56,020 --> 00:10:00,803
Y[0] will be equal to 100, because
that is what is put into the account.

145
00:10:00,803 --> 00:10:03,472
y[1] will be 105.

146
00:10:03,472 --> 00:10:07,559
y[2] will be 110.25.

147
00:10:07,559 --> 00:10:10,833
That's 1.05 square times 100.

148
00:10:10,833 --> 00:10:15,620
y[3] is something of the order of 115 and
so on.

149
00:10:15,620 --> 00:10:21,440
If we depict this, then we see that
your wealth is slowly increasing.

150
00:10:21,440 --> 00:10:25,030
Actually not that slowly because it turn
out that it's actually an exponential.

151
00:10:25,030 --> 00:10:31,100
So in general, y[n] is equal to
1.05 at the power of N times 100.

152
00:10:31,100 --> 00:10:33,640
Let's look at the second example.

153
00:10:33,640 --> 00:10:35,260
Let's take a saver.

154
00:10:35,260 --> 00:10:43,495
So the saver puts 100 every year
after the origin of time that is 0.

155
00:10:43,495 --> 00:10:47,565
The solution to this difference
equation is not obvious.

156
00:10:47,565 --> 00:10:50,645
We will be able to write it down
after we have learned some basic

157
00:10:50,645 --> 00:10:52,665
tools about difference equations.

158
00:10:52,665 --> 00:10:55,759
But we can calculate a few points.

159
00:10:55,759 --> 00:10:57,244
So Y over Z for example is a hundred.

160
00:10:57,244 --> 00:11:02,405
Y of one is 205, Y of 2 is 315.25,

161
00:11:02,405 --> 00:11:07,299
Y of 3 is of the order of 430 etcetera.

162
00:11:07,299 --> 00:11:08,780
So we can plot this.

163
00:11:08,780 --> 00:11:12,550
And now we see that it something that
goes faster than the linear growth.

164
00:11:12,550 --> 00:11:15,160
Why?
Because there is compound interest.

165
00:11:15,160 --> 00:11:20,220
The result of the different equation
is YN is equal to 2000(1.05) to

166
00:11:21,360 --> 00:11:24,676
the power of (n+1)-1.

167
00:11:24,676 --> 00:11:29,638
Let's look at the third example,
the independently wealthy person.

168
00:11:29,638 --> 00:11:35,130
So x[n] is obtained the following way,

169
00:11:35,130 --> 00:11:41,400
you put 100 times 0 and
then you take the interest out every year.

170
00:11:41,400 --> 00:11:45,460
So the interest is 5%, so 5% of 100 is 5.

171
00:11:45,460 --> 00:11:52,153
And we have 0.5 times
u[n-1] that comes up.

172
00:11:52,153 --> 00:11:57,958
The interesting thing is that now y,
the output, keeps constant.

173
00:11:57,958 --> 00:12:01,440
It's 100 times zero, this we know,
that's what we put in.

174
00:12:01,440 --> 00:12:06,372
And then when we thought it went up
to 105, we take out five, and so

175
00:12:06,372 --> 00:12:07,831
it stays at 100.

176
00:12:07,831 --> 00:12:13,690
And so the output is perfectly
constant from zero to infinity.

177
00:12:13,690 --> 00:12:16,450
We can now generalize this a little bit.

178
00:12:16,450 --> 00:12:22,120
We put a delay by capital M,
and we put the factor alpha.

179
00:12:23,350 --> 00:12:31,440
So y[n] is equal to alpha time
y[n- M] plus the input x[n].

180
00:12:31,440 --> 00:12:35,890
We are engineers so we like to choose
alpha smaller or equal to one.

181
00:12:36,910 --> 00:12:38,960
This is quite different from economists.

182
00:12:38,960 --> 00:12:43,416
We had just seen the previous
examples where alpha was 1.05.

183
00:12:43,416 --> 00:12:44,780
Let's make an example.

184
00:12:44,780 --> 00:12:51,250
Let's take M is equal 3,
alpha is equal to 0.7 and as an input,

185
00:12:51,250 --> 00:12:56,000
our usual signal, which is equal to
1 at the origin, 0 everywhere else.

186
00:12:57,480 --> 00:12:59,490
We can calculate easily
what's going to happen.

187
00:12:59,490 --> 00:13:04,960
For the first instance,
y(0) is equal to 1, then it is zero for

188
00:13:04,960 --> 00:13:09,173
two instances,
then it's equal to 0.7, etcetera.

189
00:13:09,173 --> 00:13:13,130
If we plot this,
we see something that is almost periodic.

190
00:13:13,130 --> 00:13:19,033
Namely of period three, except that
the decay is slowly, as power of 0.7.

191
00:13:19,033 --> 00:13:23,686
If we put more interesting signals,
that's a little ramp here,

192
00:13:23,686 --> 00:13:28,761
which starts equal to one at zero,
equal to two at two, equal to three at

193
00:13:28,761 --> 00:13:34,200
instant two and we put it as an input,
then we truly see the repetition.

194
00:13:34,200 --> 00:13:37,090
So, alpha here was chosen equal to one.

195
00:13:37,090 --> 00:13:39,230
So there is no decay in the signal.

196
00:13:39,230 --> 00:13:43,620
It simply repeats one period,
this period from zero to two.

197
00:13:43,620 --> 00:13:47,673
Therefore, we have seen that
the M-tap delay essentially

198
00:13:47,673 --> 00:13:51,100
generates an M-sample periodicity.

199
00:13:51,100 --> 00:13:55,850
If we want to play music with this,
we need to associate a time period, T,

200
00:13:55,850 --> 00:13:58,270
to sample intervals.

201
00:13:58,270 --> 00:14:02,255
The periodic signal of frequency, f,

202
00:14:02,255 --> 00:14:06,842
will be in hertz, a frequency 1/MT, so for

203
00:14:06,842 --> 00:14:12,516
example, if T = 22.7 microseconds,
M = 100,

204
00:14:12,516 --> 00:14:20,153
then the frequencies that these
generate will be of the order of 440Hz.

205
00:14:20,153 --> 00:14:21,628
Let us look at this.

206
00:14:21,628 --> 00:14:27,026
So for example, if you want to play a sine
wave, M = 100 Alpha is equal to one.

207
00:14:27,026 --> 00:14:31,270
X n is equal to one period of a sine wave.

208
00:14:31,270 --> 00:14:33,630
Sine of two pi times N over a hundred.

209
00:14:34,660 --> 00:14:39,105
And then this will be nicely
repeated by our recursive loop and

210
00:14:39,105 --> 00:14:45,645
generate a sine wave that is indeed
equal to a 440 hertz sine wave.

211
00:14:45,645 --> 00:14:50,530
Let us now listen to a sine
wave of frequency 440 hertz.

212
00:14:50,530 --> 00:14:56,099
[SOUND] So we have seen that
M controls the frequency,

213
00:14:56,099 --> 00:15:00,415
or what's called in music, the pitch.

214
00:15:00,415 --> 00:15:04,350
To imitate the violin,
we need to go beyond the single sine wave.

215
00:15:04,350 --> 00:15:07,140
A crude approximation
is a triangular wave.

216
00:15:07,140 --> 00:15:09,740
We can change the pitch by changing M.

217
00:15:09,740 --> 00:15:13,948
We can simulate the decay by
choosing alpha smaller than one.

218
00:15:13,948 --> 00:15:15,410
Let's look at an example.

219
00:15:15,410 --> 00:15:17,687
M is equal to 100 again.

220
00:15:17,687 --> 00:15:20,868
Alpha is equal 0.95.

221
00:15:20,868 --> 00:15:25,360
Xn is one period or
a 0 mean triangular wave.

222
00:15:26,520 --> 00:15:29,930
Sure enough,
if we put this into our recursive loop,

223
00:15:29,930 --> 00:15:35,160
it will generate a sequence of
triangular waves that slowly decay

224
00:15:35,160 --> 00:15:39,490
with 0.95 to the power of
the number of periods.

225
00:15:39,490 --> 00:15:44,950
Let us now listen to the sawtooth
wave the decay given by 0.95 to

226
00:15:44,950 --> 00:15:47,545
the power of the number of periods.

227
00:15:47,545 --> 00:15:55,260
[SOUND] We are now at
the Karplus-Strong Algorithm.

228
00:15:55,260 --> 00:16:00,553
This is an algorithm that was invented
in the 80s to simulate guitar sounds and

229
00:16:00,553 --> 00:16:05,452
what is very particular is that it's
not initialized with a sine wave, or

230
00:16:05,452 --> 00:16:09,830
a triangle wave, but
with a sequence of random numbers.

231
00:16:09,830 --> 00:16:13,110
So we see an example here,
where M again is 100,

232
00:16:13,110 --> 00:16:18,290
alpha is 0.9,
that gives a relatively slow decay.

233
00:16:18,290 --> 00:16:22,950
And xn 1 period is actually
a set of random numbers.

234
00:16:22,950 --> 00:16:27,390
We can change the pitch
again by changing M and

235
00:16:27,390 --> 00:16:32,620
the decay depends on the factor alpha,
as usual.

236
00:16:32,620 --> 00:16:36,990
We see now what signal is generated, and

237
00:16:36,990 --> 00:16:39,590
we are going to listen
to exactly this signal.

238
00:16:39,590 --> 00:16:40,850
With various pitches, and

239
00:16:40,850 --> 00:16:44,590
you will see that this is a crude
imitation of a guitar sound.

240
00:16:44,590 --> 00:16:47,660
Let us listen to the output of
the Karplus-Strong Algorithm so

241
00:16:47,660 --> 00:16:51,190
it is initialized with random numbers,
100 of them.

242
00:16:51,190 --> 00:16:56,380
And then there is a decay of 0.9 and
we can listen to this,

243
00:16:56,380 --> 00:16:58,710
it should sound like a plucked string.

244
00:16:58,710 --> 00:17:02,378
Of course it's a coarse approximation,
but now we can listen to it.

245
00:17:02,378 --> 00:17:08,185
[SOUND] Let us wrap up this example

246
00:17:08,185 --> 00:17:13,354
of building a synthesizer.

247
00:17:13,354 --> 00:17:17,500
We have seen basic elements,
adders, multipliers, delays.

248
00:17:17,500 --> 00:17:22,140
We have seen two systems moving
averages as well as recursive systems.

249
00:17:22,140 --> 00:17:26,140
We were able to build simple systems
with interesting properties and

250
00:17:26,140 --> 00:17:29,910
now, we want to understand
these in more details.

251
00:17:29,910 --> 00:17:33,890
To understand this,
we will need a mathematical framework,

252
00:17:33,890 --> 00:17:36,273
which is a topic of the next lecture.

