Deividas said:
Maybe someone can explain, why at higher rpm shorter header is better, and at lower rpm longer header is better?
When the exhaust valve opens, a huge pressure wave is sent throughout the pipe. That pressure wave travels at the speed of sound. When it reaches the atmosphere (or an area increase large enough to simulate one), this pressure wave is reflected as a lower pressure wave (think vacuum). This lower pressure wave travel also at the speed of sound towards the cylinder (yes, against gas flow). When it reaches the valve, it then reflects again as a high pressure wave, but lower than the first one. And this process keeps going on until the pressure stabilizes through the pipe. Of course - in an engine - the pressure never quite stabilize because of the engine cycle.
Because we know the speed at which the waves travel, the trick is to tune the length of the exhaust pipe such that the low pressure wave arrives at the cylinder at a moment where the exhaust valve is open to facilitate the scavenging process. The wave can return in a following cycle or even at another cylinder valve (when there is exhaust collector).
You can see this as the molecules' way to communicate between each other. When the exhaust valve opens, the gas molecules are saying: «We're getting out, make space for us!». Of course, the molecules on the other side of the valve can't really move so they just pass the message along the pipe until it reaches an open end. At this point, the molecules are saying: «We found free space, keep coming!» But that message has to go back to the cylinder where the high pressure is.
The same process is used to tune the intake length, except that a low pressure wave is sent when the intake valve opens («We found free space, send more molecules») and it is reflected as a high pressure wave going toward the cylinder («We found a bunch of molecules; they're coming!»).
Search for «pressure wave» and «fluid dynamics».
This article is a good start.