# -*- coding: utf-8 -*-
# ---
# jupyter:
#   jupytext:
#     text_representation:
#       extension: .jl
#       format_name: light
#       format_version: '1.5'
#       jupytext_version: 1.14.4
#   kernelspec:
#     display_name: Julia 0.6.4
#     language: julia
#     name: julia-0.6
# ---

# # Calibração do termistor

using Plots
gr()


include("../src/ThermistorHW.jl")
using ThermistorHW

Tc = [0.0, 5, 10, 15, 20, 25, 30, 35, 40, 50, 60.5, 70.3, 75, 80, 85, 90]
R1 = [14.11, 11.66, 9.44, 7.75, 6.37, 5.28, 4.4, 3.7, 3.09, 2.21, 1.561, 1.118, 0.961, 0.817, 0.701, 0.602]
R2 = [13.92, 11.63, 9.51, 7.73, 6.36, 5.26, 4.41, 3.69, 3.08, 2.20, 1.553, 1.115, 0.954, 0.815, 0.697, 0.6]
R3 = [13.70, 11.42, 9.16, 7.48, 6.16, 5.09, 4.29, 3.58, 3.01, 2.12, 1.503, 1.083, 0.922, 0.791, 0.674, 0.583];

plot(Tc, R1)
plot!(Tc, R2)
plot!(Tc, R3)

Rt1 = Thermistor(5.28, 3500, 25)
Rt2 = Thermistor(5.26, 3500, 25)
Rt3 = Thermistor(5.09, 3500, 25)
plot(Tc, R3)
plot!(Tc, Rt3.(Tc))

using CurveFit

# +
T0 = Rt1.T₀
oot0 = 1/T0
Tk = Tc .+ 273.15
oot = 1./Tk;
lnR1 = log.(R1)
lnR2 = log.(R2)
lnR3 = log.(R3)
fit1 = linear_fit(oot[6:10], lnR1[6:10])
fit2 = linear_fit(oot[6:10], lnR2[6:10])
fit3 = linear_fit(oot[6:10], lnR3[6:10])

B = [fit1[2], fit2[2], fit3[2]]
A = [fit1[1], fit2[1], fit3[1]]
R0 = @. exp(A+B/T0)
# -

B

Rt = Thermistor.(R0, B, 25.0)

plot(Tc, R1)
plot!(Tc, Rt[1].(Tc))

plot(Tc, R2)
plot!(Tc, Rt[2].(Tc))

plot(Tc, R3)
plot!(Tc, Rt[3].(Tc))

# +
err1 = (Rt[1].(Tc) - R1) ./ R1 * 100
err2 = (Rt[2].(Tc) - R2) ./ R2 * 100
err2 = (Rt[3].(Tc) - R3) ./ R3 * 100




# +
Ro = [5.28, 5.26, 5.01] 

fator =(Tk*T0) ./(Tk - T0)

B1 = fator .* log.(R1/Ro[1])
B2 = fator .* log.(R2/Ro[2])
B3 = fator .* log.(R3/Ro[3])
[B1 B2 B3]
# -

plot(Tc, (Rt[1].(Tc) - R1)./R1)

B



StarcoderdataJupyterScriptsDedupFiltered