plotting delta function in zero interpolation and decimation

2 次查看(过去 30 天)
clc;
close all;
clear all;
x1= [1 2 3 4 5];
L = 2;
n = linspace(0,4,100);
m =linspace(0,10);
h1 = dirac(n - m*L);
idx = h1 == Inf;
h1(idx) = 1;
h2 = dirac(n-m/L);
idx = h2 == Inf;
h2(idx) = 1;
figure (1);
subplot(1,2,1);
for i = 1:numel(n);
for j = 1:numel(m);
y1{i,j} = conv(x1,h1(i,j));
plot(y1{i,j});
end
end
subplot(1,2,2);
for i = 1:numel(n);
for j = 1:numel(m);
y2{i,j} = conv(x1,h2(i,j));
plot(y2{i,j});
end
end
Hi all, this is my code, and I want to plot like the picture result. They say "Index in position 1 exceeds array bounds (must not exceed 1)". Please help me, what is wrong in my code?

采纳的回答

Abolfazl Chaman Motlagh
the problem you are adressing is that n and m are 1x100 vector each. so the term (n-m*L) is 1x100 array. and it means h1 and h2 are not 2D array. they are 1D array with size of 1x100. here's what you should do:
n = linspace(0,4,100);
m =linspace(0,10);
[n,m] = meshgrid(n,m);
after this the h1 and h2 become the array you want.
h1 = dirac(n - m*2); % L=2
size(h1)
ans = 1×2
100 100
but remember don't use n and m in number of iteration of loops any more because they are no longer vectors. use this:
for i=1:size(n,1)
for j=1:size(m,1)
but i'm not sure you'll be okay after this. because i don't have any idea what are you doing in the plot section. maybe share your formula to think about that part too.

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Graphics Object Programming 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by