Signals 
 Home
Matlab Tutorial 
 Links
Discrete  
 Convolution
Continuous  
 Convolution
Cross Correlation
Fourier Transform
Exam 1 Material
Exam 2 Material
Final Exam Material
Fourier Series 
  via FFT
Xtreme DSP
Other Links
Celoxica
Discrete Convolution

Here are a couple of examples of how to do discrete convolution in Matlab.  Here is the first example. Here is your first signal and it's associated waveform.

Here is how you input it into Matlab.  Note that there is no obvious way to specify the fact that the signal starts at n=0.  If you put a ";" at the end of the input line, it will not echo out your input.

 

Here is your second signal and it's waveform.

Here is how you input this second signal into Matlab.  First you will see how to print out each of the individual wave forms and then we will convolve the two inputs.

This is how you plot the "x" function.  The resulting plot is shown below.

Here is how you plot the "h" function and it's resulting plot.

To convolve the two signals (x and h) you will type in the following comand.

Here is how you would plot your resulting convolution.  Note that we have to specify the right indices.

Here is a second example.  It is just a little more difficult but was neat the way it turned out.

badger

Here is the Matlab code

n0=10;
n=-n0:n0;
u1=(n-4)>=0;
f=(-1/2).^n;
f1=f.*u1;
x=f1;
u2=(2-n)>=0;
h=(4).^n;
h2=h.*u2;
h=h2;
k1=-n0:n0;

y=conv(x,h)
length_output=length(x)+length(h)-1;
k2=linspace(-2*n0,2*n0,length_output);

figure(1);
clf;
subplot(2,2,1);
xlabel('k');
ylabel('x[k]');
title('System Input');
stem(k1,x,'filled');
grid;

subplot (2,2,2);
xlabel('k');
ylabel('h[k]');
title ('System Unit Impulse Response');
stem(k1,h,'filled');
grid;

subplot (2,1,2);
stem (k2, y, 'filled');
grid;
xlabel('k');
ylabel('y[k]');
title ('System Output Via Convolution');

 

And here is how the final plot looked.

badger2
[Signals Home] [Matlab Tutorial Links] [Discrete  Convolution] [Continuous  Convolution] [Cross Correlation] [Fourier Transform] [Exam 1 Material] [Exam 2 Material] [Final Exam Material] [Fourier Series  via FFT] [Xtreme DSP] [Other Links] [Celoxica]