Finetuning is reliant on playtesting. But I can give you some hints:
Depending on how long you want the TD to go, you need to use multi-order polynomials. 50+ rounds will need at least 3 I think, but 4 could be better. If you want it to go even longer, expand to 5.
So your basic formula could look like this:
HP(for wave x)= ax^4+bx^3+cx^2+dx+e
Now you need to calculate the gold that is available up to that level and you can calculate the difficulty:
difficulty = HP / (gold available until this point)
Make sure it gets harder with each wave, at first maybe a slight rise and later when you want the game to become really hard, you wanna have a bigger rise in difficulty per level.
This ofc means you need to balance out the gold income to your HP formula. And your towers need to be balanced around the money (or other ressources) they cost. Things you need to factor in when balancing towers are things like range (not linearly ofc), fire rate, damage, how much worth their special abilities are (like splash, slow, ...).
Hope that helps and happy playtesting.