This is one way on how to do it and might not be the best, there should be some other way.
You calculate the ball's x position and the middle position of the paddle (x coordinate too of course). For the formula, you could do it like this:
speed = extraSpeed * distance / (0.5f * paddleWidth) + constant;
For distance, you can do it like this:
abs(paddleMiddle.x - ball.x); We don't want it to be negative/minus.
Okay, with the formula above
distance / (0.5f * paddleWidth) will return
0.0f when the ball hits the middle (
distance = 0.0f), and will return
1.0f when the ball hits the edge of the paddle (it can return more than
1.0f though, you might want to do something about it like clamping the value or perhaps checking the distance from the side of the ball). This value will multiply
extraSpeed, so the ball will not gain any extra speed when it hits the middle and gain full extra speed when it hits the edge of the paddle. And
constant here will act as the base speed or you can say the slowest speed (when it hits the middle) you don't want the ball to stop when it hit the middle, do you?