Scipy: Signal to noise ratio (SNR)

Created on 31 Jul 2018  路  3Comments  路  Source: scipy/scipy

Hi, there is no signal to noise ratio in SciPy. It used to be in scipy.stats but they removed it. I propose adding it in the form SNR = mean/standard deviation (of the signal in a given neighbourhood), as given as the alternative definition here: https://en.wikipedia.org/wiki/Signal-to-noise_ratio

As input the function could take the signal in a 1d numpy array, and would by default output the SNR of the entire signal. It could also take a second argument, the length of a neighbourhood to calculate moving mean/standard deviation, and then output an array of SNR for each neighbourhood.

I'm happy to implement this, but need some guidance if its wanted. Which file should I add this code to? Should it be in C/C++ or python? Many thanks.

scipy.signal wontfix

Most helpful comment

Since SNR like that is basically a one-liner, I don't quite see a case to add it back. Additionally, there's a reason that there are various definitions, it depends on the situation. E.g. for your proposed one of mean/std, that wikipedia page you link says
Notice that such an alternative definition is only useful for variables that are always non-negative

For reference, here's what the old function in scipy.stats did:

    a = np.asanyarray(a)
    m = a.mean(axis)
    sd = a.std(axis=axis, ddof=ddof)
    return np.where(sd == 0, 0, m/sd)

All 3 comments

Since SNR like that is basically a one-liner, I don't quite see a case to add it back. Additionally, there's a reason that there are various definitions, it depends on the situation. E.g. for your proposed one of mean/std, that wikipedia page you link says
Notice that such an alternative definition is only useful for variables that are always non-negative

For reference, here's what the old function in scipy.stats did:

    a = np.asanyarray(a)
    m = a.mean(axis)
    sd = a.std(axis=axis, ddof=ddof)
    return np.where(sd == 0, 0, m/sd)

Since SNR like that is basically a one-liner, I don't quite see a case to add it back.

I agree.

Two -1s to adding it back, let's call the decision made and close this.

Was this page helpful?
0 / 5 - 0 ratings