plotting delta function in zero interpolation and decimation

3 ビュー (過去 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.
  1 件のコメント
Tu Nguyen
Tu Nguyen 2022 年 3 月 2 日
Thank you so much, I figured it out

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeGraphics Object Programming についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by