Plotting sequences over intervals

159 views (last 30 days)
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
  6 Comments
Jon
Jon on 19 Nov 2020
I define it as a helper function in my script above

Sign in to comment.

Accepted Answer

Jon
Jon on 19 Nov 2020
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
  6 Comments
Jon
Jon on 20 Nov 2020
Great that your working on developing your skills, sounds like you have lots of talents, definitely post some new questions if you have more MATLAB questions. I've learned a lot from this site, there are a lot of knowledgeable people answering questions. By the way, you may already be beyond this, but if not the MATLAB On Ramp course is good for getting a quick start https://www.mathworks.com/learn/tutorials/matlab-onramp.html

Sign in to comment.

More Answers (5)

SaiDileep Kola
SaiDileep Kola on 16 Nov 2020
Hi Connor,
Start by copying complete code provided by Jon and usmpl is just a local function created to use. Don't use usmpl in the terminal without defining, that will solve your issue.
  7 Comments
Jon
Jon on 19 Nov 2020
Oops now I feel kind of silly, didn't realize I had just continued my original comment. I will try to copy and paste into an answer.

Sign in to comment.


Noor Hossen
Noor Hossen on 18 Jul 2021
Edited: Noor Hossen on 18 Jul 2021
(A).
Step 1. At first, needed to make a script file of delta function. It would be
Step 2. Then write another on script file following the problem statement
Output-----------

Sumon Gharame
Sumon Gharame on 30 Sep 2021
help

Md. Monirul Islam
Md. Monirul Islam on 30 Oct 2022
δ(n+2)

Md. Monirul Islam
Md. Monirul Islam on 30 Oct 2022
δ(n+2)

Categories

Find more on Startup and Shutdown in Help Center and File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by