smoothen a list of numbers based on bezier curve - javascript

I am looking to smoothen an ordered list of number based on a specific bezier curve. I am thinking I could walking through a list of numbers that are in order.
Example:
const numsList = [1,2,3,4,5,6,7,8,9,10]
Say I wanted a value based on a easeOutQuad (cubic-bezier(0.5, 1, 0.89, 1))
I can walk through the values in a loop feeding in the current index and total array length and somehow get a longer list (say 20 or 30 items) that has smoother interval in certain areas based on a bezier curve. Anyone know of a way to do this?
0
0.7
1.3
1.9
2.5
3.0
3.5
3.9
4.3
4.7
5.0
5.4
5.7
6.1
6.6
7.1
7.6
8.2
8.8
9.4
10
Have not tried anything as I am a bit stumped...

Related

How to get the real and imag arrays for createPeriodicWave for a piecewise periodic function?

The pattern of the wave is as follows:
0.0 - 0.5 => low,
0.5 - 1.0 => high,
1.0 - 2.0 => low,
2.0 - 2.5 => high,
2.5 - 4.0 => low,
4.0 - 4.5 => high,
4.5 - 6.5 => low,
6.5 - 7.0 => high,
The pulses are equal but the time between different pulses increases as follows: 0.5, 1.0, 1.5, 2.0. This pattern repeats itself so that if we keep going the next iteration would look like this:
7.0 - 7.5 => low,
7.5 - 8.0 => high,
8.0 - 9.0 => low,
9.0 - 9.5 => high,
9.5 - 11.0 => low,
11.0 - 11.5 => high,
11.5 - 13.5 => low,
13.5 - 14.0 => high,
I believe the lows should be -1 instead of 0 (not sure though). How can I get the real and imag arrays for this waveform?
https://developer.mozilla.org/en-US/docs/Web/API/BaseAudioContext/createPeriodicWave
The createPeriodicWave() requires a signal in the frequency domain, that means you need to transform your signal from the time domain to the frequency domain using a (Discrete) Fourier Transformation (sometimes called DFT for short) to get the data format for createPeriodicWave(). More information can be found here.
createPeriodicWave() will perform a inverse Fourier Transformation back to the time domain (which you already had at the beginning), so it makes no sense to use createPeriodicWave(). Instead you can directly feed your sample data into an AudioBuffer
There is no indication of preferred language in this question but in Node there is a version of the Fast Fourier Transform (FFT) With this you can input the test data (1 to 0 or 1 to -1 or whatever as the dc element will be removed).
Please see https://www.npmjs.com/package/fft-js for details.
Once you have it installed (npm i fft-js) you can do something like this
var fft = require('fft-js').fft,
fftUtil = require('fft-js').util,
signal = [1,0,1,0];
var phasors= fft(signal);
var frequencies = fftUtil.fftFreq(phasors, 8000), // Sample rate and coef is just used for length, and frequency step
magnitudes = fftUtil.fftMag(phasors);
var both = frequencies.map(function (f, ix) {
return {frequency: f, magnitude: magnitudes[ix]};
});
console.log(both);
I would also break the sample into something smaller so say 1 unit is the time of the on pulse (0.5 seconds?) so would be something like 0,1,0,0,1,0,0,0,1,0,0,0,0,1,0,1,0,0,1,0,0,0,1,0,0,0,0,1,

I need some help understanding this ntpq output, if it indicates proper GPS sync with PPS

I've created a project (https://github.com/kshetline/aw-clock) that, among many other things, detects GPS time sync with PPS by examining the output from the ntpq command. What I'm expecting is output that looks like this:
pi#clock:~ $ ntpq -p
remote refid st t when poll reach delay offset jitter
==============================================================================
0.debian.pool.n .POOL. 16 p - 64 0 0.000 +0.000 0.001
1.debian.pool.n .POOL. 16 p - 64 0 0.000 +0.000 0.001
2.debian.pool.n .POOL. 16 p - 64 0 0.000 +0.000 0.001
3.debian.pool.n .POOL. 16 p - 64 0 0.000 +0.000 0.001
*SHM(2) .PPS. 0 l 9 64 377 0.000 -0.007 0.001
xSHM(0) .GPS. 0 l 10 64 377 0.000 -586.75 58.377
-eterna.binary.n 128.138.140.44 2 u 79 128 377 62.565 +2.244 4.420
+t2.time.bf1.yah 98.139.133.62 2 u 53 64 377 28.750 +3.667 10.354
-65-100-46-164.d .SOCK. 1 u 3 64 377 88.300 +3.213 9.568
+time-ewr.0xt.ca 17.253.14.251 2 u 11 64 377 19.489 +2.813 12.572
For my own purposes, checking for the line with both SHM and PPS with the following regex has been working fine for me:
/^\*SHM\b.+\.PPS\.\s+0\s+l\s+.+?\s([-+]?[.\d]+)\s+[.\d]+\s*$/
One of the users of my project says he has GPS sync, but my code isn't detecting it. He's not sure about PPS sync. His output from ntpq looks like this:
pi#raspberrypi:~ $ ntpq -p
remote refid st t when poll reach delay offset jitter
==============================================================================
0.debian.pool.n .POOL. 16 p - 64 0 0.000 +0.000 0.001
oPPS(0) .PPS. 0 l 7 16 377 0.000 -290.00 0.321
*SHM(0) .GPS. 1 l 4 16 377 0.000 +4.782 4.952
SHM(2) .SHM2. 0 l - 16 0 0.000 +0.000 0.000
time.skylineser 130.207.244.240 2 u 50 64 1 37.196 -285.61 0.322
+ntp1.ring-u.net 130.207.244.240 2 u 49 64 1 28.878 -280.98 1.622
+50-205-244-108- 50.205.244.27 2 u 47 64 1 27.833 -287.90 3.220
sonic.boom.net 128.9.176.30 2 u 57 64 1 71.871 -284.30 0.001
I can't find sufficient documentation for ntpq to explain how this output works thoroughly enough for me to understand whether this output indicates proper PPS sync, just in a different way than it shows up for me, or if this indicates a problem.
The user output is actually the same as yours just without/broken formatting.
It looks like the PPS offset is rather large so I wonder if they have everything configured correctly. They also have an SHM(2) entry which appears to be doing nothing. I wonder if there shared memory config is correct. My input sources list as;
NMEA GPS:
xSHM(0) .GPS. 0 l 3 16 377 0.000 -116.89 24.632
PPS:
*SHM(1) .PPS. 0 l 6 16 377 0.000 -0.014 0.045
The docs for ntpq can be found here. And the part that explains the status flags can be found here.
Extract from the docs;
discarded as not valid
x discarded by intersection algorithm
. discarded by table overflow (not used)
- discarded by the cluster algorithm
+ included by the combine algorithm
# backup (more than tos maxclock sources)
* system peer
o PPS peer (when the prefer peer is valid)
I'd be curious to see there actual ntp.conf I wonder if they have a odd or specific setup. At a quick glance I'd say there actually using the GPS/NMEA as the system peer rather than the PPS I run several production S1 servers and haven't had a situation where the PPS is marked with the o
I'm also guessing when they sent you through that output the server had not been running long (or a least not had much connectivity) as the reachability of the remote IP servers is only 2 and given there polling every 64 sec I'd say there not reachable or don't like high frequency polls.
Ideally they need to leave it running for a while (at least till everything has a reach of 377) then look again. If they have the full ntpq suite then get the output from ntpq -pcrv and it will provide deeper details.

Equation Creation for Magic Square style logic

I am trying to bring logic and programming to a currently manually driven process.
We take the weights of 16 different crushing hammers, organize them into sets of 4 based on how close each set's weight is to the others. We are looking to have less than 1 pound difference between all 4 sets. The weights are known but I cannot logically program a method to do this without pen and paper.
Example below.
Set A
Set B
Set C
Set D
39.1
40.1
42.0
41.5
40.05
41.0
40.05
38.90
41.2
42.1
41.3
43.1
38.5
43.60
42.1
41.5
Totals
158.85
166.80
165.45
165
As you can see in the first example, Sets C and D are close enough. Sets A and B are too far apart and need readjusting, but due to the severe difference, I would most likely have to rearrange all 4 sets to get with 1 pound difference for all 4 sets. Now mind you, this is all done on paper, and I am looking for a way to plug in all numbers and have it spit out the best configuration given the hammer weights, no more paper.
Set A
Set B
Set C
Set D
42.1
39.1
42.0
41.5
40.05
41.0
40.05
38.90
43.60
43.1
41.3
42.1
38.5
41.20
40.1
41.5
Totals
164.25
164.40
163.45
164
I could do this all day, splitting hairs to get as close as possible. The closer we get the weights, the less vibration we experience and our equipments last a lot longer. Anyone have any thoughts to accomplishing this?
I'm not a good math guy but I think in order to arrange ALL 4 SETS within 1lb tolerance, all 16 hammers should have some what consistent weight that is a bit apart from targeted weight.
The most simple way I can think of is to sort all of them in order and assign index 0~3 to each group until all 16 are assigned.

Reading File, Segregating and Tesseract.js Performance

I'm trying to read a file whose content is a bunch of Multiple Choice Questions jot down together like below:
SCHOOL NAME NAME OF EXAMINATION sto-vit TIME ;2 HOURS MAXIMUM MARKS 50
LFill in the blanks Marks -15 1 =0 2 (D157 39k IL True of false Marks
-5 1. Integers are closed under subtraction 2. Difference of two negative integers cannot be a positive integer. IIL. Evaluate using
distributivity property:- Marks - 10 1. -39x99 2. 8543+ 43x-15
3.53%9--109x53 4. 6817+ 683 IV. Solve the problems:- Marks - 10 1. A vehicle covers a distance of 43.2 km in 2.4 litre of petrol. How much
distance will it cover in 1 litre of petrol? V. Evaluate:- Marks - 10
11005105 2. 10101 %001
I have got this by reading an image (a question paper) with the help of Tesseract.js.
First of all, some of the mathematical digits including decimal points are omitted. Can I improve the performance?
Is there a way to identify the questions with their options separately so that it can be stored in a database for people to answer?
The object can be of this format:
{
[
q: 'Which website is this?',
options: ['Github', 'Stackoverflow', 'Google']
],
[
...
]
}

How to fix calculation error occuring on javascript as well c#

I am using mvc3 with c# language where I was stuck in calculation problem.Here I am using double type variables for 3 properties Qty,Cost and totalprice
Here totalprice=Qty*Cost;
I have requirement where I want to get totalprice of product without decimals. For example if qty=14.3 , cost=15. Then on java script/C# I will get total price 214.5
But I require 214.To solve this I used Math.Floor(214.5) to get 214. But when Qty=18.9 and cost=1500. Then on javascript or C# multiplication, I am getting total price=28349.999999999996, The correct result should be 28350. Please help me to get solution where I will get both result accurately
Choose according to you in c#.
-3 -2 -1 0 1 2 3
+--|------+---------+----|----+--|------+----|----+-------|-+
a b c d e
a=-2.7 b=-0.5 c=0.3 d=1.5 e=2.8
====== ====== ===== ===== =====
Floor -3 -1 0 1 2
Ceiling -2 0 1 2 3
Truncate -2 0 0 1 2
Round (ToEven) -3 0 0 2 3
Round (AwayFromZero) -3 -1 0 2 3
In javscript do like this:
var qty=qty.toFixed(1);
var cost=cost.toFixed(1);
var totalprice=Math.round(qty*cost);
you can use Math.round(); this solves your problem.
Math.round(214.5- .1);
This question already has an answer here: Javascript floating calculation error
you can use toFixed() for example: (1.2 - 1).toFixed(1) * 1 // 0.2

Categories

Resources