View License

Download apps, toolboxes, and other File Exchange content using Add-On Explorer in MATLAB.

» Watch video

Highlights from
Kernel density estimation for circular functions

5.0 | 1 rating Rate this file 7 Downloads (last 30 days) File Size: 4.12 KB File ID: #44072 Version: 1.5
image thumbnail

Kernel density estimation for circular functions


Dylan Muir (view profile)


24 Oct 2013 (Updated )

Performs kernel density estimates over arbitrary periodic domains.

| Watch this File

File Information

See also
circ_ksdensity - Compute a kernel density estimate over a periodic domain
Usage: [vfEstimate] = circ_ksdensity(vfObservations, vfPDFSamples, <vfDomain, fSigma, vfWeights>)
This function calculates a kernel density estimate of an (optionally weighted) data sample, over a periodic domain.
'vfObservations' is a set of observations made over a periodic domain, optionally defined by 'vfDomain': [fMin fMax]. The default domain is [0..2*pi]. 'vfPDFSamples' defines the sample points over which to perform the kernel density estimate, over the same domain as 'vfObservations'.
Weighted estimations can be performed by providing the optional argument 'vfWeights', where each element in 'vfWeights' corresponds to the matching element in 'vfObservations'.
The kernel density estimate will be performed using a wrapped Gaussian kernel, with a width estimated as
     (4/3)^0.2 * circ_std(vfObservations, vfWeights) *(length(vfObservations^-0.2)
The optional argument 'fSigma' can be provided to set the width of the kernel.
'vfEstimate' will be a vector with a (weighted) estimate of the underlying distribution, with an entry for each element of 'vfPDFSamples'. If no weighting is supplied, the estimate will be scaled such that it forms a PDF estimate over the supplied sample domain, taking into account sample bin widths. If a weight vector is supplied then the estimate will be scaled such that the sum over the domain attempts to match the sum of weights, taking into account sample bin widths.

Required Products MATLAB
MATLAB release MATLAB 7.11 (R2010b)
MATLAB Search Path
Tags for This File   Please login to tag files.
Please login to add a comment or rating.
Comments and Ratings (2)
21 Feb 2014 Dylan Muir

Dylan Muir (view profile)

Yes, good point. I will adjust the weighting and submit an updated version.

Thanks very much for your feedback.

Comment only
21 Feb 2014 Josip Music

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?

24 Feb 2014 1.1

Improved weighting of density estimate.

18 Mar 2014 1.2

Updated scaling of density estimate.

31 Mar 2014 1.3

Updated description

18 Jun 2014 1.4

Updated summary

22 Sep 2016 1.5

Updated usage formatting

04 Oct 2016 1.5

Updated description

24 Oct 2016 1.5

Updated description

13 Dec 2016 1.5

Updated description

Contact us