The Philippine Electronics and Technology Forum
February 10, 2012, 01:21:46 PM *
Welcome, Guest. Please login or register.

Login with username, password and session length
 
   Home   Help Search Login Register  

Pages: 1 [2]   Go Down
  Print  
Author Topic: curve fitting... tell me about it!!! :( [MATLAB]  (Read 3925 times)
insomartin
Guest
« Reply #20 on: July 13, 2009, 04:13:17 AM »

can't wait for a mcu code!
Logged
The Philippine Electronics and Technology Forum
« Reply #20 on: July 13, 2009, 04:13:17 AM »

 Logged
z22
CR2032 Battery
**

Pogi/Ganda Points: 3
Offline Offline

Gender: Male
Posts: 33


« Reply #21 on: July 13, 2009, 04:18:54 AM »

Hmm paano ba i-eexplain....
Kung log yung scale ng y-axis, almost linear yung mga curves, so transform the measured resistance and the table to the log domain (parang dB lang), then use bilinear interpolation to get the RH value. Kasi kung yung raw values yung gagamitin, baka bicubic interpolation yung kailangan, eh medyo mahirap yun (I'm still reading Numerical Recipies). Pwede kaya?
If not, pwede kaya yung model na

R = SUM(i=0..5, j=0..7)aijTiHj,

R = resistance, T = temperature, H = RH, aij yet to be determined.
Logged
insomartin
Guest
« Reply #22 on: July 13, 2009, 04:31:38 AM »

that is where i can't answeeer.
http://www.intmath.com/Exponential-logarithmic-functions/7_Graphs-log-semilog.php
sa pinaka babang page may applications. hope that could help...

madaming CNC codes na ginagamit ko using spline curves and linear interpolate. but walang source code...
Logged
z22
CR2032 Battery
**

Pogi/Ganda Points: 3
Offline Offline

Gender: Male
Posts: 33


« Reply #23 on: July 13, 2009, 06:20:45 PM »

Same table, but resistance in Kohm replaced with log10(resistance in Kohm):
Code:
       15.000 25.000 35.000 45.000 55.000
------------------------------------------
20.0 |  4.000  3.699  3.491  3.243  3.068
30.0 |  3.367  3.114  2.875  2.633  2.447
40.0 |  2.740  2.491  2.279  2.061  1.857
50.0 |  2.190  1.940  1.748  1.580  1.398
60.0 |  1.708  1.491  1.301  1.176  1.041
70.0 |  1.301  1.114  0.954  0.833  0.740
80.0 |  0.919  0.756  0.623  0.519  0.431
90.0 |  0.613  0.431  0.322  0.230  0.146
Suppose the temperature is 29 degrees C. Interpolate the values between the 25 degrees and 35 degrees column:
Code:
       25.000 29.000 35.000
----------------------------
20.0 |  3.699  3.616  3.491
30.0 |  3.114  3.018  2.875
40.0 |  2.491  2.406  2.279
50.0 |  1.940  1.863  1.748
60.0 |  1.491  1.415  1.301
70.0 |  1.114  1.050  0.954
80.0 |  0.756  0.703  0.623
90.0 |  0.431  0.388  0.322
If the measured resistance is 100K, log10(100) = 2. Interpolate again using the 29 degrees column, the RH is 47%

Tanong ko lang po, paano yung mapping from resistance to measured ADC value, check ko sana sa generated table.
Logged
marcelino
Technical People
Solar Power Satellite
*****

Pogi/Ganda Points: 247
Offline Offline

Posts: 5861


...keep moving forward! - Robinson's


« Reply #24 on: July 13, 2009, 08:46:36 PM »

very simple yung circuit na ginawa ko... parang ganito:


RE0 = HIGH;
some_delay(x);    //to emulate half of my preferred frequency (half lang.)
var0 = read_adc();
RE0 = LOW;
some_delay(x);   
RE1 = HIGH;
some delay(x);
var1 = read_adc;
RE1 = LOW;
some delay();

so makikita natin na dalawang readings ang makukuha, var0 and var1.... the values presented by these two are 10-bits. so ang total nyan ay nasa 1024... actually nag-eexceed, pero ok lang yun. di naman ganun ka accurate yung ginagawa kong data gathering, but at least, i can read the changes of the resistance. i will just cheat the output by having to compare it with the existing (commercial) hygrometer. dagdag-bawas nalang siguro.

makikita natin during RE0 = HIGH, RE1 = LOW - providing a voltage divider among the 39k and the sensor. then mababasa na yung var0. in reverse, mababasa yung var1. pero i based my calculation from the reading of the 39k. so mas importante saaking yung readin of var1.

ang ginawa ko nalang ay mag set na ng table. given var1 and the temperature, hahanapin nya yung row number, which is the humidity. so kailangan ko talgang i plot ang bawat content ng axis.

eto, using cubic spline, nagawa ko to (just part of the generated values):
Code:
TEMP 23 24 25 26 27 28 29
--------------------------------------------------------------
20 5648.24 5307.00 5000.00 4724.00 4475.76 4252.03 4049.58
21 5016.94 4715.44 4443.33 4197.89 3976.39 3776.08 3594.25
22 4439.72 4174.43 3934.20 3716.74 3519.79 3341.06 3178.28
23 3913.99 3681.57 3470.33 3278.41 3103.93 2945.00 2799.76
24 3437.16 3234.43 3049.46 2880.75 2726.75 2585.94 2456.79
25 3006.64 2830.59 2669.32 2521.59 2386.19 2261.89 2147.47
26 2619.84 2467.65 2327.63 2198.81 2080.22 1970.90 1869.89
27 2274.18 2143.19 2022.12 1910.24 1806.78 1711.00 1622.17
28 1967.05 1854.79 1750.53 1653.73 1563.81 1480.22 1402.39
29 1695.88 1600.02 1510.58 1427.14 1349.28 1276.59 1208.65
30 1450.16 1372.82 1300.00 1230.99 1165.52 1103.43 1044.56
31 1240.15 1176.72 1116.52 1058.79 1003.35 950.18 899.28
32 1059.76 1007.67 957.87 909.56 862.66 817.23 773.34
33 906.16 863.16 821.78 781.25 741.53 702.74 665.01
34 776.56 740.67 705.97 671.77 638.03 604.91 572.54
35 668.15 637.68 608.18 579.04 550.23 521.90 494.16
36 578.10 551.67 526.14 500.99 476.21 451.90 428.15
37 503.63 480.13 457.57 435.55 414.03 393.08 372.74
38 441.91 420.53 400.20 380.63 361.77 343.62 326.19
39 390.14 370.37 351.77 334.17 317.50 301.71 286.74

converting to the voltage across 39k (integer value na):
value = (39k*1024)/(39k+var1)

Code:
TEMP 23 24 25 26 27 28 29
-----------------------------------------------------------
20 7 7 8 8 9 9 10
21 8 8 9 9 10 10 11
22 9 9 10 11 11 12 12
23 10 11 11 12 13 13 14
24 11 12 13 14 14 15 16
25 13 14 15 16 16 17 18
26 15 16 17 18 19 20 21
27 17 18 19 20 22 23 24
28 20 21 22 24 25 26 28
29 23 24 26 27 29 30 32
30 27 28 30 31 33 35 37
31 31 33 35 36 38 40 43
32 36 38 40 42 44 47 49
33 42 44 46 49 51 54 57
34 49 51 54 56 59 62 65
35 56 59 62 65 68 71 75
36 65 68 71 74 78 81 85
37 74 77 80 84 88 92 97
38 83 87 91 95 100 104 109
39 93 98 102 107 112 117 123

so kapag nakaread ako ng value ng 101 and the temperature is 27degrees. i put that value under 100 na kasi di naman nagexceed sa 112 (the next value with 27deg). then the humidity will be 38%RH.]

nga pala, i have decided of using cubic spline nalang... i might not include the equation on the documentation... sasabihin ko nalang na generated nalang using MATLAB.

pero baka may suggestion kayo... open pa naman. Cheesy
Logged

"Don't take life seriously. After all, no one has ever come out of it alive. -Bugs Bunny"
z22
CR2032 Battery
**

Pogi/Ganda Points: 3
Offline Offline

Gender: Male
Posts: 33


« Reply #25 on: July 13, 2009, 09:15:22 PM »

1. Look up table: 1491 values, simple code.
2. Smaller look up table + bilinear interpolation
3. Bicubic spline interpolation: bad idea, sobrang daming coefficients (16 per grid square)

LUT na lang...
Logged
marcelino
Technical People
Solar Power Satellite
*****

Pogi/Ganda Points: 247
Offline Offline

Posts: 5861


...keep moving forward! - Robinson's


« Reply #26 on: July 13, 2009, 09:58:05 PM »

^another thing... kukunin ko lang naman yung from 15 - 35deg ... di na kasi realistic ibang temp range. (at least for time being - wait fo the global warming.)

so LUT nalang. thanks sa suggestion. and thank you for the comparison.

did you know that that table consumed 5% of my 64k ROM? hehehe Grin pic18f4620.
may idadagdag pa akong isa after characterization ko nung moisture sensor ko, gypsum block...
(eto naman ay weight vs resistance or voltage)
Logged

"Don't take life seriously. After all, no one has ever come out of it alive. -Bugs Bunny"
z22
CR2032 Battery
**

Pogi/Ganda Points: 3
Offline Offline

Gender: Male
Posts: 33


« Reply #27 on: July 13, 2009, 11:40:33 PM »

Isa pa pala, delta compression. Store mo lang yung diffrence from the last, para kasya sa isang byte, or less
Logged
marcelino
Technical People
Solar Power Satellite
*****

Pogi/Ganda Points: 247
Offline Offline

Posts: 5861


...keep moving forward! - Robinson's


« Reply #28 on: July 13, 2009, 11:44:41 PM »

Isa pa pala, delta compression. Store mo lang yung diffrence from the last, para kasya sa isang byte, or less

papano yan Huh

di ko gets...  Huh
Logged

"Don't take life seriously. After all, no one has ever come out of it alive. -Bugs Bunny"
z22
CR2032 Battery
**

Pogi/Ganda Points: 3
Offline Offline

Gender: Male
Posts: 33


« Reply #29 on: July 14, 2009, 12:09:08 AM »

Ex. may 4 akong values
900 915 923 933
10 bits each for storage = 40 bits total

Ganito gagawin
915-900=15
923-915=8
933-923=10
Yung mga differences pwedeng 4 bits lang
Ang ilalagay mo sa memory
900 15 8 10
22 bits lang kailangan
Logged
marcelino
Technical People
Solar Power Satellite
*****

Pogi/Ganda Points: 247
Offline Offline

Posts: 5861


...keep moving forward! - Robinson's


« Reply #30 on: July 14, 2009, 01:00:06 AM »

Ex. may 4 akong values
900 915 923 933
10 bits each for storage = 40 bits total

Ganito gagawin
915-900=15
923-915=8
933-923=10
Yung mga differences pwedeng 4 bits lang
Ang ilalagay mo sa memory
900 15 8 10
22 bits lang kailangan


ayos yang technique na yan ah... very useful lalo na siguro kung sobrang dami ng inputs...  Cheesy
nakikita ko, mas mabilis pa ang accessing ng data...
sige try ko to kung magkaroon pa ako ng time mag code. honestly, halos tapos na kasi. isa pa, 5 nodes lang naman ang babasahin ko...

nice learning! pogi mo!!! Cheesy
Logged

"Don't take life seriously. After all, no one has ever come out of it alive. -Bugs Bunny"
z22
CR2032 Battery
**

Pogi/Ganda Points: 3
Offline Offline

Gender: Male
Posts: 33


« Reply #31 on: July 14, 2009, 06:56:08 PM »

Mula sa table, 15 degrees column:

x[1] = 4
x[2] = 4
x[3] = 5
x[4] = 5
x[5] = 6
...
x[69]  = 906
x[70] = 916
x[71] = 927


Gagamit tayo ng linear predictor x'[n] = 3*x[n-1] - 3*x[n-2] + x[n-3] and measure its error e[n] = x'[n] - x[n].
Given na yung unang 3 values: 4, 4, 5.
Predicted 4th value: x'[4] = 3*x[3] - 3*x[2] + x[1] = 3*5 - 3*4 + 4 = 7.
Prediction error: e[4] = x'[4] - x[4] = 7 - 5 = 2.

Tuloy tuloy lang...
x'[5] = 4, e[5] = -2
x'[6] = 8, e[6] = 1
x'[7] = 8, e[7] = 0
...
x'[69] = 908, e[69] = 2
x'[70] = 916, e[70] = 0
x'[71] = 926, e[71] = -1

Ang ilalagay mo sa memory ay x[1], x[2], x[3], e[4], e[5], e[6], ..., e[69], e[70], e[71]:

4, 4, 5, 2, -2, 1, 0, -1, 2, -3, 2, -1, 1, -1, 0, 1, 0, 0, 1, 0, -2, 1, -2, 0, 0, 0, -3, 1, -2, -2, 2, 0, 6, 4, 6, 1, 3, -4, -4, -5, -4, -3, 0, 1, -1, 1, 1, -1, 1, 1, 4, 2, 0, 3, -2, 2, -3, 2, -3, -1, 0, -2, 0, 0, 1, -2, 3, -3, 2, 0, -1

Kasya na sa 4-bit signed integer yung bawat value, so yung buong table 746 bytes. Yung post ko kanina (store the difference) kailangan ng 6 bits per value.

Madali lang i-reconstruct yung actual values: x[n] = x'[n] - e[n].
Logged
piona
Gas Turbine
**

Pogi/Ganda Points: 112
Offline Offline

Posts: 2963


earth - evils = heaven


« Reply #32 on: July 14, 2009, 07:19:51 PM »


dapat may inverse curve equation basi sa R versus H values e, para ipadaan mo lang yong inputs sa equation ayos na, kahit anong values okay....

w8 gawa ako ng inverse curve function....
Logged

love without accomplishing the laws, is complicated - sshrekk
piona
Gas Turbine
**

Pogi/Ganda Points: 112
Offline Offline

Posts: 2963


earth - evils = heaven


« Reply #33 on: July 14, 2009, 08:38:32 PM »

Eto sampol ng R versus H inverse curve:



kailangan to para paggawa ng circuit ipadaan lang ang sensor input don sa equation okay na, either > or < the resultant values would trigger whatever, depende na lang sa application nito.

i think the thread starter wants to fit the R-H curve relationship into a formula or equation to use the sensor in the circuit at any given analog values of the sensor.

Logged

love without accomplishing the laws, is complicated - sshrekk
piona
Gas Turbine
**

Pogi/Ganda Points: 112
Offline Offline

Posts: 2963


earth - evils = heaven


« Reply #34 on: July 14, 2009, 11:18:06 PM »

all i got for 15degC



yong RH30 parang imposible  Grin





Logged

love without accomplishing the laws, is complicated - sshrekk
e.novacek
Size D Battery
******

Pogi/Ganda Points: 58
Offline Offline

Gender: Male
Posts: 285


The LionHeart


« Reply #35 on: July 18, 2009, 04:24:15 PM »


Isa pa pala, delta compression. Store mo lang yung diffrence from the last, para kasya sa isang byte, or less

also known as "finite difference" technique or the difference method..
Logged

Take the gun. Leave the cannoli.
-Mario Puzo
insomartin
Guest
« Reply #36 on: December 09, 2009, 01:20:32 AM »

i'm trying to solve this using eureqa...

and walang sin/cos/log sa flowcode... help naman.
Logged
insomartin
Guest
« Reply #37 on: December 09, 2009, 09:44:02 AM »

Logged
The Philippine Electronics and Technology Forum
   

 Logged
Pages: 1 [2]   Go Up
  Print  
 
Jump to:  


Related Topics
Subject Started by Replies Views Last post
Looking for D.C. motor 3/4 hp, 24v (with torque-rpm curve data sheet)
Looking For/Wanted to Buy
hardworker 0 144 Last post April 01, 2010, 09:05:42 PM
by hardworker
Curve fit function MiscEI Misc Electronics Calculator.
Microcontroller/Microprocessor Unit Projects and Programming
DigitalMind 0 262 Last post October 20, 2010, 05:11:49 AM
by DigitalMind
Blackberry Curve 8520
Items For Sale
weemallasiatel 1 92 Last post July 05, 2011, 03:59:45 PM
by circuit_zero
simetrix simulator transfer curve
Electronics Design Automation and Simulation Softwares
jep_pogi 7 153 Last post July 07, 2011, 10:59:47 PM
by rdpzycho
Powered by MySQL Powered by PHP Powered by SMF 1.1.15 | SMF © 2011, Simple Machines Valid XHTML 1.0! Valid CSS!