How to find g-forces for 3 axis accelerometer - accelerometer

I am working on collecting 3 axis accelerometer data from an input file. I have extracted the x, y, z values but don;t know how to get the g forces for the accelerometer with 0g being half-scale and the range of the accelerometer is +/-5g.
Any formulas to use? Thanks in advance.

Related

How to make a 3d plot in Simulink from real-time (x, y, z) coordinates?

I am building a project to take as input z coordinates of the roof from a distance sensor mounted on a robot via arduino and take the x and y from two rotary encoders. I have used the Simulink Support Package for Arduino to take digital inputs.
Currently I am not using the encoders and so I'll be storing X and Y coordinates in a matrix and use those for plotting.
I now plan to plot the z-coordinates with pre-defined X and Y coordinates onto a 3d Plot and I am not able to understand how to proceed.
As the readings of z-coordinates is real-time, I hope to get a real-time varying 3d plot. Alternatively, I can also store a set of 1000 points and then plot those and then clear the memory for the next 1000 points.
Thing is, the plot is going to be a line that has its points scattered over the x and y axes.
Kindly advise how to obtain the plot in Simulink.
There is no built in 3d plot block for simulink (at least up to the version I used actively), but you can find some code for different blocks in the file exchange. Two examples:
https://de.mathworks.com/matlabcentral/fileexchange/61335-3d-stem-for-simulink-block
https://de.mathworks.com/matlabcentral/fileexchange/4915-3dscope
Pick the one you like or look for further ones.

Calculation vibration with accelerometer (LSM303D sensor)with STM32

I want to write an algorithm for ageing or condition monitoring of fluid valves.I read something about condition monitoring of valves and finally, I decided to calculate the vibration of the valve with accelerometer sensor.
Currently, I am working with LSM303D and ADXL345 sensors.
I am getting raw data from this sensor(LSM303D) like
X-axis = -2587 negative
Y -axis = -2230 negative
Z - axis = 16063
Is this mean acceleration is in Z axis direction?
I have fixed my sensor on the valve(There is no physical movement) and want to measure the vibration while switching on and off the valve.
How to proceed with my raw data for creating an algorithm for vibration calculation with STM32 controller?
Please explain about the raw data from sensor.
Sensor Datasheet
http://www.st.com/content/ccc/resource/technical/document/datasheet/1c/9e/71/05/4e/b7/4d/d1/DM00057547.pdf/files/DM00057547.pdf/jcr:content/translations/en.DM00057547.pdf
STM32 Datasheet:
http://www.st.com/content/ccc/resource/technical/document/datasheet/95/3c/2e/5b/21/09/45/a6/DM00115237.pdf/files/DM00115237.pdf/jcr:content/translations/en.DM00115237.pdf
OutPUT:
X axis
-2320,-2288,-2290,-2273,-2308,-2264,-2258,-2302,-2361,-2361,-2263,-2349,-2338,-2301,-2383,-2311,-2313,-2313,-2354,-2351,-2358,-2254,-2411,-2336,-2336,-2269,-2232,-2354,-2300,-2356,-2326,-2368,-2368,-2295,-2370,-2345,-2344,-2342,-2323,-2323,-2341,-2290,-2292,-2328,-2363,-2347,-2347,-2303,-2330,-2384,-2306,-2318,-2348,-2348,-2289,-2300,-2384,-2301,-2269,-2269,-2391,-2314,-2294,-2327,-2343,-2331,-2331,-2247,-2313,-2403,-2284,-2336,-2336,-2323,-2340,-2276,-2277,-2353,-2400,-2400,-2321,-2296,-2317,-2314,-2356,-2359,-2359,-2313,-2250,-2312,-2334,-2314,-2314,-2298,-2317,-2279,-2368,-2331,-2560,-2304,-2298,-2327,-2301,-2332,-2330,-2330,-2269,-2300,-2300,-2332,-2271,-2057,-2313,-2316,-2309,-2257,-2362,-2406,-2406,-2290,-2298,-2373,-2314,-2260,-2277,-2277,-2323,-2332,-2189,-2314,-2339,-2553,-2297,-2332,-2327,-2289,-2347,-2326,-2326,-2319,-2361,-2330,-2352,-2329,-2550,-2294,-2311,-2312,-2327,-2344,-2362,-2360,-2280,-2307,-2307,-2370,-2307,-2211,-2264,-2313,-2354,-2317,-2344,-2352,-2288,-2288,-2266,-2307,-2297,-2356,-2334,-2302,-2307,-2307,-2326,-2289,-2345,-2387,-2378,-2308,-2308,-2323,-2323,-2273,-2348,-2288,-2288,-2314,-2255,-2299,-2335,-2306,-2327,-2327,-2267,-2313,-2319,-2275,-2307,-2354,-2354,-2299,-2288,-2279,-2337,-2325,-2325,-2256,-2312,-2294,-2295,-2294,-2368,-2368,-2326,-2324,-2320,-2303,-2310,-2325,-2325,-2310,-2291,-2309,-2328,-2364,-2364,-2284,-2354,-2376,-2311,-2335,-2342,-2342,-2336,-2322,-2317,-2276,-2385,-2362,-2268,-2107,-2363,-2307,-2292,-2296,-2356,-2288,-2288,-2355,-2372,-2303,-2348,-2279,-2346,-2346,-2238,-2320,-2323,-2280,-2318,-2345,-2345,-2318,-2323,-2316,-2316,-2307,-2324,-2324,-2376,-2251,-2347,-2375,-2300,-2300,-2399,-2318,-2283,-2375,-2356,-2316,-2316,-2260,-2418,-2341,-2347,-2327,-2327,-2308,-2358,-2335,-2344,-2350,-2264,-2264,-2377,-2328,-2323,-2347,-2351,-2352,-2352,-2290,-2369,-2307,-2333,-2306,-2540,-2284,-2343,-2353,-2283,-2301,-2310,-2548,-2292,-2358,-2321,-2275,-2290,-2267,-2267,-2378,-2330,-2319,-2356,-2315,-2337,-2337,-2360,-2385,-2358,-2320,-2304,-2290,-2290,-2329,-2362,-2318,-2335,-2303,-2303,-2358,-2305,-2293,-2288,-2244,-2255,-2255,-2339,-2337,-2375,-2296,-2243,-2053,-2309,-2346,-2410,-2333,-2287,-2316,-2316,-2362,-2331,-2291,-2350,-2394,-2323,-2323,-2377,-2313,-2324,-2327,-2322,-2322,-2258,-2325,-2356,-2337,-2376,-2351,-2351,-2286,-2255,-2347,-2376,-2359,-2343,-2343,-2389,-2303,-2302,-2384,-2298,-2298,-2313,-2344,-2323,-2273,-2295,-2316,-2316,-2369,-2343,-2287,-2280,-2348,-2544,-2288,-2279,-2380,-2349,-2241,-2344,-2344,-2366,-2363,-2350,-2303,-2335,-2340,-2340,-2309,-2348,-2304,-2354,-2644,-2461,-2404,-2404,-2170,-2374,-2299,-2268,-2334,-2334,-2364,-2288,-2337,-2329,-2401,-2241,-2241,-2247,-2339,-2395,-2312,-2369,-2526,-2270,-2298,-2318,-2285,-2254,-2316,-2349,-2349,-2334,-2274,-2297,-2352,-2321,-2321,-2293,-2358,-2289,-2341,-2329,-2336,-2336,-2360,-2311,-2345,-2344,-2321,-2321,-2333,-2285,-2284,-2325,-2360,-2280,-2280,-2303,-2343,-2237,-2317,-2373,-2535,-2279,-2309,-2287,-2308,-2289,-2334,-2334,-2293,-2330,-2315,-2271,-2300,-2346,-2346,-2336,-2287,-2308,-2320,-2315,-2347,-2347,-2302,-2283,-2267,-2312,-2288,-2096,-2352,-2298,-2252,-2290,-2341,-2328,-2290,-2290,-2265,-2242,-2326,-2262,-2300,-2074,-2330,-2322,-2382,-2304,-2316,-2337,-2337,-2209,-2358,-2339,-2285,-2319,-2280,-2280,-2327,-2299,-2329,-2331,-2317,-2347,-2347,-2343,-2334,-2255,-2295,-2295,-2295,-2315,-2343,-2365,-2366,-2326,-2542,-2286,-2331,-2343,-2370,-2317,-2291,-2270,-2270,-2343,-2261,-2335,-2343,-2297,-2297,-2359,-2290,-2293,-2350,-2314,-2315,-2315,-2388,-2357,-2335,-2382,-2235,-2052,-2308,-2379,-2340,-2313,-2260,-2301,-2301,-2225,-2323,-2286,-2383,-2370,-2504,-2248,-2274,-2317,-2282,-2285,-2226,-2145,-2401,-2341,-2361,-2422,-2336,-2288,-2288,-2386,-2357,-2294,-2310,-2295,-2117,-2373,-2260,-2274,-2289,-2379,-2313,-2313,-2256,-2300,-2344,-2293,-2296,-2312,-2312,-2363,-2328,-2347,-2351,-2294,-2092,-2348,-2381,-2347,-2229,-2275,-2328,-2328,-2379,-2256,-2362,-2331,-2347,-2360,-2360,-2279,-2269,-2332,-2374
Y Axis
-2485,-2478,-2511,-2486,-2486,-2475,-2490,-2517,-2482,-2505,-2457,-2457,-2468,-2471,-2475,-2498,-2513,-2489,-2531,-2531,-2509,-2435,-2473,-2493,-2486,-2428,-2428,-2485,-2473,-2513,-2459,-2514,-2510,-2456,-2456,-2519,-2511,-2569,-2466,-2484,-2524,-2524,-2475,-2468,-2518,-2469,-2443,-2513,-2513,-2494,-2460,-2503,-2466,-2497,-2497,-2460,-2472,-2528,-2473,-2479,-2480,-2480,-2448,-2425,-2447,-2523,-2552,-2447,-2447,-2513,-2532,-2480,-2459,-2511,-2511,-2493,-2472,-2447,-2477,-2542,-2434,-2434,-2472,-2484,-2477,-2503,-2472,-2472,-2478,-2519,-2501,-2449,-2453,-2477,-2477,-2491,-2471,-2480,-2507,-2473,-2449,-2449,-2514,-2457,-2473,-2513,-2501,-2501,-2437,-2520,-2479,-2481,-2468,-2497,-2497,-2523,-2488,-2454,-2525,-2470,-2470,-2448,-2487,-2484,-2477,-2460,-2476,-2476,-2515,-2467,-2443,-2449,-2480,-2480,-2451,-2459,-2470,-2477,-2489,-2463,-2463,-2492,-2500,-2469,-2491,-2475,-2528,-2528,-2438,-2442,-2506,-2499,-2489,-2461,-2486,-2485,-2483,-2492,-2523,-2453,-2453,-2484,-2458,-2509,-2484,-2497,-2433,-2433,-2515,-2479,-2507,-2519,-2485,-2483,-2500,-2500,-2477,-2510,-2506,-2488,-2480,-2497,-2497,-2488,-2464,-2452,-2496,-2487,-2487,-2512,-2464,-2489,-2484,-2496,-2477,-2477,-2467,-2478,-2500,-2452,-2534,-2490,-2490,-2499,-2485,-2463,-2457,-2501,-2501,-2471,-2448,-2524,-2480,-2473,-2503,-2503,-2481,-2525,-2497,-2449,-2511,-2483,-2483,-2513,-2459,-2501,-2462,-2489,-2489,-2496,-2494,-2468,-2453,-2464,-2537,-2537,-2484,-2520,-2442,-2514,-2505,-2463,-2517,-2523,-2523,-2471,-2454,-2444,-2442,-2519,-2519,-2521,-2480,-2457,-2455,-2492,-2471,-2471,-2454,-2493,-2510,-2480,-2458,-2489,-2489,-2485,-2492,-2487,-2459,-2466,-2466,-2519,-2446,-2500,-2527,-2459,-2489,-2489,-2479,-2469,-2484,-2482,-2477,-2480,-2480,-2479,-2494,-2514,-2485,-2474,-2474,-2493,-2505,-2495,-2471,-2496,-2501,-2501,-2438,-2495,-2469,-2488,-2481,-2521,-2521,-2508,-2490,-2465,-2480,-2455,-2524,-2524,-2499,-2502,-2481,-2472,-2490,-2490,-2432,-2494,-2543,-2478,-2462,-2487,-2487,-2525,-2491,-2500,-2491,-2449,-2490,-2490,-2459,-2506,-2476,-2487,-2493,-2480,-2480,-2498,-2472,-2506,-2473,-2457,-2457,-2503,-2515,-2479,-2486,-2482,-2521,-2521,-2491,-2509,-2505,-2496,-2483,-2483,-2453,-2495,-2519,-2440,-2548,-2482,-2482,-2427,-2532,-2495,-2466,-2436,-2443,-2443,-2500,-2444,-2458,-2455,-2489,-2489,-2510,-2497,-2494,-2510,-2519,-2485,-2485,-2458,-2509,-2466,-2519,-2483,-2523,-2523,-2482,-2511,-2492,-2463,-2470,-2470,-2494,-2481,-2487,-2495,-2493,-2513,-2513,-2490,-2495,-2505,-2476,-2470,-2470,-2480,-2502,-2479,-2420,-2470,-2479,-2479,-2491,-2530,-2512,-2503,-2538,-2446,-2446,-2447,-2562,1029,-2413,-2366,-2607,-2607,-2426,-2440,-2552,-2446,-2503,-2517,-2517,-2428,-2496,-2462,-2489,-2525,-2513,-2513,-2456,-2476,-2500,-2535,-2524,-2453,-2453,-2534,-2493,-2480,-2487,-2437,-2437,-2470,-2514,-2465,-2532,-2511,-2448,-2448,-2479,-2532,-2519,-2507,-2463,-2510,-2510,-2459,-2461,-2483,-2488,-2520,-2520,-2485,-2455,-2491,-2492,-2445,-2458,-2458,-2477,-2489,-2492,-2478,-2506,-2501,-2501,-2489,-2485,-2481,-2480,-2486,-2486,-2471,-2453,-2505,-2473,-2478,-2472,-2472,-2493,-2487,-2491,-2479,-2492,-2518,-2518,-2520,-2508,-2503,-2465,-2501,-2488,-2488,-2485,-4231,-2508,-2483,-2376,-2474,-2474,-2453,-2503,-2498,-2455,-2495,-2495,-2495,-2517,-2455,-2470,-2441,-2478,-2478,-2470,-2500,-2484,-2473,-2418,-2477,-2477,-2512,-2459,-2503,-2473,-2464,-2476,-2476,-2480,-2497,-2499,-2501,-2492,-2492,-2443,-2478,-2500,-2476,-2486,-2529,-2529,-2455,-2521,-2463,-2482,-2460,-2460,-2510,-2506,-2470,-2484,-2473,-2441,-2441,-2500,-2489,-2502,-2496,-2415,-2504,-2504,-2518,-2417,-2500,-2498,-2460,-2501,-2501,-2498,-2460,-2449,-2465,-2499,-2499,-2496,-2479,-2521,-2513,-2513,-2479,-2479,-2480,-2546,-2514,-2502,-2479,-2479,-2446,-2484,-2531,-2524,-2533,-2489,-2489,-2486,-2444,-2477,-2462,-2474,-2513,-2513,-2485,-2475,-2463,-2438,-2477,-2477,-2470,-2481,-2467,-2497,-2454,-2475,-2475,-2507,-2477,-2499,-2464,-2501,-2501,-2523,-2502,-2452,-2497,-2488,-2456,-2456,-2487,-2504,-2490,-2472,-2547,-2458,-2458,-2469,-2429
Z Axis:
16068,16050,16097,16178,16142,16294,16038,16070,16184,16207,16125,16174,16246,16246,16161,16117,16132,16128,16104,16281,16326,16070,16012,16147,16174,15961,16097,16121,15919,16175,16173,16092,16019,16144,16074,16136,16136,16031,16016,16123,16077,16166,16019,16019,16169,16132,16150,16075,16100,15896,16152,16047,16215,16183,16040,16178,16178,16127,16099,16035,16169,16243,16323,16067,16150,16071,16144,16052,16118,15931,16187,16242,16096,16243,16090,16170,16170,16108,16137,16060,16081,16184,16323,16067,16078,16148,16104,16011,16174,16174,16123,16133,16196,16109,16117,16088,16088,16159,16153,16112,16127,16215,16215,16064,16046,16073,16081,16141,16351,16095,16143,16171,16145,16081,16226,16339,16083,16078,16209,15997,16071,16181,16181,16128,16070,16077,16018,16163,16293,16037,16146,16207,16147,16041,16124,16124,16093,16129,15987,16152,16175,16311,16055,16114,16116,16245,16052,16125,16148,16111,16111,16157,16040,15968,16174,16213,16106,16052,16161,16048,16142,16142,16147,16030,16102,16079,16153,16178,16129,16179,16179,16079,16060,16020,16103,16074,16078,16078,16164,16182,16163,16105,16046,16046,16160,16068,16060,16074,16125,16131,16131,16160,16026,16019,16153,16048,15924,16180,16087,16150,16048,16072,16040,16040,16139,16106,16077,16262,16117,16212,16212,16239,16043,16219,16119,16012,16105,16105,16111,16044,16161,16073,16020,16020,16135,16160,16096,16076,16110,16053,16053,16151,16066,16068,16129,16123,16114,15886,16142,16199,16181,16064,16090,16043,16099,16099,16128,16058,16016,16043,16167,16177,16177,16010,16158,16086,16112,16115,15888,16144,16135,16226,16110,16121,16053,15916,16172,16075,16061,16119,16137,16159,16159,16181,16075,16039,16242,16121,15977,15977,16141,16155,16207,16069,16107,16107,16114,16083,16102,16008,16071,16119,16119,16028,16124,16225,16022,16134,16130,16130,16137,16174,16086,16159,16056,16088,16088,16186,16154,16050,16092,16159,16146,16146,16070,16176,16225,16088,16118,16118,16093,16289,16118,16091,16141,16207,16207,16173,16151,16048,16195,16141,16202,16202,16058,16040,16145,16190,16140,16140,16159,16163,16153,16151,16106,16178,16178,16044,16064,16223,16131,16101,15955,16211,16151,16161,15998,16099,16053,16053,16085,16005,16134,16144,16088,15872,16128,16072,16029,16230,16109,16039,16081,16081,16267,16176,16049,16156,16162,16162,16130,16138,16018,16119,16180,16129,16129,16178,16091,16108,16169,16191,16191,16064,16070,16117,16160,16110,16082,16082,16096,15991,16130,16194,16068,15930,15930,16132,16121,16067,16105,16087,16087,16183,16269,16118,15998,16180,16129,16129,16128,16156,16166,16065,16136,16248,16248,11913,15882,16067,16164,16004,16159,16159,16201,16050,16129,16144,16119,16129,16129,16028,16126,16152,16117,16107,15903,16159,16138,16140,16131,16075,16110,15895,16151,16064,16168,16116,16131,16160,16160,16150,16130,16059,16141,16128,16195,16195,16216,16053,16097,16167,16122,16122,16077,16173,16031,16131,16092,16099,16099,16163,16126,16065,16137,16165,16342,16086,16050,16156,16087,16107,16169,16169,16178,16061,16091,16061,16260,16133,16133,16117,16174,16108,16164,16162,16311,16055,16219,16143,16127,16105,16121,15902,16158,16194,16044,16178,16057,16085,15329,15329,16090,16066,16131,16113,16163,16352,16096,16080,16057,16111,16146,16134,16134,16162,16092,16139,16120,16144,16028,16028,16142,16171,16066,16041,16154,16366,16110,16110,16128,16117,16125,16091,16091,16149,16050,16024,16154,16186,16072,16072,16090,16143,16206,16141,16073,16052,16052,16123,16158,16159,16197,16135,16135,16119,16128,16090,16063,16139,16153,16153,16019,16072,16128,16153,16129,16180,16180,16157,16207,16126,16158,16066,16066,16102,16177,16104,16202,16104,16159,16159,16090,16071,16070,16115,16127,15924,16180,16088,16122,16075,16085,16105,16105,16187,16056,16010,16150,16151,16166,16166,16124,16088,16166,16123,15991,15944,16200,16124,16152,16093,16106,16057,16057,16177,16163,16167,16021,16095,16106,16106,16088,16170,16162,16144,16266,16266,16115,16135,16159,16021,16240,16162,16162,16004,16154,16182,16073,16129,16299
The reference is relative to the chip position. See the datasheet for this.
Don't forget that gravity is an acceleration, so when the accelerometer is still, the output vector points downwards (in the Earth reference). You can store an initial value (an average on several points in the best case), and substract this value from your datapoints.
The best way to debug this is to plot the values in real time.

having X axis in special discrete values

i want to plot Y versus the corresponding values in X in MATLAB,and i want to see the points (x,y) just when x=5,10,2000.because these values are really far apart the graph is not good.what must be done with my X axis?
thank u.
If you just want to have the 5,10,2000 values plotted, then maybe do:
plot(X([5,10,2000]),Y([5,10,2000]),'o')
or else you can try plotting the whole thing, but represent the X-axis as log:
semilogx(X,Y)
HTH!

3D scatter plot with 4D data

I need to plot a 3D figure with each data point colored with the value of a 4th variable using a colormap. Lets say I have 4 variables X,Y,Z and W where W = f(X,Y,Z). I want a 3D plot with X, Y, and Z as the three axis. The statement scatter3(X,Y,Z,'filled','b') gives me a scatter plot in 3D but I want to incorporate the value of Z in the graph by representing the points as an extra parameter (either with different areas :bigger circles for data points with high value of Z and small circles for data points with low value of Z or by plotting the data points with different colors using a colormap). However, I am a novice in MATLAB and dont really know how to proceed. Any help will be highly appreciated.
Thanks in advance!
So just use z for the size vector (4th input) as well as the color vector (5th input):
z = 10*(1:pi/50:10*pi);
y = z.*sin(z/10);
x = z.*cos(z/10);
figure(1)
scatter3(x,y,z,z,z)
view(45,10)
colorbar
The size vector needs to be greater 0, so you may need to adjust your z accordingly.
You are already nearly there... simply use
scatter3(X,Y,Z,s,W);
where s is the point size (scalar, e.g. 3) and W is a vector with your W values.
You might also want to issue an
set(gcf, 'Renderer','OpenGL');
where gcf gets your current figure you are plotting in to significantly increase responsiveness when scattering a lot of data.

Matlab - Multiple 2D plots along a 3rd dimension

I'm trying to plot many 2D plots (x,y).
But...
each 2D plot is for a constant z.
So really my data is (x,y,z) but not z(x,y), which I believe are the requirements for using the "surf" command.
Could anyone help with this?
Example,
x = velocity
y = drag
I have multiple runs of y(x) for a constant temperature, z.
I just want to plot each (x,y) along a 3rd axis, temperature z.
Ideally I'd also want some sort of contour between the (x,y) plots so I can show the peaks/troughs etc.
Any help would be great.
If the runs are not independent (there is some trend over multiple runs) then it may make sense to use surf. You then need to construct your data such you have an X,Y, and Z - in this case I'd suggest you use the drag measurements as your Z (height).
Assuming that you have all the drag/velocity data in drag and velocity which are both of size [data points x number of runs]:
% construct matrix of run numbers
runs = repmat(1:numruns, [1, datapoints]);
runs = reshape(runs, datapoints, numruns);
% plot and label
surf(runs,velocity,drag);
xlabel('runs')
ylabel('velocity')
zlabel('drag')