# Calculate seismic to signal ratio and peak seismic to noise ratio?

**URL:** <https://community.wolfram.com/t/calculate-seismic-to-signal-ratio-and-peak-seismic-to-noise-ratio/13696>\
**Category:** Questions\
**Tags:** earth-science, signal-processing\
**Created:** [February 21, 2019, 10:00pm UTC](https://community.wolfram.com/t/calculate-seismic-to-signal-ratio-and-peak-seismic-to-noise-ratio/13696 "2019-02-21T22:00:13Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![sheunsky](https://avatars.discourse-cdn.com/v4/letter/s/858c86/32.png) [@sheunsky](https://community.wolfram.com/u/sheunsky)\
**Post date:** [February 21, 2019, 10:00pm UTC](https://community.wolfram.com/t/calculate-seismic-to-signal-ratio-and-peak-seismic-to-noise-ratio/13696/1 "2019-02-21T22:00:13Z")

</div>

Dear All,  
I am a beginner in mathematica. Please, I want to write a mathematica code to calculate seismic-to-noise ratio using the equation:  
 ![Capture.JPG](https://global.discourse-cdn.com/wolfram/original/2X/a/a1da8232b25263c4efa6edde4ff1ca6d41d42064.jpeg)

a is the amplitude scaling factor, s is the waveform and n is the noise. I have attempted to write the code as follows:

```
SNR = 10*Log*(Norm[s[[i]]^2, 2]/Norm[n[[i]]^2, 2], {i, nx})

```

I will also like to write a code to calculate peak signal to noise ratio using the equation

![Capture2.JPG](https://global.discourse-cdn.com/wolfram/original/1X/4871955d1e2a2d84014f30bebcb449dec9ed242f.jpeg)

Pi is the peak value of s in the first equation and sigma is the variance.

[SNRi.docx](https://community.wolfram.com/uploads/short-url/11ZPPoiPXdB9xllE2ZvhHia5zVf.docx) (11.4 KB)

---

<div class="post-metadata">

**Author:** ![anon\_91240867](https://avatars.discourse-cdn.com/v4/letter/a/8baadc/32.png) [@anon\_91240867](https://community.wolfram.com/u/anon_91240867)\
**Post date:** [February 22, 2019, 1:32am UTC](https://community.wolfram.com/t/calculate-seismic-to-signal-ratio-and-peak-seismic-to-noise-ratio/13696/2 "2019-02-22T01:32:51Z")

</div>

I’ll try the 2nd eq. only. I assume you want each PSNR[i] calculated and accessible as array.

```
Do[PSNR[i] := 10 Log[(a[[i]]^2 P[[i]]^2/s^2), 10], {i, 100}]

```

Usually we do it like this (a List[]):

```
Table[10 Log[(a[[i]]^2 P[[i]]^2/s^2), 10], {i, 100}]

```

You could Enter as an input:

```
10 Log[(a[[i]]^2 P[[i]]^2/s^2), 10]

```

and Mathematic will have a button appear below it saying “Plot”, if you just want to see the plot

I view .nb but i do not view .docx as i don’t know what might happen if i open them and they are encrypted. Please share .nb

---

<div class="post-metadata">

**Author:** ![sheunsky](https://avatars.discourse-cdn.com/v4/letter/s/858c86/32.png) [@sheunsky](https://community.wolfram.com/u/sheunsky)\
**Post date:** [February 22, 2019, 10:49am UTC](https://community.wolfram.com/t/calculate-seismic-to-signal-ratio-and-peak-seismic-to-noise-ratio/13696/3 "2019-02-22T10:49:49Z")

</div>

Thank you John for your response. I want the P in the second equation to be reading the maximum value of s in the first equation.

---

<div class="post-metadata">

**Author:** ![anon\_91240867](https://avatars.discourse-cdn.com/v4/letter/a/8baadc/32.png) [@anon\_91240867](https://community.wolfram.com/u/anon_91240867)\
**Post date:** [February 22, 2019, 5:07pm UTC](https://community.wolfram.com/t/calculate-seismic-to-signal-ratio-and-peak-seismic-to-noise-ratio/13696/4 "2019-02-22T17:07:26Z")

</div>

It makes no sense to say P[[i]] if P is the max of s. Perhaps you mean Max[s[[i]]].

```
P=Max[Table[s[[i]],{i,100}]]; (*no?*)
SNR:=10 Log[a[[i]]^2 Norm[s[[i]]^2, 2]/Norm[n[[i]]^2, 2],10];
P:=Max[s[[i]]];
PSNR:=10 Log[(a[[i]]^2 P[[i]]^2)/sigma^2, 10];
{SNR[[1]],PSNR[[1]]}

```

---

<div class="post-metadata">

**Author:** ![anon\_91240867](https://avatars.discourse-cdn.com/v4/letter/a/8baadc/32.png) [@anon\_91240867](https://community.wolfram.com/u/anon_91240867)\
**Post date:** [February 22, 2019, 5:10pm UTC](https://community.wolfram.com/t/calculate-seismic-to-signal-ratio-and-peak-seismic-to-noise-ratio/13696/5 "2019-02-22T17:10:43Z")

</div>

i cannot comment on “sigma” seismic-to-noise ratio variance without seeing the material your reading. there would be endless reasonings from which to make such a thing.

---

<div class="post-metadata">

**Author:** ![sheunsky](https://avatars.discourse-cdn.com/v4/letter/s/858c86/32.png) [@sheunsky](https://community.wolfram.com/u/sheunsky)\
**Post date:** [February 22, 2019, 5:35pm UTC](https://community.wolfram.com/t/calculate-seismic-to-signal-ratio-and-peak-seismic-to-noise-ratio/13696/6 "2019-02-22T17:35:18Z")

</div>

Thank you John for your help. Please find attached the page of the material for proper understanding of what I intend to do.

Regards

[material.pdf](https://community.wolfram.com/uploads/short-url/k2fxS561U5BM5QjW7f1UBIqivVH.pdf) (45.1 KB)

---

<div class="post-metadata">

**Author:** ![danl](https://yyz1.discourse-cdn.com/wolfram/user_avatar/community.wolfram.com/danl/32/41267_2.png) [@danl](https://community.wolfram.com/u/danl)\
**Post date:** [February 22, 2019, 10:23pm UTC](https://community.wolfram.com/t/calculate-seismic-to-signal-ratio-and-peak-seismic-to-noise-ratio/13696/7 "2019-02-22T22:23:07Z")

</div>

It is very unclear what you are asking. Please edit to add an explicit example of input and a clear description of desired output.

---

<div class="post-metadata">

**Author:** ![sheunsky](https://avatars.discourse-cdn.com/v4/letter/s/858c86/32.png) [@sheunsky](https://community.wolfram.com/u/sheunsky)\
**Post date:** [February 23, 2019, 5:38pm UTC](https://community.wolfram.com/t/calculate-seismic-to-signal-ratio-and-peak-seismic-to-noise-ratio/13696/8 "2019-02-23T17:38:26Z")

</div>

Thank you Daniel. I wish to calculate SNR for i traces as given by this equation:  
 ![Capture.JPG](https://global.discourse-cdn.com/wolfram/original/2X/a/a1da8232b25263c4efa6edde4ff1ca6d41d42064.jpeg)

where ai is the amplitude scaling factor, si is the signal in the trace and ni is the noise. I expect to see arrays of SNR for i traces.  
I also need a code to calculate PSNR using this equation:  
 ![Capture2.JPG](https://global.discourse-cdn.com/wolfram/original/1X/4871955d1e2a2d84014f30bebcb449dec9ed242f.jpeg)

where Pi is the peak value of si in the first equation and sigmal is the variance of the noise in the first equation.  
I attach the material in pdf that shows what I am trying to do.  
This is what I have so far:

SNR := Table[  
10_Log[a[[i]]^2_Norm[trs[[i]]^2, 2]/Norm[s[[i]]^2, 2], 10], {i,  
Length[trs]}];

P := Max[trs[[i]]];

PSNR := 10\*Log[(a[[i]]^2 P[[i]]^2)/s^2, 10], {i, Length[trs]};  
{SNR[[1](https://community.wolfram.com//c/portal/getImageAttachment?filename=Capture.JPG&userId=1616968)], PSNR[[1](https://community.wolfram.com//c/portal/getImageAttachment?filename=Capture.JPG&userId=1616968)]}

[material.pdf](https://community.wolfram.com/uploads/short-url/k2fxS561U5BM5QjW7f1UBIqivVH.pdf) (45.1 KB)
