Frequency operator for anharmonic oscillators