Hi Work Wolf
this is John BG ( <mailto:email@example.com firstname.lastname@example.org> ), please comment if the following answers your question, script and support function attached, following my understanding of the question:
Defining a test x:
Defining void grid for result, your px(x) I call it pv
sweep v, not x
[xk xk1 xk2]=find_nearest_xk(v(k),x)
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;
hold all;stem(x);grid on
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)
if n_b>1 && n_b<numel(b)
comment, please note that in order to keep symmetry and shorten the amount of required Ifs I have used the following expression
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