Tutorial  III
Tutorial III
Q.1
Ans: An accumulator is a register for shortterm, intermediate storage of arithmetic and logic data
in a computer's CPU (central processing unit). The term "accumulator" is rarely used in reference to
contemporary CPUs, having been replaced around the turn of the millennium by the term "register."
In a modern computers, any register can function as an accumulator.
The most elementary use for an accumulator is adding a sequence of numbers. The
numerical value in the accumulator increases as each number is added, exactly as it happens in a
simple desktop calculator (but much faster, of course). Once the sum has been determined, it is
written to the main memory or to another register.
The term "accumulator" is used in a wide variety of noncomputing applications and
activities, such as electrical engineering (an energy storage device such as a rechargeable battery or
ultracapacitor), hydraulics (a mechanical energy storage device), in stock trading (a contract or
agreement), and even in gambling (a parlay bet).
Program:
xl
Input X[n] =
l=0
Q.2
xl
l=0
+ Xn.
What is a Moving average filter? Write a program to implement for one dimensional
signal and two dimensional signal.
1)
In financial applications a simple moving average (SMA) is the unweighted mean of the
previous n data. However, in science and engineering the mean is normally taken from an equal
140010741014
Tutorial  III
When calculating successive values, a new value comes into the sum and an old value drops
out, meaning a full summation each time is unnecessary for this simple case,
The period selected depends on the type of movement of interest, such as short, intermediate,
or longterm. In financial terms movingaverage levels can be interpreted as support in a falling
market, or resistance in a rising market.
If the data used are not centered around the mean, a simple moving average lags behind the
latest datum point by half the sample width. An SMA can also be disproportionately influenced by
old datum points dropping out or new data coming in. One characteristic of the SMA is that if the
data have a periodic fluctuation, then applying an SMA of that period will eliminate that variation
(the average always containing one complete cycle). But a perfectly regular cycle is rarely
encountered.
For a number of applications, it is advantageous to avoid the shifting induced by using only
'past' data. Hence a central moving average can be computed, using data equally spaced on either
side of the point in the series where the mean is calculated. This requires using an odd number of
datum points in the sample window.
A major drawback of the SMA is that it lets through a significant amount of the signal shorter
than the window length. Worse, it actually inverts it. This can lead to unexpected artifacts, such as
peaks in the smoothed result appearing where there were troughs in the data. It also leads to the
result being less smooth than expected since some of the higher frequencies are not properly
removed.
2) Cumulative moving average:In a cumulative moving average, the data arrive in an ordered datum stream, and the user
would like to get the average of all of the data up until the current datum point. For example, an
investor may want the average price of all of the stock transactions for a particular stock up until the
140010741014
Tutorial  III
current time. As each new transaction occurs, the average price at the time of the transaction can be
calculated for all of the transactions up to that point using the cumulative average, typically an
equally weighted average of the sequence of n values
up to the current time:
The bruteforce method to calculate this would be to store all of the data and calculate the
sum and divide by the number of datum points every time a new datum point arrived. However, it is
possible to simply update cumulative average as a new value,
becomes available, using the
formula:
Thus the current cumulative average for a new datum point is equal to the previous
cumulative average, times n, plus the latest datum point, all divided by the number of points
received so far, n+1. When all of the datum points arrive (n = N), then the cumulative average will
equal the final average.
The derivation of the cumulative average formula is straightforward. Using
results in:
140010741014
Tutorial  III
When calculating the WMA across successive values, the difference between the numerators
of WMAM+1 and WMAM is npM+1 pM pMn+1. If we denote the sum pM + + pMn+1 by TotalM,
then
The graph at the right shows how the weights decrease, from highest weight for the most recent
datum points, down to zero. It can be compared to the weights in the exponential moving average
which follows.
140010741014
Tutorial  III
for
Where:
The coefficient represents the degree of weighting decrease, a constant smoothing factor
between 0 and 1. A higher discounts older observations faster.
for any suitable k = 0, 1, 2, ... The weight of the general datum point
is
This formula can also be expressed in technical analysis terms as follows, showing how the EMA
steps towards the latest datum point, but only by a proportion of the difference (each time):
140010741014
Tutorial  III
Expanding out
each time results in the following power series, showing how the
weighting factor on each datum point p1, p2, etc., decreases exponentially:
where
is
is
and so on
,
since
i.e.
simplified, tends to
The above discussion requires a bit of clarification. The sum of the weights of all the terms
(i.e., infinite number of terms) in an exponential moving average is 1. The sum of the weights of
terms is
. Both of these sums can be derived by using the formula for the sum of
a geometric series. The weight omitted after
terms is given by subtracting this from 1, and you
get
(this is essentially the formula given below for the
weight omitted). Note that there is no "accepted" value that should be chosen for although there
are some recommended values based on the application. In the above discussion, we have
140010741014
Tutorial  III
The power formula above gives a starting value for a particular day, after which the
successive days formula shown first can be applied. The question of how far back to go for an initial
value depends, in the worst case, on the data. Large price values in old data will affect on the total
even if their weighting is very small. If prices have small variations then just the weighting can be
considered. The weight omitted by stopping after k terms is
which is
i.e. a fraction
out of the total weight. For example, to have 99.9% of the weight, set above ratio equal to 0.1% and
solve for k:
approaches
140010741014
Tutorial  III
5) Modified moving average:A modified moving average (MMA), running moving average (RMA), or smoothed moving
average (SMMA) is defined as:
6) Application to measuring computer performance:Some computer performance metrics, e.g. the average process queue length, or the average CPU
utilization, use a form of exponential moving average.
where exp() is the exponential function, time for readings tn is expressed in seconds, and
is the period of time in minutes over which the reading is said to be averaged (the mean lifetime of
each reading in the average). Given the above definition of , the moving average can be expressed
as
For example, a 15minute average L of a process queue length Q, measured every 5 seconds (time
difference is 5 seconds), is computed as
Q.3
140010741014
Tutorial  III
Ans: A convolution is an integral that expresses the amount of overlap of one function as it is
shifted over another function. It therefore blends one function with another. English dictionary
defines convolution as the action of coiling or twisting or winding together. Convolution is used
in filtering, Study of heat conduction, wave motion and other areas of physics and mathematics.
Convolution is relationship among three signals : input signal, impulse response and output
signal. If we know impulse response of any system then by using convolution we know output of the
system for every input signal.
How Convolution is calculated ?
If there are two signals , if we multiply them in time domain then we are really convolving them in
frequency domain and viceversa.
There are Two types of convolution:
1. Linear convolution :
if
convolution is given by
2. Circular convolution :
if
convolution is given by
circular convolution. Following two are widely used :
i) Circular convolution using linear convolution : Compute linear convolution and then
bring last
terms from
Example:
1
2
3
4
5
6
7
 1 2 3
4 4 8 12

5 5 10 15

6 6 12 18
terms of
140010741014
Tutorial  III
Note that
. To covert this linear convolution to circular
convolution we will add last 2 terms of Y_lc to first 2 terms.
Note that
This property of circular convolution is widely used in OFDM transcievers where CP used to avoid
inter symbol interference. Instead of adding zeros between two OFDM symbols, N11 last terms are
added at the start of symbol.
ii) Circular convolution using DFT multiplication:
See octave example below:
01
02
03
04
05
06
07
08
%%
%%
%%
%%
09
10
x = [1,2,3];
11
h = [4,5,6];
12
13
x_fft = fft(x);
14
y_fft = fft(h)
15
Y_cc = ifft(x_fft.*y_fft)
16
17
subplot(211);
18
stem(Y_cc);
19 title('Circular convolution using DFT multiplication');
140010741014
Tutorial  III
20 grid on;
21
22
23 %One other thing to notice is that if we add N11 zeros at the end of x and h
24 %then we will get output as linera convolution
25
26
27
28
29
30
31
32
33
34
35
36
37
38
N1=length(x); N2=length(h);
X=[x,zeros(1,N2)];
Y=[h,zeros(1,N1)];
n=N1+N21;
x_fft = fft(X,n);
y_fft = fft(Y,n);
Y_lc = ifft(x_fft.*y_fft,n)
subplot(212);
stem(Y_lc);
title('Linear convolution');
grid on;
140010741014
Tutorial  III
Q.4
Ans: FFT is a fast algorithm for execution of DFT. The multiplication of two DFTs is equivalently
a circular convolution of the two sequences. We can make use of DFT for computation of
convolution as the circular convolution in time domain is equivalently a multiplication in the DFT
domain using a property of convolution. We need to convert the linear convolution to a circular
convolution and then make use of FFT algorithm to reduce the number of computation for filtering.
The procedure to convert the linear convolution to a circular convolution is increase length of each
sequence by appending zeros so that it is equal to the length of the resulting convolved sequence.
Overlapadd Algorithm :Step 1: Take the L samples of data sequence . Append M 1 extra zeros to this block of data so
that its length is L + M 1.
Step 2: Append L 1 extra zeros to the FIR filter so that its length is L + M 1.
Step 3: Convolve the two sequences circularly using FFT as shown in Fig. 1 to obtain the output as
L + M  1.
Step 4: Repeat steps 1 to 3 for all the blocks.
Step 5: Accumulate the results by adding the overlapped samples of the convolved output for
For example, let the input sequence be = [1 2 3 4 5 1 2 3 4 5 1 2 3 4 5]. Let the FIR filter
sequence be = [3 2 1 1]. Let us calculate the convolution using overlapadd method. We will use
block size for the data as L = 5 and M = 4. We have to append three zeros to the data block and 4
zeros to . Therefore, the length of both the sequences is L + M 1 = 5 + 4 1 = 8. When we use
FFT, N is selected as some exponential of 2. The data blocks will be
X1 = [ 1 2 3 4 5 0 0 0 ]
X2 = [ 1 2 3 4 5 0 0 0 ]
X3 = [ 1 2 3 4 5 0 0 0 ]
=[32110000]
140010741014
Tutorial  III
OverlapSave Algorithm :The algorithm for overlapsave method can be written as follows:
Step 1: Take L samples of the data sequence .
Step 2: Append M 1 last sample from the first block at the start of the second block and so on so
that the length of each block is L + M 1.
Step 3: For the first block, there is no previous block, append zeros at the start of this block.
Step 4: Append L 1 extra zeros to the FIR of the filter so that its length is L + M 1.
Step 5: Convolve the two sequences circularly using FFT to obtain the output.
Step 6: Repeat steps 1 to 5 for all the blocks.
Step 7: Accumulate the result by appending samples of the convolved output for successive blocks.
Discard first M 1 samples from result of every block and then append M 1 samples of the first
block at the end of the accumulated result by circular shifting.
Step 8: Overlap the input data samples and save the rest of the nonoverlapping result samples.
For example, let the input sequence be = [1 2 3 4 5 1 2 3 4 5 1 2 3 4 5].Let the FIR filter sequence
be = [3 2 1 1]. Let us calculate the convolution using overlapsave method. We will use block
size for the data as L = 5 and M = 4. We have to append three zeros to the data block and 4 zeros to
. Therefore, the length of both the sequences is L + M 1 = 5 + 4 1 = 8. When we use FFT, N
is selected as some exponential of 2. The data blocks will be
X1 = [0 0 0 1 2 3 4 5]
X2 = [3 4 5 1 2 3 4 5]
X3 = [3 4 5 1 2 3 4 5]
= [3 2 1 1 0 0 0 0]
140010741014
Tutorial  III
Q.5
Ans:
Introduction:
Pulse dialing and tone dialing are the two systems used in telephone signaling. DTMF is the
name used for pushbutton tone dialing. DTMF uses two tones to represent each key on the touch
pad. DTMF has found widespread applications such as in automated telephone inquiry services
where a user can select options from a menu by sending DTMF signals from a telephone.
DTMF signaling represents a digit or a character by the sum of a highfrequency tone and a
low frequency tone (thereby, dual tone). When any key is pressed, the tone of the column and the
tone of the row are generated. The DTMF corresponding to that key is generated by either table
lookup or a resonator. The signal is transmitted through the telephone line to a switching center. The
switching center samples the signal and uses FFT or Goertzel algorithm to determine the received
frequencies and hence tell the corresponding digit.
Methodology:
Initially, a simple energy threshold is used to separate the digits in each file which can be done
as follows. The whole signal is divided into frames whose individual average energy is calculated.
The average of all these is considered as the threshold. But in some cases, the noise energy exceeds
the threshold. Hence, five continuous frames are joined to make the noise energy less than the signal
140010741014
Tutorial  III
energy. This is done in steps 1 and 2 of the program. Now, the starting point of each digit is needed
to be found, shown in step 3. If the current frame number is 1 and the energy is more than the
threshold, then it is one of the digits starting points. For frame numbers after 1, if the frame energy
is more than the threshold and also the previous frame energy, then it is again one of the digits
starting points. Then the Goertzel algorithm is implemented to obtain the frequency spectrum. Using
the largest two amplitudes in the output of Goertzel algorithm, the digits in the signal are found.
140010741014
Tutorial  III
Observations:
Not many frequency points are required to decode the signal
1) If the Goertzel Algorithm criteria is satisfied, the time for computing is greatly reduced.
2) It is better than the FFT method.