Babies as young as 5 months can distinguish an upbeat tune, such as "Ode to Joy" from Beethoven's Ninth Symphony, from a lineup of gloomy tunes.

Researchers displayed an emotionally-neutral face for the baby while sad music played. When the baby looked away from the face, the music stopped and a new sad song would start. When the happier "Ode to Joy" played, the babies stared at the face three to four seconds longer, suggesting they were interested in the shift.

By 9 months old, babies can do the opposite, picking out the sorrowful sound of Beethoven's Seventh Symphony from a pack of happy pieces.

The finding is another example of how babies make sense of the world long before they can talk, said Brigham Young University psychology professor and study author Ross Flom.

"One of the first things babies understand communicatively is emotion, so for them the melody is the message," Flom said. "Our study showed that by nine months, babies are categorizing songs as happy or sad the same way that preschoolers and adults do."

The results of the musical study will be published in the upcoming issue of the journal Infant Behavior and Development.

So what makes a happy song?

BYU music professor Susan Kenney, who was not involved with the study, noted some of the technical differences between the happy and sad songs the babies heard.

"The happy songs were all in major keys with fairly short phrases or motives that repeated," Kenney said. "The tempo and melodic rhythms were faster than any of the sad selections, and the melodies had a general upward direction. Four of the sad songs were in minor keys and all had a slower beat and long melodic rhythms. For an infant to notice those differences is fascinating."