6) Noisy peak finding. Finding peak in a noisy data is a very common task in analyzing physical from sensors. Consider the following data shown below. Your task for this problem is to find the peak position and peak height from noisy data. There are 10 dataset make sure you succeed in finding **all** the peak in at least 9. ```python def find_peaks(xs, ys): return [(xpeak, ypeak), (xpeak, ypeak), ...] ``` Here are some hints: - You should first find candidates for peak in noisy data. - Fit the peak(and neighbor) with parabola - Make sure the parameter from the fitted parabola actually indicate that it is a peak. - Then use the parameter from the fitted parabola to find the peak location and height. (Recall High School Math)given import numpy as np %matplotlib inline from matplotlib import pyplot as plt import math from math import exp np.random.seed(9999) def is_good_peak(mu, min_dist=0.8): if mu is None: return False smu = np.sort(mu) if smu[0] < 0.5: return False if smu[-1] > 2.5: return False for p, n in zip(smu, smu[1:]): #print(abs(p-n)) if abs(p-n) < min_dist: return False return True maxx = 3 ndata = 500 nset = 10 l = [] answers = [] for iset in range(1, nset): npeak = np.random.randint(2,4) xs = np.linspace(0,maxx,ndata) ys = np.zeros(ndata) mu = None while not is_good_peak(mu): mu = np.random.random(npeak)*maxx for ipeak in range(npeak): m = mu[ipeak] sigma = np.random.random()*0.3 + 0.2 height = np.random.random()*0.5 + 1 ys += height*np.exp(-(xs-m)**2/sigma**2) ys += np.random.randn(ndata)*0.07 l.append(ys) answers.append(mu) p6_ys = l p6_xs = np.linspace(0,maxx,ndata) p6_answers = answers for ys, ans in zip(p6_ys, p6_answers): plt.figure() plt.plot(xs, ys, '.') for a in ans: plt.axvline(a,color='red')
6) Noisy peak finding. Finding peak in a noisy data is a very common task in analyzing physical from sensors. Consider the following data shown below. Your task for this problem is to find the peak position and peak height from noisy data. There are 10 dataset make sure you succeed in finding **all** the peak in at least 9. ```python def find_peaks(xs, ys): return [(xpeak, ypeak), (xpeak, ypeak), ...] ``` Here are some hints: - You should first find candidates for peak in noisy data. - Fit the peak(and neighbor) with parabola - Make sure the parameter from the fitted parabola actually indicate that it is a peak. - Then use the parameter from the fitted parabola to find the peak location and height. (Recall High School Math)given import numpy as np %matplotlib inline from matplotlib import pyplot as plt import math from math import exp np.random.seed(9999) def is_good_peak(mu, min_dist=0.8): if mu is None: return False smu = np.sort(mu) if smu[0] < 0.5: return False if smu[-1] > 2.5: return False for p, n in zip(smu, smu[1:]): #print(abs(p-n)) if abs(p-n) < min_dist: return False return True maxx = 3 ndata = 500 nset = 10 l = [] answers = [] for iset in range(1, nset): npeak = np.random.randint(2,4) xs = np.linspace(0,maxx,ndata) ys = np.zeros(ndata) mu = None while not is_good_peak(mu): mu = np.random.random(npeak)*maxx for ipeak in range(npeak): m = mu[ipeak] sigma = np.random.random()*0.3 + 0.2 height = np.random.random()*0.5 + 1 ys += height*np.exp(-(xs-m)**2/sigma**2) ys += np.random.randn(ndata)*0.07 l.append(ys) answers.append(mu) p6_ys = l p6_xs = np.linspace(0,maxx,ndata) p6_answers = answers for ys, ans in zip(p6_ys, p6_answers): plt.figure() plt.plot(xs, ys, '.') for a in ans: plt.axvline(a,color='red')
Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
Related questions
Question
6) Noisy peak finding.
Finding peak in a noisy data is a very common task in analyzing physical from sensors. Consider the following data shown below.
Your task for this problem is to find the peak position and peak height from noisy data. There are 10 dataset make sure you succeed in finding **all** the peak in at least 9.
```python
def find_peaks(xs, ys):
return [(xpeak, ypeak), (xpeak, ypeak), ...]
```
Here are some hints:
- You should first find candidates for peak in noisy data.
- Fit the peak(and neighbor) with parabola
- Make sure the parameter from the fitted parabola actually indicate that it is a peak.
- Then use the parameter from the fitted parabola to find the peak location and height. (Recall High School Math)
given
given
import numpy as np
%matplotlib inline
from matplotlib import pyplot as plt
import math
from math import exp
np.random.seed(9999)
def is_good_peak(mu, min_dist=0.8):
if mu is None:
return False
smu = np.sort(mu)
if smu[0] < 0.5:
return False
if smu[-1] > 2.5:
return False
for p, n in zip(smu, smu[1:]):
#print(abs(p-n))
if abs(p-n) < min_dist:
return False
return True
maxx = 3
ndata = 500
nset = 10
l = []
answers = []
for iset in range(1, nset):
npeak = np.random.randint(2,4)
xs = np.linspace(0,maxx,ndata)
ys = np.zeros(ndata)
mu = None
while not is_good_peak(mu):
mu = np.random.random(npeak)*maxx
for ipeak in range(npeak):
m = mu[ipeak]
sigma = np.random.random()*0.3 + 0.2
height = np.random.random()*0.5 + 1
ys += height*np.exp(-(xs-m)**2/sigma**2)
ys += np.random.randn(ndata)*0.07
l.append(ys)
answers.append(mu)
p6_ys = l
p6_xs = np.linspace(0,maxx,ndata)
p6_answers = answers
for ys, ans in zip(p6_ys, p6_answers):
plt.figure()
plt.plot(xs, ys, '.')
for a in ans:
plt.axvline(a,color='red')
Expert Solution
This question has been solved!
Explore an expertly crafted, step-by-step solution for a thorough understanding of key concepts.
Step by step
Solved in 2 steps
Knowledge Booster
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.Recommended textbooks for you
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education