Problem with Time Series Data - Negative Increase and Long Pause - matlab

I'm trying to solve two problems from Time Series data in Matlab.
Data = [1000 2000 3000 2500 4000 5000 9000 10000 11000 10500 12000 18000 19000 18500 20000 21000 22000 23000 24000 25000];
Write a function to find negative increase, e.g., 1000, 2000 3000, 2500, 4000, 5000, 9000. Once we find the number, we need to shift all future times up, like 2500 -> 4000, and 4000 -> 5000…
Write a function to identify long pause, e.g., 1000, 2000, 3000, 2500 4000, 5000, 9000, 10000, 11000, 10500, 12000, 18000. After Identifying the number, we need to remember all pauses for padding with nan.

Related

Psychtoolbox flip time issue

I am running a psychophysics task on psychtoolbox that need to show each image for 16, 30, 60, and 120 milliseconds. Although my system monitor refresh rate is 16.66 ms (60 Hz) but the lowest time I get is almost 33 ms (I check this time by recording video from the screen while showing these images).
I've searched a lot and now I use flip with specifying the time with ifi and nextFrameInterval but still can't show my image for 16 milliseconds. Why is this happening and how can I fix this?
ifi = Screen('GetFlipInterval',window);
Screen('DrawTexture',window,fixation,[],fixRect);
[~,lastVisualInterval] = Screen('Flip', window);
nextStimFrameDelta= (p.pre_mask_time/ifi);
Screen('DrawTexture',window,stimulus(rec(TrialNum, 3)),[],rectStim);
[~,lastVisualInterval] = Screen('Flip', window,lastVisualInterval +((nextStimFrameDelta-0.5)*ifi));
nextStimFrameDelta= ((rec(TrialNum,2)/1000)/ifi) % rec(TrialNum,2) is the duration of peresenting images (16,30,... ms)
Screen('DrawTexture',window,mask(TrialNum),[],rectStim);
[~,lastVisualInterval] = Screen('Flip', window,lastVisualInterval +((nextStimFrameDelta-0.5)*ifi));
% And here the facial expression must be replaced by a mask after 16 or 30,... ms

How to color measure value with condition in tableau?

table:
id category qty sales_2017 sales_2018
1 pen 5 5000 7000
1 pen 8 15000 7000
1 pen 9 15000 7000
2 pencil 6 5000 17000
2 pencil 1 5000 14000
2 pencil 10 5000 7000
output:
category qty sales_2018(sales_2018-sales_2017)
pen 22 35000(-14000)
pencil 17 15000(20000)
i need to get output like this, with the color formatted which are in bracket if it is negative then red
else green.
For as close to the desired output as possible, you need to drag Category to the Rows shelf, then SUM(qty) to rows, SUM(sales_2018) to rows.
Now, for the conditional formatting on the bracket data, you need a simple calculated field for 2018 -2017 sales. Drag this to the text card.
To color that text accordingly, write a calculated field:
IF [calculated field you just created above] < 0 THEN 'red' ELSE 'green' END
Drag that calculated field to the color card and choose colors to match their names (aliases). You can do this by double clicking on the colors in the legend.
If you need to add parentheses around the result you can do that in the label card.

How can i get rid of unpredictable speed peaks during speed measurements?

I had wrote service for user speed tracking.This service is using Core Location framework to track geo points and do calculation of the user speed.
Service example:
private func processLocation(_ current:CLLocation) {
guard let location = lastLocation else {
lastLocation = current
speed.value = 0
return
}
var speed = current.speed
if (speed > 0) {
speed.value = speed
} else {
speed = location.distance(from: current) / (current.timestamp.timeIntervalSince(location.timestamp))
speed.value = speed
}
lastLocation = current
}
This service is working with acceptable accuracy. But there is a case when you are stationary and this service receive quite a lot of unpredictable peaks.
Log when I am stationary.
Speed: 0.249200397696353
Speed: 0.778375328912623
Speed: 6.99212664940017 -> peak
Speed: 4.91809055561385 -> peak
Speed: 0.701735999364708
Speed: 0.025146066057472
Speed: 0.0233857682731226
Speed: 12.7814687721084 -> peak
Speed: 0.61632553168542
Speed: 7.37520678279276 -> peak
Speed: 0.023421072500409
Speed: 0.0343784939631481
Speed: 0.471982071125438
Speed: 0.0207671001927932
Speed: 0.0217459598583271
Speed: 0.0394697185852203
Speed: 0.439568634647097
Speed: 14.1348693612176 -> peak
Speed: 6.29588775714151 -> peak
Speed: 5.55254459904619 -> peak
Speed: 0.218587071425142
How can I get rid of unpredictable peaks in this speed tracking service? Should I do better configuration of the Core Location manager ?
I suggest using a Median Filter for reducing data peaks. Define a threshold for detecting peak values and apply filter on them. Refer to this document https://homepages.inf.ed.ac.uk/rbf/HIPR2/median.htm

Matlab Stepinfo Function

S = stepinfo(Y,T,180,'SettlingTimeThreshold',ST) ;
ts=S.SettlingTime;
in this does it mean ts is the time at which |Y-180| becomes less than ( ST/100 )or something else...
in my code though |Y-180| is less than ST/100 but i am getting ts = NAN;
pls help me out
My code:
if ee(end)>160
S = stepinfo(ee,times,180,'SettlingTimeThreshold',0.01);
else
S = stepinfo(ee,times,0.5,'SettlingTimeThreshold',1);
end
settling_time = S.SettlingTime;
end
where 'ee' is an array of values at each 'times'
ee is basically error angle which becomes 180 or 0 after some time..
thanks
From the help:
The response has settled when the error |y(t) - yfinal| becomes
smaller than a fraction ST of its peak value.
This means that it's the fraction of the peak error value, not an absolute threshold - e.g. if your system was something that started at around 30, and eventually rose and settled at near 180 (yfinal = 180), then the max error is 150, and the threshold would be 0.01*150 = 1.5. So it would need to get to 178.5 (180-1.5).
If your system started at 100 and settled at about 180, your max error is 80, and the threshold is then only 0.8, so your value needs to be at 179.2.
Look at what your min(ee) and max(ee) are and then decide on what a sensible threshold is.
EDIT:
If you want to set a fixed threshold you'll have to calculate it on the fly:
desiredthreshold = 1.8 % absolute value, e.g. 0.01*180
maxerror = 180-min(ee); % assuming your values are all between 0 and 180
actualthreshold = 1.8/maxerror; %if your min value is 0 then this goes to 0.01, otherwise it will be larger

Calculate Pace To String

I am trying to calculate pace (min/mi) and format it as mmmm:ss.
So far I calculate my pace into a float by taking 60 and dividing it by my average speed. At an average speed of 76mph, my average pace is displayed as 0.79. I want to format it so that it converts my 0.79 minutes to mmmm:ss (thus showing my average pace as 0000:47). How can I do this?
double milesPerHour = 76.0;
int secondsPerMile = (int)round(3600.0 / milesPerHour);
NSString *paceString = [NSString stringWithFormat:#"%04d:%02d", secondsPerMile / 60, secondsPerMile % 60];
Not sure if I get your question right, but this is pretty much just math.
You can get the minutes by rounding your value (0.79 in this case) down and you can get seconds by taking your value, subtracting the minutes from it and multiplying that by 60.
So if you'd need 2.35 minutes for a mile, you'd have 2 minutes and 0.35*60 = 21 seconds.