(old answer deleted - not as good as Carl's)
Bjorne, I was able to take your more complicated code and use Carl Woll's method to get something useful. Since your hh and your ef functions are both differentiable, the only trick was to "get inside" the NIntegrate[ ] function. I think the pattern below works, which is to:
- Deactivate the NIntegrate and swap out a dummy variable
- Differentiate with respect to the dummy variable
- Put the original variable back in and activate to let the NIntegrate run its course
The function I defined below computes the derivative of your hilbertTransformSmoothFinite[ ] with respect to x, and is only modified below the (******)
delhilbert[f_, x_?NumericQ, supp_, s_: 1] := Module[{xx, esupp, ef},
esupp = {supp[[1]] - Abs[f[supp[[1]]]]/s, supp[[2]] + Abs[f[supp[[2]]]]/s};
ef = Function[X, Piecewise[{{f[X],
supp[[1]] < X <= supp[[2]]}, {f[supp[[1]]] +
Sign[f[supp[[1]]]] s (X - supp[[1]]),
esupp[[1]] < X <= supp[[1]]}, {f[supp[[2]]] -
Sign[f[supp[[2]]]] s (X - supp[[2]]),
supp[[2]] < X <= esupp[[2]]}, {0, True}}]];
(*******)
term = Inactivate[NIntegrate[1/π (ef[ ξ] - ef[x])/( ξ - x), { ξ, esupp[[1]], esupp[[2]]}] +
1/π ef[x] Log[(esupp[[2]] - x)/(x - esupp[[1]])]] /. x -> xx;
(D[term, xx] /. xx -> x) // Activate
];
pdel = Function[x, delhilbert[hh, x, {0, 1}]];
Here is the plot of your p[ ] function
Plot[p[x], {x, 0, 1}]

And here is the pdel[ ] function. Looks like a proper derivative plot of p[ ]
Plot[pdel[x], {x, 0, 1}]
