A magnitude 4.0 earthquake has been recorded off the coast of Western Australia.