Scipy finding average peak to peak voltage of a signal

I have a noisy sinewave in varying frequencies. I save all the samples (in mV) of this sinewave in variable data_mV

I can find the peaks of my sinewave with the following function using find_peaks from the scipy python library

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code>def find_peaks_in_signal(data_mV,sampling_rate,signal_frequency,plot):
if(debug_prints):
print("Sampling rate = ",sampling_rate)
print("Expected signal frequency = ",signal_frequency)
distance = (sampling_rate / signal_frequency) - 100
print("Distance = ",distance)
peaks, _ = find_peaks(data_mV, distance=distance)
if plot:
plt.plot(data_mV)
plt.plot(peaks, data_mV[peaks], "x")
plt.plot(np.zeros_like(data_mV), "--", color="gray")
plt.show()
return peaks
</code>
<code>def find_peaks_in_signal(data_mV,sampling_rate,signal_frequency,plot): if(debug_prints): print("Sampling rate = ",sampling_rate) print("Expected signal frequency = ",signal_frequency) distance = (sampling_rate / signal_frequency) - 100 print("Distance = ",distance) peaks, _ = find_peaks(data_mV, distance=distance) if plot: plt.plot(data_mV) plt.plot(peaks, data_mV[peaks], "x") plt.plot(np.zeros_like(data_mV), "--", color="gray") plt.show() return peaks </code>
def find_peaks_in_signal(data_mV,sampling_rate,signal_frequency,plot):
    if(debug_prints):
        print("Sampling rate = ",sampling_rate)
        print("Expected signal frequency = ",signal_frequency)
    distance = (sampling_rate / signal_frequency) - 100
    print("Distance = ",distance)
    peaks, _ = find_peaks(data_mV, distance=distance)
    if plot:
        plt.plot(data_mV)
        plt.plot(peaks, data_mV[peaks], "x")
        plt.plot(np.zeros_like(data_mV), "--", color="gray")
        plt.show()
    return peaks

The result is:

As you can see I am able to detect the peaks quite nicely. My absolute goal is to be able to calculate Average Peak to Peak voltage of the sinewave. Perhaps someone could point me in the right direction on what is the most reliable way to do that?

Can this be done using scipy functions or scipy does not have this kind of thing implemented?

I too am trying to do this, and the best solution I have come up with is to take all the peaks, then invert the signal, and find the troughs. Then you can take the average of all the trough values and peaks and get your average pk-pk.

e.g.

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code>import numpy as np
peaks, _ = find_peaks(data_mV, distance=distance)
troughs, _ = find_peaks([x*-1 for x in data_mV], distance=distance)
pk_list = []
tr_list = []
for peak in peaks:
pk_list.append(peaks[peak])
for trough in troughs:
tr_list.append(troughs[trough])
pkpk = np.average(pk_list)-np.average(tr_list)
</code>
<code>import numpy as np peaks, _ = find_peaks(data_mV, distance=distance) troughs, _ = find_peaks([x*-1 for x in data_mV], distance=distance) pk_list = [] tr_list = [] for peak in peaks: pk_list.append(peaks[peak]) for trough in troughs: tr_list.append(troughs[trough]) pkpk = np.average(pk_list)-np.average(tr_list) </code>
import numpy as np
peaks, _ = find_peaks(data_mV, distance=distance)
troughs, _ = find_peaks([x*-1 for x in data_mV], distance=distance)
pk_list = []
tr_list = []

for peak in peaks:
    pk_list.append(peaks[peak])

for trough in troughs:
    tr_list.append(troughs[trough])

pkpk = np.average(pk_list)-np.average(tr_list)

however, it looks like numpy also has a pk-pk function, but it only provides the value of the maximum-min for the list, not the average peak-peak value, so its not quite as useful as the above.

New contributor

Avery Louie is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa

Scipy finding average peak to peak voltage of a signal

I have a noisy sinewave in varying frequencies. I save all the samples (in mV) of this sinewave in variable data_mV

I can find the peaks of my sinewave with the following function using find_peaks from the scipy python library

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code>def find_peaks_in_signal(data_mV,sampling_rate,signal_frequency,plot):
if(debug_prints):
print("Sampling rate = ",sampling_rate)
print("Expected signal frequency = ",signal_frequency)
distance = (sampling_rate / signal_frequency) - 100
print("Distance = ",distance)
peaks, _ = find_peaks(data_mV, distance=distance)
if plot:
plt.plot(data_mV)
plt.plot(peaks, data_mV[peaks], "x")
plt.plot(np.zeros_like(data_mV), "--", color="gray")
plt.show()
return peaks
</code>
<code>def find_peaks_in_signal(data_mV,sampling_rate,signal_frequency,plot): if(debug_prints): print("Sampling rate = ",sampling_rate) print("Expected signal frequency = ",signal_frequency) distance = (sampling_rate / signal_frequency) - 100 print("Distance = ",distance) peaks, _ = find_peaks(data_mV, distance=distance) if plot: plt.plot(data_mV) plt.plot(peaks, data_mV[peaks], "x") plt.plot(np.zeros_like(data_mV), "--", color="gray") plt.show() return peaks </code>
def find_peaks_in_signal(data_mV,sampling_rate,signal_frequency,plot):
    if(debug_prints):
        print("Sampling rate = ",sampling_rate)
        print("Expected signal frequency = ",signal_frequency)
    distance = (sampling_rate / signal_frequency) - 100
    print("Distance = ",distance)
    peaks, _ = find_peaks(data_mV, distance=distance)
    if plot:
        plt.plot(data_mV)
        plt.plot(peaks, data_mV[peaks], "x")
        plt.plot(np.zeros_like(data_mV), "--", color="gray")
        plt.show()
    return peaks

The result is:

As you can see I am able to detect the peaks quite nicely. My absolute goal is to be able to calculate Average Peak to Peak voltage of the sinewave. Perhaps someone could point me in the right direction on what is the most reliable way to do that?

Can this be done using scipy functions or scipy does not have this kind of thing implemented?

I too am trying to do this, and the best solution I have come up with is to take all the peaks, then invert the signal, and find the troughs. Then you can take the average of all the trough values and peaks and get your average pk-pk.

e.g.

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code>import numpy as np
peaks, _ = find_peaks(data_mV, distance=distance)
troughs, _ = find_peaks([x*-1 for x in data_mV], distance=distance)
pk_list = []
tr_list = []
for peak in peaks:
pk_list.append(peaks[peak])
for trough in troughs:
tr_list.append(troughs[trough])
pkpk = np.average(pk_list)-np.average(tr_list)
</code>
<code>import numpy as np peaks, _ = find_peaks(data_mV, distance=distance) troughs, _ = find_peaks([x*-1 for x in data_mV], distance=distance) pk_list = [] tr_list = [] for peak in peaks: pk_list.append(peaks[peak]) for trough in troughs: tr_list.append(troughs[trough]) pkpk = np.average(pk_list)-np.average(tr_list) </code>
import numpy as np
peaks, _ = find_peaks(data_mV, distance=distance)
troughs, _ = find_peaks([x*-1 for x in data_mV], distance=distance)
pk_list = []
tr_list = []

for peak in peaks:
    pk_list.append(peaks[peak])

for trough in troughs:
    tr_list.append(troughs[trough])

pkpk = np.average(pk_list)-np.average(tr_list)

however, it looks like numpy also has a pk-pk function, but it only provides the value of the maximum-min for the list, not the average peak-peak value, so its not quite as useful as the above.

New contributor

Avery Louie is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật