plotting delta function in zero interpolation and decimation

조회 수: 2 (최근 30일)
Tu Nguyen
Tu Nguyen 2022년 3월 2일
댓글: Tu Nguyen 2022년 3월 2일
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
Abolfazl Chaman Motlagh 2022년 3월 2일
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