필터 지우기
필터 지우기

Estimating PDF numerically without using Hist() function?

조회 수: 2 (최근 30일)
catarina
catarina 2012년 1월 26일
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

답변 (1개)

Walter Roberson
Walter Roberson 2012년 1월 27일
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.

카테고리

Help CenterFile Exchange에서 Smoothing and Denoising에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by