Does it ever seem like your dog is in tune with your emotions? You may be on to something.

In new experiments, dogs showed signs of understanding whether a human or a dog was happy or mad based on facial expressions and vocalizations.

The research, published in the journal Biology Letters, set out to explore the emotional connection between man and his best friend.

"We still didn't know if the dogs ... can somehow understand that, say, a happy facial expression is positive and a negative facial expression is negative," says study leader Natalia de Souza Albuquerque, a Ph.D. student in experimental psychology at the University of São Paulo in Brazil.

For the research, Albuquerque and her team recruited 17 pet dogs from around Lincoln, England, and put the canines through two rounds of experiments in their laboratory.

Doggy Trials

In the first trials, each dog was placed in front of two screens and presented with an image of a dog or human with either a happy or angry facial expression. The images were then paired with a variety of sounds—a playful or aggressive bark for dogs, and a phrase in an unfamiliar language—Brazilian Portuguese—in a happy or angry tone for people. (Read why dogs are even more like us than we thought.)

Related: This is What Your Dog Does When You're Angry

When exposed to complimentary images and sounds in both humans and dogs—say, a happy dog facial expression and playful bark—the dogs looked at the screens longer than if the facial expression did not match the sound.

Their paying attention was a clue that the dogs recognized the emotions.

On the other hand, when dogs heard a neutral sound, the animals lost interest, looking around the room instead of at the screen—an indicator that the dogs had correctly discerned a lack of emotion.

Clever Pups

According to Albuquerque, dogs' ability to connect emotionally with humans and dogs is neither an instinct or learned behavior, but rather a sign of cognitive ability.

"The dogs had to extract the information from the sound, then associate this information with the image, and that involves very complex psychological mechanisms," she says. (Read why dogs are so friendly.)

Surprisingly, the team discovered that the dogs were better at recognizing emotions of their fellow species than those of humans.

"That was quite interesting," Albuquerque says, "because it makes sense to think that dogs already have that ability [to emotionally connect] and use that, and develop that, to interact with humans."

Indeed, humans and dogs have lived side by side by some 30,000 years, and along the way, evolution seems to have given dogs the skills to read their owners' needs and emotions.

Tugging the Heartstrings

Next, Albuquerque plans to investigate dogs' emotional reactions, and how they use their understanding of emotion to interact with humans.

For instance, scientists have already been investigating how dogs may know their owners so well they can manipulate them for maximum effect.

An October study showed that dogs will make the classic "sad puppy face"—raising their inner eyebrows to make their eyes look larger and more infant-like—when looking into a human's eyes.