Hi! Just a quick observation. I have been using your code on my data and it works well except I noticed one possible issue (i'm not expert in the field so correct me if I'm wrong).
I tried this on synthetic data (generated by circular statistic toolbox and circ_vmrnd command) where i know exact KD function: the shape of the KD estimate is good but not the amplitude (similar effect I noticed on my real world data). As far as I could say is that in your code you do not take account of the fact that padding has been added when using ksdensity function so in essence I get correct amplitude if I multiply your estimate (amplitudes) with number three (original data + upper and lower padding). I'm I correct or have I missed something?