Estimating PDF numerically without using Hist() function?

1 visualizzazione (ultimi 30 giorni)
Hello,
I've been stuck with the issue of estimating PDf numerically without using the hist() function for some time now. I had some improvements but there is some coding that I get stuck with and can't figure it out. Really hope there is someone out there that can help me. One bit is writing the following: fnj={1, if An<=yj<=An+1,0 otherwise} which I tried to use a if statement but don't think I did it right. The other problem is in coding the sigma notation: N-1 Fn=sigma(fnj) -not able to represent this in matlab code j=0
My script is underneath for a better understanding of what I done and my doubt:
%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
Look forward to hear some tips,
Catarina

Risposte (1)

Walter Roberson
Walter Roberson il 27 Gen 2012
fnj = @(this_n,this_j) An(this_n+1) <= yj(this_j+1) & yj(this_j+1) <= An(this_n+2);
fn_all_j = @(this_n) arrayfun(@(this_j) fnj(this_n,this_j), 0:N-1);
Fn = @(this_n) sum(fn_all_j(this_n));
all_Fn = arrayfun(Fn, n);
plot(all_Fn, An);
Yes, this is written quite differently than what I would write in practice for myself. It is written step by step to allow you to study the individual pieces -- to see how to write the condition, to see how to do the iteration over j, to see how to do the sigma over those values.
You should, by the way, expect the calculation of all_Fn to bomb out. I will leave it to you to figure out why. I will say that the code reflects your specifications.

Categorie

Scopri di più su Startup and Shutdown in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by