The extremely brief answer to your question is that origin of the doctrine of the trinity is the teaching of Jesus and the New Testament (with a little bit of support from the Old Testament).
However, this is a grossly simplified and to some extent even misleading answer, so you deserve quite a bit better than that.
The doctrine of the trinity, as defined by the Nicene Creed (AD 325) confirmed by the Council of Constantinople (AD 381) and amplified somewhat by the Council of Calchedon (AD 451) is that the Father, the Son and the Holy Spirit are of the same substance (Greek homoiousis). Jesus is fully human and fully God, as worked out at Calchedon. Jesus, while in the body on the earth was one person with two natures, both divine and human completely joined and unified. Here is an extended quote from Calchedon:
We should confess that our Lord Jesus is one and the same Son; the same perfect in Godhead and the sme perfect in manhood, truly God and truly man, the same of a rational soul and body; consubstantial with the Father in Godhead and the same consubstantial with us in manhood; like us in all things except sin; begotten of the Father before all ages as regards to his Godhead and in the last days the same, for us and for our salvation… Later the church completed the process to say without ambiguity that the Holy Spirit is also consubstatial with the Father and the Son.
These creeds were hammered out over a nearly two hundred year period by the church. In the process, teachings eventually considered heretical, such as those of Arian (Jesus is a great but created being) or that (supposedly) of Nestor (that the humanity of Jesus is separate somehow from the divinity of Jesus–with the divinity being more essential) were pronounced by the biships to be incorrect. The first we know of to use the word Trinity was Tertullian in the first decade of the third century. He argued even at this early date that the trinity were consubstantial (ie of one substance).
Perhaps the best question we can ask is whether this doctrine, as defined by the Orthodox Christian Church in the third through fifth centuries is indeed true and biblical. Because you did not ask this question, I will leave you to think carefully and deeply about that. I believe that it is conceivable that the church overly defined the "trinity" ie overly defined the nature of the relationship between Father Son and Spirit, but I see nothing in this creed which contradicts the Scripture. I have studied the process by which these creeds were created fairly carefully. My conclusion is that the Church fathers put into relatively concrete form what was more or less the general thinking of the church from the beginning, although the words to express the nature of God were developed over a period of time.
John Oakes, PhD