<p>Estimating SNR means first estimating the (background) noise.
The two spectrograms are great as they emphasize that in most cases signal would be hidden in background noise when displayed as broadband time series.</p>
<p>One solution is: working in spectrogram domain and quick answer is:</p>
<pre><code>[~,F,T,P]=spectrogram(xx,hann(nw),no,nfft,fs);
N=median(P,2);
SNR=sqrt(P./N);
</code></pre>
<p>The median approximates the noise estimate for a reasonable noise window reducing the influence of a spiky signal.
If you have a noise window without the signal then you would use</p>
<pre><code>N=mean(P,2);
</code></pre>
<p>P and N are in terms  of spectral power (here: power spectral density PSD), so in order to get a amplitude-based SNR by taking the sqrt.</p>
<p>SNR is here a spectral matrix.</p>
<p>Note: I'm using Matlab 2019a, so that &quot;./&quot; works properly even if P is a matrix and N is a vector.</p>
<p>If you wanted to work in the time domain, then you must bandpass filter your data to remove the out-of-interest noise.</p>
<p>For pulse sequences in your data you can then still use the median approach</p>
<pre><code>nn=median(xx);
snr=xx/nn;
</code></pre>
<p>or if you know that xxo is data without signal (e.g. 1 or 2 seconds before signal) then you can use</p>
<pre><code>nn=std(xxo);
snr=(xx-mean(xx))/nn;
</code></pre>
<p>snr is here a time vector.</p>

CC BY-SA 4.0
2022-07-23T05:37:37.573Z
2022-07-23T05:37:37.573Z
WMXZ
<p>I was wondering if anyone could provide some insight on how to calculate the SNR of low frequency baleen whale calls? Matlab has a SNR function,but when I try that it doesn't seem to be capturing the frequencies of interest for the call. I included spectrograms of the calls I'm interested in. One is a Rice's whale long-moan call and the other is a downsweep pulse sequence of the same species.
<a href="https://i.sstatic.net/Qg0Io.jpg" rel="noreferrer"><img src="https://i.sstatic.net/Qg0Io.jpg" alt="enter image description here" /></a></p>
<p><a href="https://i.sstatic.net/pvBzt.jpg" rel="noreferrer"><img src="https://i.sstatic.net/pvBzt.jpg" alt="enter image description here" /></a></p>

CC BY-SA 4.0
2022-07-22T23:24:37.513Z
Could you share which parameters you used with the Matlab SNR function please?
Noil
CC BY-SA 4.0
2022-07-25T16:53:54.797Z
Sure all I did was snr(x,Fs) where x is a 30s window centered on the call (from a 30 min wav file -also used that to make the spectrogram) and Fs is is 2000. This is the output I get, but I know the fundamental frequency it's focusing on isn't the long-moan call since it's too low
atcook65
CC BY-SA 4.0
2022-07-28T15:11:21.120Z
@atcook65 comments can disappear over time and are often ignored. Could you edit your question directly to include the settings specified in your comment?
selene
<snr>
How to calculate the SNR of a call in Matlab
# How to calculate the SNR of a call in Matlab

(Asked by: username_0 on 2022-07-22)

I was wondering if anyone could provide some insight on how to calculate the SNR of low frequency baleen whale calls? Matlab has a SNR function,but when I try that it doesn't seem to be capturing the frequencies of interest for the call. I included spectrograms of the calls I'm interested in. One is a Rice's whale long-moan call and the other is a downsweep pulse sequence of the same species.
[![enter image description here](https://i.sstatic.net/Qg0Io.jpg)](https://i.sstatic.net/Qg0Io.jpg)

[![enter image description here](https://i.sstatic.net/pvBzt.jpg)](https://i.sstatic.net/pvBzt.jpg)

**Tags:** snr

> **Comments:**
> **username_1**: Could you share which parameters you used with the Matlab SNR function please?  
> **username_0**: Sure all I did was snr(x,Fs) where x is a 30s window centered on the call (from a 30 min wav file -also used that to make the spectrogram) and Fs is is 2000. This is the output I get, but I know the fundamental frequency it's focusing on isn't the long-moan call since it's too low  
> **username_2**: @username_0 comments can disappear over time and are often ignored. Could you edit your question directly to include the settings specified in your comment?  

---

## 1 answers

### Answer by username_3 on 2022-07-23. Score: 9 | Accepted answer

Estimating SNR means first estimating the (background) noise.
The two spectrograms are great as they emphasize that in most cases signal would be hidden in background noise when displayed as broadband time series.

One solution is: working in spectrogram domain and quick answer is:

```
[~,F,T,P]=spectrogram(xx,hann(nw),no,nfft,fs);
N=median(P,2);
SNR=sqrt(P./N);

```

The median approximates the noise estimate for a reasonable noise window reducing the influence of a spiky signal.
If you have a noise window without the signal then you would use

```
N=mean(P,2);

```

P and N are in terms of spectral power (here: power spectral density PSD), so in order to get a amplitude-based SNR by taking the sqrt.

SNR is here a spectral matrix.

Note: I'm using Matlab 2019a, so that "./" works properly even if P is a matrix and N is a vector.

If you wanted to work in the time domain, then you must bandpass filter your data to remove the out-of-interest noise.

For pulse sequences in your data you can then still use the median approach

```
nn=median(xx);
snr=xx/nn;

```

or if you know that xxo is data without signal (e.g. 1 or 2 seconds before signal) then you can use

```
nn=std(xxo);
snr=(xx-mean(xx))/nn;

```

snr is here a time vector.


---

