Clear Filters
Clear Filters

plotting delta function in zero interpolation and decimation

2 views (last 30 days)
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);
for i = 1:numel(n);
for j = 1:numel(m);
y1{i,j} = conv(x1,h1(i,j));
for i = 1:numel(n);
for j = 1:numel(m);
y2{i,j} = conv(x1,h2(i,j));
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?

Accepted Answer

Abolfazl Chaman Motlagh
Abolfazl Chaman Motlagh on 2 Mar 2022
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
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.

More Answers (0)


Find more on Graphics Object Programming in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!