Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.0k views
in Technique[技术] by (71.8m points)

signal processing - How do I perform x[2n], x[n/2],x[n-3], and x[n+2] on MATLAB? I believe these involves scaling and shifting

The instructions are:

Create a random signal with the maximum amplitude value of (15 *0.1) with 11 sample values and center the middlemost value in the 0 of the x-axis. Write down the random values in the given format below. x(n)=[values]

Plot the graph x[n] to show the 11 samples in a stem graph. Then do the following operations:

  1. Plot the graph x[2n] to show the 11 samples in a stem graph.
  2. Plot the graph x[n/2] to show the 11 samples in a stem graph.
  3. Plot the graph x[n-3] to show the 11 samples in a stem graph.
  4. Plot the graph x[n+2] to show the 11 samples in a stem graph.

The graphs should look similar to the graphs in this link:

https://cnx.org/contents/[email protected]:e6-BCH5U@1/Discrete-Time-Signal-Operations

for x[2n] i tried

xn=(15 *0.1).*rand(1,11); to create the random values

n=(-5:5);

n1 = 2*n;

stem(n1,xn);

the n values were just multiplied by two and all values of xn were still plotted, which is not supposed to be the case according to the link that I provided.

question from:https://stackoverflow.com/questions/65938354/how-do-i-perform-x2n-xn-2-xn-3-and-xn2-on-matlab-i-believe-these-inv

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

There are 2 key points I think you are missing:

  1. If you are going to decimate your random numbers by a factor of 2, you need to start with twice as many points if you are going to end up with 11 points.
  2. Multiplying the index by 2 does not discard every other point.

Here is some code that demonstrates making more random points so you end up with the right number after decimation, and creating a use variable that is not incremented by 1 so that you can decimate.

c = 2; % decimation factor
num_pts_after_dec = 11;
num_pts_before_dec = num_pts_after_dec * c;

xn=(15 *0.1) * rand(1, num_pts_before_dec); 
use = 1:c:length(xn); % Create index for the decimation
xn = xn(use); % Do the decimation
n=(1:length(xn)) - (num_pts_after_dec + 1) / 2;

stem(n,xn);

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...