plot summation of shifted discrete signals

2 views (last 30 days)
n=-4:2;
y=[1,-2,4,6,-5,8,10];
n=n-2
stem(n,y);
I want to plot Z = y(n-2)+y(n+1);

Accepted Answer

Hamoon
Hamoon on 17 Sep 2015
Edited: Hamoon on 17 Sep 2015
n=-4:2;
y=[1,-2,4,6,-5,8,10];
maxShift = 10; % maximum shift that you may want,
% you can't shift more than this value,
% you should set this value high enough
% I could set it to be 2 here, but I prefer 10
n=min(n)-maxShift:1:max(n)+maxShift; % define proper range for n
y=[zeros(1,maxShift), y, zeros(1,maxShift)]; % add zeros to the begining and
% end of y
z= circshift(y',-2) + circshift(y',1); % calculate your new signal. you need
% transpose of y ==> y'
  2 Comments
Hamoon
Hamoon on 17 Sep 2015
here is the output using:
subplot(2,1,1)
stem(n,y);
title('y')
axis([-15 15 -10 20])
subplot(2,1,2)
stem(n,z);
title('z')
axis([-15 15 -10 20])
Nguyen Hong Son
Nguyen Hong Son on 17 Apr 2020
Excuse me. Can I ask you why we can use circular shift to compute operations of shifted discrete signals? (I can't have the intuition or visualization of it)
Why do we need the transpose of y in the last line of code?
Thank you so much!

Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!