Hi Work Wolf
this is John BG ( <mailto:jgb2012@sky.com jgb2012@sky.com> ), please comment if the following answers your question, script and support function attached, following my understanding of the question: 1.
Defining a test x:
N=10
x=randi([1 1000],1,10)/100
h=min(abs(diff(x)))
2.
Defining void grid for result, your px(x) I call it pv
dv=.1*h
v=[min(x)-h:dv:max(x)+h];
pv=zeros(1,numel(v));
3. check
4.
sweep v, not x
for k=1:1:length(v)
[xk xk1 xk2]=find_nearest_xk(v(k),x)
sgna=sign(v(k)-xk)
da=abs(v(k)-xk)
da1=abs(v(k)-xk1)
da2=abs(v(k)-xk2)
if da<=h/3 pv(k)=1-sgna*da;end;
if da1>h/3 && da<2*h/3 pv(k)=.5-3*sgna*(da1-h); end;
if da2>2*h/3 && da<h pv(k)=da2^3*sgna; end;
end
5.
result
figure(2);plot(v,pv)
hold all;stem(x);grid on
.
6.
the support function finds the nearest x(k) to each point of v, which is your input x, not the same as the input sequence of scattered points x [x1 x2 .. xn]
function [y y1 y2]=find_nearest_xk(a,b)
db=0
for s=1:1:length(b)
db=[db abs(a-b(s))];
end
db(1)=[];
[db n_b]=min(db)
if n_b==1
y=0;y1=b(1);y2=b(2);
end
if n_b==numel(b)
y=b(numel(b)-1);y1=b(numel(b));y2=0;
end
if n_b>1 && n_b<numel(b)
y=b(n_b-1);y1=b(n_b);y2=b(n_b+1);
end
end
7.
comment, please note that in order to keep symmetry and shorten the amount of required Ifs I have used the following expression
8. update
ok, so far pk(x) now does something, not flat anymore, it looks like a noisy sin(v), sort of.
This is because the support function I initially used did not take into account x(k-1) and x(k+1), check 1st email.
I have updated both script and support function to take into account x(k-1) and x(k+1) as requested, check attachments to this answer and 3rd email.
Now, for different random sequences (10 samples only each test) one gets a clear spike, or a couple of them. Sample:
.
Hope it helps.
.
Work Wolf, also to PhD Adel Adel
if you find this answer useful would you please be so kind to consider marking my answer as Accepted Answer?
To any other reader, if you find this answer useful please consider clicking on the thumbs-up vote link
thanks in advance
John BG