There are 2 key points I think you are missing:
- 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.
- 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);
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…