Reinderien
Reinderien

Reputation: 15233

Simple antialiasing in Matlab

There seem to be dozens upon dozens of different ways to do this in Matlab, but I need a simple one that is fast and performant, and can't really find one (there are many entries for interpolation but none that I can find for antialiasing).

Given some one-dimensional array filled with 0s, such as

[0 0 0 0 0]

I need to be able to add one single value v at some non-integer index i. For example, if v were 10 and i were 2.75, we would get something close to

[0 2.5 7.5 0 0]

I can do this manually but I'm sure there's already something built in.

Upvotes: 1

Views: 992

Answers (1)

Luis Mendo
Luis Mendo

Reputation: 112689

Manually is probably the fastest:

x = [0 0 0 0 0]; %// original data
ind = 2.75; %// index of new value
val = 10; %// new value
ind_int = floor(ind); %// integer part of index
ind_fr = ind - ind_int; %// fractional part of index
x(ind_int) = x(ind_int) + (1-ind_fr)*val; %// or maybe x(ind_int) = (1-ind_fr)*val;
x(ind_int+1) = x(ind_int+1) + ind_fr*val; %// maybe x(ind_int+1) = ind_fr*val;

Upvotes: 2

Related Questions