Clear Filters
Clear Filters

Deriving PDF from a given signal without using the hist() function?

8 views (last 30 days)
Hello,
I'm newbie at this and am enjoyably although a bit painfully trying to work my way around Matlab. As my question implies I have a signal and I would like to derive it's PDF function numerically without using the hist () function ? I looked in the documentation that it would be:
p1=pdf('name',X,A) or extra B,C depending if we have 1 or three parameters. Although I read the documentation I don't understand what X stands for (what I should replace it with?). From what I understand if it's for example normal pdf it would be:
p1=(pdf('name', X, A, B), being A the mean and B the standart derivation and X I don't know. I really don't understand how do I relate the pdf function with the signal I generated on matlab???
Hope I'm making sense and someone is able to help.
Thank you very much
Catarina

Accepted Answer

bym
bym on 29 Dec 2011
I am not sure I understand, but take a look at:
doc ksdensity
  2 Comments
David Young
David Young on 30 Dec 2011
catarina: I'm very puzzled. If you can't use hist(), how is that ksdensity() is a good solution?

Sign in to comment.

More Answers (2)

David Young
David Young on 29 Dec 2011
The pdf function is not useful for this. It generates the theoretical PDF for a named distribution, but does not estimate an empirical PDF from data.
You are probably being asked to write code that does what hist does. This involves taking each element of the signal vector, working out the index of the bin it falls into, and incrementing an element of a histogram vector. To get an estimated PDF, you'd finally normalise the counts in the histogram vector.
You can do this with loops, or using MATLAB's vectorised style of programming. The essential ideas are the same in both cases, but vectorised code is more compact and often somewhat more efficient.
  5 Comments
catarina
catarina on 26 Jan 2012
Hi David (and other people that might be able to help),
I'm still having problems in deriving the PDF without the hist() function but I think is because I'm stuck in how to code certain stuff. Would you able to look at my script and if possible give me some tips? I explained my doubts in the script.
Here is my script:
%Estimating PDF numerically without using hist() function
%Dividing amplitude range into M=60 segments
delta=20 %Amplitude range
n=0:1:M-1;
An=-10+n*(delta/M);
%sampling the signal
%Time points
N=1024; %(number of samples)
j=0:1:N-1;
T=1; %(number of cycles for tis problem T=1)
tj=j*(T/N)
%function points
yj=10*sin(2*pi*tj);
%counting number of samples falling in each segment:
%by constructing a 2D array with elements defined as:
%fnj={1, if An<=yj<=An+1,0 otherwise - I'm not being able to represent
%this statement in matlab, I tried using if statements
%but keeps giving me an error
%Counting the number of samples Fn in amplitude segment number n as:
% N-1
% Fn=sigma(fnj) -not able to represent this in matlab code
% j=0
%Now plot Fn agains An - can't do this because of my previous the doubts
Cheers,
Catarina
Walter Roberson
Walter Roberson on 27 Jan 2012
No point debugging this in two Questions. See the answer in your newer Question on this point, http://www.mathworks.com/matlabcentral/answers/27188-estimating-pdf-numerically-without-using-hist-function

Sign in to comment.


Peter Perkins
Peter Perkins on 29 Dec 2011
Catarina, the pdf function (I assume this is the one in the Statistics Toolbox) evaluates a known PDF at a set of points. That isn't what you want, at least initially.
If you have a set of data, then I think what you're asking for is a way to estimate their PDF. For a normal distribution, that's the normfit function, for other distributions there are other corresponding functions. Once, you have estimated the parameters of the distribution you want to use, then you can use the pdf function to plot the PDF over some range. There is also the ksdensity function, which creates a non-parametric estimate.
You might find it easier to use the fitdist function, and even easier still to use dfittool, which lets you do all this using a GUI.
Hope this helps.
  3 Comments
David Young
David Young on 30 Dec 2011
Peter: I suspect the fact that hist() is mentioned is an indication that the empirical PDF based on the histogram is required, not a fit to a specific model. Since hist() is forbidden, and the object is to become familiar with MATLAB rather than analyse some real data, I doubt that ksdensity() will be the right kind of answer.

Sign in to comment.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!