A hydraulic pump or motor comprising: a rotatable shaft, a shaft sensor which measures the position or speed of rotation of the rotatable shaft, at least one cam having at least one lobe, a plurality of cylinders having working volumes which vary cyclically with rotation of the rotatable shaft, a low pressure working fluid line and a high pressure working fluid line, a plurality of valves (118, 126) regulating the flow of working fluid between each cylinder and the low and high pressure working fluid lines (26, 28), at least one said valve associated with each cylinder being an electronically controlled valve, wherein the hydraulic pump or motor comprises a valve control module configured to generate command signals to actively control the said electronically controlled valves (118, 126) in phased relationship to cycles of cylinder working volume, to thereby determine whether each cylinder carries out an active cycle in which there is a net displacement of working fluid or an inactive cycle in which there is no net displacement of working fluid, for each cycle of cylinder volume, the valve control module having a demand input which receives a displacement demand signal representative of a target net displacement of working fluid by the plurality of cylinders, characterized in that the valve control module is configured to generate said command signals so that the time averaged net displacement of the plurality of cylinders meets the displacement demand represented by the displacement demand signal, while selecting the pattern of command signals so that the frequency of one or more intensity peaks of the frequency spectrum of the pattern of active and inactive cycles of cylinder working volume carried out by the cylinders do not remain within one or more ranges of undesirable frequencies, taking into account the speed of rotation of the rotatable shaft. a rotatable shaft, a shaft sensor which measures the position or speed of rotation of the rotatable shaft, at least one cam having at least one lobe, a plurality of cylinders having working volumes which vary cyclically with rotation of the rotatable shaft, a low pressure working fluid line and a high pressure working fluid line, a plurality of valves (118, 126) regulating the flow of working fluid between each cylinder and the low and high pressure working fluid lines (26, 28), at least one said valve associated with each cylinder being an electronically controlled valve, wherein the hydraulic pump or motor comprises a valve control module configured to generate command signals to actively control the said electronically controlled valves (118, 126) in phased relationship to cycles of cylinder working volume, to thereby determine whether each cylinder carries out an active cycle in which there is a net displacement of working fluid or an inactive cycle in which there is no net displacement of working fluid, for each cycle of cylinder volume, the valve control module having a demand input which receives a displacement demand signal representative of a target net displacement of working fluid by the plurality of cylinders, characterized in that the valve control module is configured to generate said command signals so that the time averaged net displacement of the plurality of cylinders meets the displacement demand represented by the displacement demand signal, while selecting the pattern of command signals so that the frequency of one or more intensity peaks of the frequency spectrum of the pattern of active and inactive cycles of cylinder working volume carried out by the cylinders do not remain within one or more ranges of undesirable frequencies, taking into account the speed of rotation of the rotatable shaft.