Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

New to MATLAB?

Thread Subject:
Need help in debugging a program !!

Subject: Need help in debugging a program !!

From: Animesh Pandey

Date: 19 Mar, 2011 17:47:07

Message: 1 of 1

This is an animated program for convolution .....
I have not made this program but I wanted to run it.
I am having errors when I run mainly due to lines 41,42,43,44 .....
Please help in removing those errors !!!
thanx !!!
axis_color= [0.5 0.5 0.5];% color of axis constant
s_int = 0.1;
t = [ -10:s_int:10 ];
syms m
x=input('enter x(m).you should enter a function that its variable is m\n');

t1 = [-10:s_int:10];
h=input('enter h(m).you should enter a function that its variable is m\n');


g = fliplr(h1);%flip 'h(t1)' for the graphical convolutions g = h(-t1)
tf = fliplr(-t1);

% slide range of 'g' to discard non-overlapping areas
%with 'x' in the convolution
tf = tf + ( min(t)-max(tf) );

% get the range of function 'c' which is the convolution of 'x(t)' and
% 'h(t1)'
tc = [ tf t(2:end)];
tc = tc+max(t1);

% convolve operations
for i=1:length(tc)

% start graphical output with three subplots
a_fig = figure(1);
  set(a_fig, 'Name', 'Animated Convolution', 'unit', 'pixel', ...
             'Position', [250, 00, 550, 550]);
ax_1 = subplot(3,1,1);
  op = plot(t,x1, 'b', t1, h1, 'r');
  hold on; grid on;
  set(ax_1, 'XColor', axis_color, 'YColor', axis_color, 'Color', 'w', 'Fontsize', 9);
  xlim( [ ( min(t)-abs(max(tf)-min(tf)) - 1 ) ( max(t)+abs(max(tf)-min(tf)) + 1 ) ] );
  title('Graph of x(t) and h(t)', 'Color', axis_color );
  legend({'x(t)' 'h(t)'});
  ax_2 = subplot(3,1,2);
  p = plot(t, x1);
  hold on; grid on;
  title('Graphical Convolution: x(t) and g = h(-t1)', 'Color', axis_color );
% plot g in the subplot number 2
  q = plot(tf, g, 'r');
  xlim( [ ( min(t)-abs(max(tf)-min(tf))-1 ) ( max(t)+abs(max(tf)-min(tf))+1 ) ] );
  u_ym = get(ax_2, 'ylim');

% plot two vertical lines to show the range of overlapped area
  s_l = line( [min(t) min(t)], [u_ym(1) u_ym(2)], 'color', 'g' );
  e_l = line( [min(t) min(t)], [u_ym(1) u_ym(2)], 'color', 'g' );
  hold on; grid on;
  set(ax_2, 'XColor', axis_color, 'YColor', axis_color, 'Color', 'w', 'Fontsize', 9);

  % put a yellow shade on overlapped region
  sg = rectangle('Position', [min(t) u_ym(1) 0.0001 u_ym(2)-u_ym(1)], ...
                 'EdgeColor', 'w', 'FaceColor', 'y', ...
                 'EraseMode', 'xor');
% initialize the plot the convolution result 'c'
  ax_3 = subplot(3,1,3);
  r = plot(tc, c);
  grid on; hold on;
  set(ax_3, 'XColor', axis_color, 'YColor', axis_color, 'Fontsize', 9);
  % xlim( [ min(tc)-1 max(tc)+1 ] );
  xlim( [ ( min(t)-abs(max(tf)-min(tf)) - 1 ) ( max(t)+abs(max(tf)-min(tf)) + 1 ) ] );
  title('Convolutional Product c(t)', 'Color', axis_color );

% animation block
  for i=1:length(tc)
    % control speed of animation minimum is 0, the lower the faster
    % update the position of sliding function 'g', its handle is 'q'

    % show overlapping regions
    % show a vertical line for a left boundary of overlapping region
      sx = min( max( tf(1), min(t) ), max(t) );
      sx_a = [sx sx];
      set(s_l, 'XData', sx_a);

    % show a second vertical line for the right boundary of overlapping region
      ex = min( tf(end), max(t) );
      ex_a = [ex ex];
      set(e_l, 'XData', ex_a);
    % update shading on overlapped region
      rpos = [sx u_ym(1) max(0.0001, ex-sx) u_ym(2)-u_ym(1)];
      set(sg, 'Position', rpos);
    % update the plot of convolutional product 'c', its handle is r
      set(r,'XData',tc(1:i),'YData',c(1:i) );

Tags for this Thread

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us