Plot SPIKES in MATLAB
17 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Hello guys..
I am struggling with this for a while and I need help urgently.. I have the code for generating the possion process but I need it to generate spikes instead in the axis line and the function (sin/cos) in to be smooth, at the moment the spikes is generated in the function so the function is not smooth and i dont want this and I believe its a slight change what is missing but I cant figure it out.. I put the code below and a link to show the spikes am talking about..............
Thanks in advance :) Many Thanks your help will be appreciated it..
function S = nonhomogeneousPossion(lambda0,lambda,T)
t = -5;
I = 0;
S = [];
u = rand;
t = t - log(u)/lambda0;
while t <= T
u = rand;
if (u <= lambda(t)/lambda0)
I = I+1;
S(I) = t;
end
u = rand;
t = t - log(u)/lambda0;
end
test script..
lambda0 = 50; % Maximum value of lambda
T = 1;
lambda =@(x) lambda0 * cos(x); % lambda0(t)/lambda0
S = nonhomogeneousPossion(lambda0,lambda,T);
subplot 121
plot(S,lambda(S),'.')
xlabel('t')
ylabel('lambda(t)')
lambda = @(x) lambda0 *sin(x);
S = nonhomogeneousPossion(lambda0,lambda,T);
subplot 122
plot(S,lambda(S),'.')
xlabel('t')
0 Kommentare
Akzeptierte Antwort
Matt Fig
am 2 Apr. 2011
I looked at your pdf, and it is not entirely clear where you want to plot the lines. This might give you a head start, put it at the end of your test script and maximize the figure:
for ii = 1:length(S)
line([S(ii) S(ii)],[lambda(S(ii)) lambda(S(ii))-2],'color','r' )
end
The FOR loop could be replaced by this:
line(repmat(S,2,1),repmat([0;1],1,length(S)),'color','r' )
Now the spikes are on the x-axis. Hope this helps...
EDIT
How's this?
lambda0 = 50; % Maximum value of lambda
T = 1;
lambda =@(x) lambda0 * cos(x); % lambda0(t)/lambda0
S = nonhomogeneousPossion(lambda0,lambda,T);
subplot(1,2,1)
plot(S,lambda(S),'-')
xlabel('t')
% ylabel('lambda(t)')
lambda = @(x) lambda0 *sin(x);
S = nonhomogeneousPossion(lambda0,lambda,T);
subplot(1,2,2)
plot(S,lambda(S),'-')
xlabel('t')
X = linspace(min(S),max(S),200);
Y = pchip(S,lambda(S),X);
plot(X,Y,'-b',S,lambda(S),'ok')
line(repmat(S,2,1),repmat([0;1],1,length(S)),'color','r' )
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Spectral Measurements finden Sie in Help Center und File Exchange
Produkte
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!