MATLAB: Plotting sequences over intervals

signal processing

Hello,
How would I go about plotting a seqeunce over the below intervals?
A) ?(?) = 2?(? + 1)− ?(? −6), −10 ≤ ? ≤ 10.
B) ?(?) = {… , 5, 4, 3, 2, 1, 5, 4, 3, 2, 1, 5, 4, 3, 2, 1, … }; −20 ≤ ? ≤ 12.
Thanks

Best Answer

You could do it like this
n = -10:10
x = zeros(length(n),1) % preallocate array of zeros to hold result
for k = 1:length(n)
% evaluate x(n)
x(k) = 2*usmpl(n(k)+ 1) - usmpl(n(k)-6);
end
% plot result
stem(n,x)
% define helper function
function delta = usmpl(n)
% define unit sample function
if n == 1
delta = 1
else
delta = 0
end
end