Azzera filtri
Azzera filtri

Info

Questa domanda è chiusa. Riaprila per modificarla o per rispondere.

How can i write this in matlab please

1 visualizzazione (ultimi 30 giorni)
Folakemi Omotoye
Folakemi Omotoye il 8 Ago 2018
Chiuso: MATLAB Answer Bot il 20 Ago 2021
this is the whole code
n=30;
[v]=linspace(3,20,n);
%CUSUM Algorithm
h=4; %threshold
t=2;
for t=2:numel(v) %start time
s(t)=sum(v(t-1)+v(t)); %cumulative sum up to current value
g(t)=max( s(2:t)); %maximum value
if g(t) > h %if output is greater than the specified threshold
detect_tim=t(g(t)>h); %store the detection time
disp(['The detection time= ', num2str(detect_tim),'']) %display the detection time
%estimate the change time
%%%i need help here please.(please refer to attached pic for analogy-signal.jpg) from the attached figure, i want to specify the time when the signal started increasing from zero (point 1000).the threshold is known (red line in the pic) but the assumption should be that the value zero is unknown (i.e the value zero should be the cumulative sum in previous lines of code).i want to specify the time the signal significantly started increasing from the cumulative sum up till the threshold
change_time=t(max(s(2:t))) ; %the time following the current minimum of
%the cumulative sum
disp(['The change time estimate= ', num2str(change_time),'']) %display value of change
% stop and reset algorithm
continue %to re-start algorithm
end
end
%Here, my xlim line doesnt get to the end of the length of the x-axis.it always stops at 1. i used auto because i don't know the last value of the x-axis. i want the horizontal line xl to extend till the end of the x-axis (signal plotpt1.jpg)
xL = get(gca,'XLim'); %plot threshold line on same axis
figure(1), subplot(2,1,1)
line(xL,[4 4],'Color','r'); %horizontal line through the threshold value
hold on
plot(2:t,v(2:t),'*b') %the time vector plot
title('signal change plot')
xlabel('time (ms)')
ylabel('Amplitude (v)')

Risposte (0)

Questa domanda è chiusa.

Community Treasure Hunt

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

Start Hunting!

Translated by