Imagine that you’re a female frog. It’s mating time, and you’re choosing a male of your species. But you have a problem. How do you pick out your suitors’ calls from the cacophonous background noise—from, say, the rainbow of other frog species who live in your swamp?

It turns out that at least some frogs might have their own built-in noise-cancelling features: Lungs.

A new paper suggests that the vibration of a frog’s lungs feeds back into the frog’s eardrums, reducing their sensitivity to certain frequencies in a process that scientists think is similar to how noise-cancelling headphones work. So, at least in this species, the frog can quite literally tune out the pitches of unwanted calls—and more clearly hear the sounds of its own kind.

“It shows that evolution sometimes can fashion these rather smart solutions,” Jakob Christensen-Dalsgaard, a biologist at the University of Southern Denmark and one of the authors of the paper, published in Current Biology.

When the researchers discovered this phenomenon, they hadn’t actually been looking at noise-cancellation at all. They’d been trying to find out how frogs—in particular, green treefrogs, or Hyla cinerea, who live in wet areas in the southeastern US—can tell which direction a sound is coming from.

Frogs’ ears aren’t quite like ours. Our two ears are mostly independent of each other, but frogs’ two eardrums are connected through their larynx, meaning that one eardrum can hear sounds passed through the other eardrum. This configuration isn’t found in mammals, and it might seem alien, but it’s hardly unique to frogs: Lizards and alligators also hear this way.

For decades, scientists like Christensen-Dalsgaard had known  that there was some link between the connected eardrums and the puffing up of a frog’s lungs. They thought, for instance, that the vibrations from inflated lungs might help frogs pinpoint where a sound—a male frog’s call, say—is coming from.

The researchers tested this by shining lasers into frogs’ eardrums. By measuring the frequency of the reflected light and its shift thanks to the Doppler effect, scientists could understand precisely how a frog’s eardrums responded. The researchers played sounds from different angles to see if frogs’ lungs helped fine-tune their directional hearing.

“Long story short, they have nothing to do with directional hearing,” says Mark Bee, a biologist at the University of Minnesota, Twin Cities and a coauthor on the paper. “That left us with this puzzle of, like, well, the thing we set out to quantify doesn’t exist. What’s going on? So we started slicing and dicing the data in different ways.”

They found that frogs’ eardrums picked up far more sound from their lungs than from the opposite eardrums. Moreover, they found that lungs actually reduced eardrums’ sensitivity to sounds at certain frequencies. But what were those frequencies? The scientists wondered if they matched anything that might live in the treefrog’s natural habitat.

Using data from citizen scientists who had collected information on which amphibians lived where in the US, the scientists found that the resonant frequencies of the lungs matched the calls of the treefrogs’ neighbors in the wild. At the same time, the signals didn’t interfere with the treefrogs’ ability to hear the calls from their own species.

The researchers say they’ve only begun scratching the surface of understanding this process. But, for now, they think it’s quite like how noise-cancelling headphones listen to ambient noise and erase it. They believe that the lungs’ vibrations create sound waves at the same frequency as other frog species’ calls—but out of phase. The “peaks” of unwanted outside sound waves match the “valleys” of the lungs’ waves, and vice versa. The researchers think this is an evolved trait.

So, when the waves meet at the eardrum, they cancel each other out. And it only works at particular frequencies, allowing frogs to hear their own kind best.

“It’s purely mechanical,” says Christensen-Dalsgaard. “There’s no nerve processing or anything going into this.”

David C. Blackburn, a herpetologist at the University of Florida and the Florida Museum of Natural History, says the paper could open new opportunities into how researchers look at frogs, not just in the lab, but also in the field. In particular, he says that frogs’ lungs have never been a subject of particular interest because they’re considered so simple and basic next to those of other amphibians and reptiles.

Looking beyond Hyla cinerea, how many of the over 7000 known frog species have the same noise-cancelling abilities? Researchers say it’s impossible to say with certainty, partly because, according to Blackburn, frogs are an especially diverse lot. Some frogs don’t have ears, while others don’t have lungs. Some frogs call from holes in trees; some frogs’ females are far larger than their males.

But, says Bee, “The short answer is we think it probably is common in frogs.”

In fact, scientists have observed similar connections between lungs and eardrums in three different families of frogs whose last common ancestor lived some 150 million years ago. So it’s quite possible, according to Bee, that these abilities might have evolved that long ago.