
Signals and Systems by M. J. Roberts
1) Using MATLAB, garph these function combinations, p 42
t = 0 : 1/120 : 6 % make vectors with values from 0 to 6 with the step 1/120.
x1 = exp(-t).*sin(20*pi*t) + exp(-t/2) .* sin(19*pi*t);
subplot(2,1,1); p = plot(t, x1, 'k'); set(p, 'LineWidth', 2);
xlabel('\itt'); ylabel('x_l({\itt})'); % { } determines the range of the effect of \it (italic font)
t = -4 : 1/60 : 4 ; x2 = sinc(t) .* cos(20*pi*t);
subplot(2, 1, 2); p = plot(t, x2, 'k'); set(p, 'LineWidth', 2);
xlabel('\itt'); ylabel('x_2({\itt})') ;
2) Program to illustrate some of MATLAB's built-in functions, p60
close all;
t = -20 : 1/20 : 20;
x1 = chirp(t, 1/20, 20, 1/3); subplot(4,2, 1); p = plot(t, x1, 'k');
axis([-20, 20, -1.5 1.5]); title('chirp - A "chirped" cosine');
xlabel('\itt'); ylabel('x_1({\itt})');
x2 = diric(t, 5); subplot(4,2,2); p = plot(t, x2, 'k');
axis([-20,20,-1.5,1.5]);
title ('diric - The MATLAB "Dirichlet" function');
xlabel('\itt'); yabel('x_2({\itt})');
x3 = sawtooth(t); subplot(4,2,3); p = plot(t, x3, 'k');
axis([-20,20,-1.5,1.5]); title('sawtooth - A Periodic Sawtooth');
xlabel('\itt'); ylabel('x_3({\itt})');
x4 = square(t); subplot(4,2,4); p = plot(t, x4, 'k');
axis([-20,20,-1.5,1.5]); title('square - A Square Wave');
xlabel('\itt'); ylabel('x_4({\itt})');
x5 = rectpuls(t); subplot(4,2,5); p = plot(t, x5, 'k');
axis([-20,20,-1.5,1.5]); title('rectpuls - A Rectangular Pulse');
xlabel('\itt'); ylabel('x_5({\itt})');
x6 = tripuls(t); subplot(4,2,6); p = plot(t, x6, 'k');
axis([-20,20,-1.5,1.5]); title('tripuls - A Triangular Pulse Wave');
xlabel('\itt'); ylabel('x_6({\itt})');
x7 = sinc(t/2); subplot(4,2,7); p = plot(t, x7, 'k');
axis([-20,20,-1.5,1.5]); title('sinc(t)');
xlabel('\itt'); ylabel('x_7({\itt})');
x8 = sign(t/2); subplot(4,2,8); p = plot(t, x8, 'k');
axis([-20,20,-1.5,1.5]); title('sign - The Signum Function');
xlabel('\itt'); ylabel('x_8({\itt})');
---------------------------------------------------------------
x1e = (x1 + x1(end : -1 : 1) ) /2 ; x1o = (x1 - x1(end : -1 : 1) ) /2; % x1 is a matrix !! so, the step of
% index is -1, not a fraction
subplot (2,1,1); plot( t, x1e, 'k');
axis([-20,20,-1.5,1.5]); title('Even part of x_1');
xlabel('\itt'); ylabel('x_1_e({\itt})');
subplot (2,1,2); plot( t, x1o, 'k');
axis([-20,20,-1.5,1.5]); title('Odd part of x_1');
xlabel('\itt'); ylabel('x_1_o({\itt})');
3) Discrete Signals, p80
function y = g(n)
ss = find(n ~= round(n));
n(ss) = NaN; % notice that n is not a variable in other languages.
% In MATLAB, all variables are MATRICES with (INDICES)
y = 10*exp(-n/4).* sin(3 * pi * n / 16) .* uDT(n);
function y = uDT(n)
ss = find(n ~= round(n));
y = double(n >= 0);
y(ss) = NaN;
>> n = -5:48;
>> g0 = g(n);
>> g1 = g(2*n);
>> g2 = g(n/3);
>> subplot(3,1,1);
>> p = stem(n, g0, 'k', 'filled');
>> set(p, 'LineWidth', 2, 'MarkerSize',4);
>> ylabel('g[n]'); title('Example 2.5');
>> subplot(3,1,2);
>> p = stem(n, g1, 'k', 'filled');
>> set(p, 'LineWidth', 2, 'MarkerSize', 4);
>> ylabel('g[2n]');
>> subplot(3,1,3);
>> p = stem(n, g2, 'k', 'filled');
>> set(p, 'LineWidth', 2', 'MarkerSize',4);
>> ylabel('g[n/3]');