Coding wavelets the easy way

Application to a simple moving average


We assume here that the structured signal is still in your workspace. If not, go back here and there.
Observe that sig.s is aline vector, so, if we want the convolution to work, the impulse response should be a line vector.
Use the File menu of Matlab to create a new script file, or, alternatively create a new text file if your favorite plain text editor. Name the file "average.m".
This script should be begin by defining a causal filter with impulse response h which computes the average of the current data with the value of the previous one.
Next, the script should plot the data field of sig in figure 1 for future reference. To create a numbered figure window with number i, use figure(i).
When you want to test your script, just type "average" in the command window. You can do this now.

Next you will recursively apply the h filter to the signal sig.
To do so, you will use the following syntax for Matlab loops
for varname = vector
-- do your stuff
end
varname
is the index variable that will be updated during the loop; vector is a vector that contains the sequence of values that varname should take in the loop. Here we shall use the fact that 1:n, if n is an nonnegative integer, defines an integer line vector ranging from 1 to n.
Now the script should continue with
  • setting the variable n to 8
  • copying sig into a variable loopsig that will be used in the loop
  • copy h into a variable looph that will be used in the loop
  • create a loop with index i ranging from 1 to n
  • inside the loop: apply the filter looph to loopsig by convolution at each index i to produce an output also called and loopsig, and create a figure numbered i+1 to plot the data of loopsig.
  • insert zeros in looph
The solution is here