Old spark plugs, weak engine mounts, dodgy sensor. Before running down the more expensive route, try a tank of high octane fuel through the car and you'll see an improvement all round.
Even if the knock sensor is slightly lose it will rattle and "detect knock" quite a simple sensor really.