Spaces:
Sleeping
Sleeping
import streamlit as st | |
import matplotlib.pyplot as plt | |
import pandas as pd | |
import numpy as np | |
# Set streamlit configuration with wide mode | |
st.set_page_config(layout="wide") | |
st.config.set_option("server.enableXsrfProtection", False) | |
def plot_signal(signal, index): | |
# Assuming df is your DataFrame and 'Signal1', 'Signal2', 'Signal3' are your columns | |
ch1 = pd.to_numeric(signal[index], errors='coerce') | |
# Define the moving average window size | |
N = 25 | |
# Function to calculate moving RMS | |
def moving_rms(signal, window_size): | |
return np.sqrt(pd.Series(signal).rolling(window=window_size).mean()**2) | |
# Calculate moving RMS for each channel | |
ch1_rms = moving_rms(ch1, N) | |
# Calculate mean and standard deviation of the RMS signals | |
mean_ch1_rms = np.mean(ch1_rms) | |
std_ch1_rms = np.std(ch1_rms) | |
# Print mean and standard deviation values | |
st.write(f'Mean of RMS Signal {int(index)}: {mean_ch1_rms:.3f}, Std Dev of RMS Signal 1: {std_ch1_rms:.3f}') | |
# Plot the RMS signals | |
plt.figure(figsize=(15,6)) | |
plt.plot(ch1_rms, label='Signal 1 RMS') | |
plt.title('RMS Signal Values, Moving Average Window Size N=25') | |
plt.xlabel('Index') | |
plt.ylabel('RMS Value') | |
plt.legend() | |
st.pyplot(plt.gcf()) | |
# plt.show() | |
def main(): | |
st.title('👅Dysphagia Analysis - by ITRI BDL') | |
uploaded_file1 = st.file_uploader("Choose the EMG_data CSV file", type="csv") | |
uploaded_file2 = st.file_uploader("Choose the time_marker CSV file", type="csv") | |
if uploaded_file1 is not None: | |
try: | |
data1 = pd.read_csv(uploaded_file1, skiprows=[0,1,3,4]) | |
# st.dataframe(data1) | |
except Exception as e: | |
st.error(f"Error: {e}") | |
if uploaded_file2 is not None: | |
try: | |
data2 = pd.read_csv(uploaded_file2, skiprows=[0,1]) | |
# st.dataframe(data2) | |
except Exception as e: | |
st.error(f"Error: {e}") | |
# Detect Upload File and choose signal with sidebar menu | |
if uploaded_file1 is not None and uploaded_file2 is not None: | |
signal = st.sidebar.selectbox('Select EMG Signal', data1.columns) | |
st.write(f'You selected: channel {signal}') | |
# Plot the selected signal | |
st.line_chart(data1[signal]) | |
# Analysis button | |
if st.button('Start Analysis'): | |
st.write('Analysis started...') | |
# Add analysis code here | |
plot_signal(data1, signal) | |
st.write('Analysis completed...') | |
if __name__ == '__main__': | |
main() |