You are on page 1of 1

function conv_322(x,x_start,h,h_start,delta);

% conv_322(x,x_start,h,h_start,delta);
%
% Convolution support function for the Signals and Systems course,
% EE-322 at the United States Naval Academy {EE Department}.
% Calculates and plots the numeric convolution integral, y(t) = x(t)*h(t).
% The input, x(t), and the impulse response, h(t), are also plotted.
% For the result to be accurate ... delta must be sufficiently small.
%
% x
- sampled version of the input function
% x_start - input function start time (in seconds)
% h
- sampled version of the impulse response function
% h_start - impulse response function start time (in seconds)
% delta
- time interval between samples (in seconds) ... delta t
%
% 7 September 1998, last rev 23 September 1998
% copyright (c) 1998, written by CDR Thad Welch {USNA}
% w/ help from Midshipman 2/C Trevor Laughter
expand=0.1;
total_length=length(x)+length(h)-1;
t=x_start+h_start+delta*(0:total_length-1);
t_min=min([x_start h_start t]);
t_max=max([x_start+delta*length(x) h_start+delta*length(h) t]);
y=delta*conv(x,h);
y_min=min([x h y]);
y_max=max([x h y]);
tmin=t_min-expand*(t_max-t_min);
tmax=t_max+expand*(t_max-t_min);
ymin=y_min-expand*(y_max-y_min);
ymax=y_max+expand*(y_max-y_min);
x_time=x_start+delta*(0:length(x)-1);
h_time=h_start+delta*(0:length(h)-1);
subplot(3,1,1)
plot([tmin t(1)-delta t tmax],[0 0 y 0],'b')
grid
title('Convolution of x(t) and h(t)')
ylabel('output, y(t)')
%axis([tmin tmax ymin ymax])
subplot(3,1,2)
plot([tmin x_time(1)-delta x_time x_time(length(x_time))+delta tmax],[0 0 x 0
0],'r')
grid
ylabel('input, x(t)')
%axis([tmin tmax ymin ymax])
subplot(3,1,3)
plot([tmin h_time(1)-delta h_time h_time(length(h_time))+delta tmax],[0 0 h 0
0],'g')
grid
xlabel('time (seconds)')
ylabel('impulse response, h(t)')
%axis([tmin tmax ymin ymax])

You might also like