This one may be simple and only cost you less than $100. More than likely your crankshaft sensor has completely failed or fails once it heats up. The ECM takes the readings from the crankshaft and camshaft position sensors and uses that to determine when to fire the injectors, spark the plugs and shift the transmission.
You should be able to replace this yourself fairly easily. I had one fail on my old car when it got warmed up the car would not restart until it cooled down. Eventually, it completely failed.
If the problem is because of a wiring fault that can be quite a bit more difficult to track down. I'd start by testing the sensor or just replacing it.
Check this link for more details
2004 Hyundai Sonata P0320 Diag Err Cd (Ignition Failure Sens
Personally, I prefer to replace defective sensors with OEM parts
MISFIRE SENSOR for 2002 HYUNDAI SONATA|27370-38000