<jupyter_start><jupyter_text>IMPORTING PACKAGES<jupyter_code>import pandas as pd
import matplotlib.pyplot as plt
import numpy as np 
from sklearn.preprocessing import RobustScaler<jupyter_output><empty_output><jupyter_text>Reading DataUpload the csv file with only ' Breath Data Column '<jupyter_code>df = pd.read_csv('FILE_NAME.csv') # For CSV

# pd.read_excel('deep6.xlsx') # For excel data
df
df.columns = ['Breath data'] # giving column name, no. of column names should be equal to columns

# df = df.drop(['Index'],axis = 1) # to remove column just write their names seperated in commas<jupyter_output><empty_output><jupyter_text>**Scaling the data**important for getting peaks.<jupyter_code>sc = df['Breath data'].values.reshape(-1,1) # reshape 1d values from:-  [1.33] to [[1.33],]

scaler = RobustScaler() # calling the scaler
k = scaler.fit(sc) # do all the calculation required to do scaling on data
l = scaler.transform(sc) # no return the values through the calculation.
sc = l

df1 = sc<jupyter_output><empty_output><jupyter_text>GETTING THE PEAK VALUES<jupyter_code>import plotly.graph_objects as go
import pandas as pd
from scipy.signal import find_peaks

k = df1.ravel() # Data to Converting to 1D array before using
peaks, _ = find_peaks(k, prominence=0.1) # Get all the peak values and store in 'peaks' variable<jupyter_output><empty_output><jupyter_text>Plotting 'Peak' Values to check<jupyter_code>plt.subplot()
plt.plot(peaks, k[peaks], "ob"); plt.plot(k); plt.legend(['prominence'])<jupyter_output><empty_output><jupyter_text>These are the index of Peaks ( Considered as time as it's 1 second )if it's in milliseconds, then the difference would still be the same but counted in Milliseconds. If it's in seconds or hours doesn't matter as difference will come out same.<jupyter_code>peaks<jupyter_output><empty_output><jupyter_text>FINDING PEAK WIDTH Finding difference in corresponding x-axis of peaks. ( difference of time of crests )<jupyter_code>difference = [] # creating a label
for i in range(0, len(peaks), 2):
  diff = peaks[i+1] - peaks[i]
  difference.append(diff)

difference = pd.DataFrame(difference)
difference.columns = ['width']
len(peaks)
len(difference)
difference[:10] # oradeeo breath was milliseconds so this is in millisecinds
#x = df.to_numpy()
#y = x.ravel() # to 1D<jupyter_output><empty_output><jupyter_text>Download this dataframe, will show on the left bar after download<jupyter_code>difference.to_csv('FILE_NAME.csv') # Edit file name<jupyter_output><empty_output><jupyter_text>For Plotting PurposeTo check values and see the plot of data<jupyter_code>import plotly.graph_objects as go
import numpy as np
import pandas as pd
from scipy.signal import find_peaks, peak_widths

breath_series = k

indices = find_peaks(breath_series, prominence=0.1)[0] # use threshold=10 or prominence=0.1

fig = go.Figure()

fig.add_trace(go.Scatter(
    y=breath_series,
    mode='lines+markers',
    name='Original Plot'
))

fig.add_trace(go.Scatter(
        x=indices,
        y=[breath_series[j] for j in indices],
        mode='markers',
        marker=dict(
             size=8,
             color='red',
             symbol='cross'
            ),
        name='Detected Peaks'
            ))
fig.show()
import pandas as pd
import matplotlib.pyplot as plt
from scipy.signal import find_peaks, peak_widths


df = pd.read_csv('data_Pradeep.csv')

x = df.iloc[1:,:1]
y = df.iloc[1:,1]
n_y = (y-y.min())/(y.max()-y.min())#Do this for normalizing the data.

#peak = find_peaks(y, height = )
#d = scaler.fit_transform(y)
peaks, _ = find_peaks(n_y)
results = peak_widths(n_y, peaks, rel_height=0.85)
plt.plot(n_y)
plt.plot(peaks,n_y[peaks],"x")
plt.hlines(*results[1:], color='C2')
plt.xlabel('Time (s) * 0.1', size = 16)
plt.ylabel('Voltage (V)', size = 16)
plt.xlim(0,5466)
plt.show()
plt.tight_layout()
peaks<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.11980376968758069, 'fraction_numerical': 0.013168086754453912, 'mean_word_length': 5.062597809076682, 'pattern_counts': {'":': 0, '<': 37, '<?xml version=': 0, '>': 37, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '9', 'dir': 'jupyter-structured-clean-dedup', 'id': '158169', 'license': 'MIT', 'n_tokens_mistral': 1443, 'n_tokens_neox': 1373, 'n_words': 369, 'path': 'PEAK_FINDING.ipynb', 'repo_name': 'PlugRS/IIT_1DCNN', 'size': '3873'}