Spaces:
Sleeping
Sleeping
| import streamlit as st | |
| import numpy as np | |
| import matplotlib.pyplot as plt | |
| import pandas as pd | |
| def calculate_output(vin): | |
| v_ge = np.where(vin >= 0.3, 0.3, np.where(vin < 0, vin, 0)) | |
| v_o = np.where((vin >= 0.3) | (vin < 0), 0, 6) | |
| return v_ge, v_o | |
| def main(): | |
| st.title("π©πͺ Germanium Transistor Waveform Simulator") | |
| st.caption("Analyze clipping behavior of Ge transistor (V_Ge = 0.3V) with 6V DC supply") | |
| # User inputs | |
| amplitude = st.slider("Input Amplitude (V)", 0, 15, 10) | |
| time = np.linspace(0, 2*np.pi, 1000) | |
| # Generate input waveform | |
| vin = amplitude * np.sin(time) | |
| # Calculate outputs | |
| v_ge, v_o = calculate_output(vin) | |
| # Create table data | |
| sample_points = [10,8,6,5,4,3,2,1,0.7,0.3,0,-0.3,-0.7,-1,-2,-3,-4,-5,-6,-8,-10] | |
| table_data = [] | |
| for point in sample_points: | |
| v_ge_val = 0.3 if point >= 0.3 else (point if point < 0 else 0) | |
| v_o_val = 0 if (point >= 0.3 or point < 0) else 6 | |
| table_data.append([point, round(v_ge_val, 2), v_o_val]) | |
| # Display results | |
| col1, col2 = st.columns(2) | |
| with col1: | |
| st.subheader("Waveforms") | |
| fig, ax = plt.subplots(figsize=(8, 4)) | |
| ax.plot(time, vin, label='Input (V_in)') | |
| ax.plot(time, v_o, label='Output (V_o)', color='red') | |
| ax.set_xlabel('Time') | |
| ax.set_ylabel('Voltage (V)') | |
| ax.legend() | |
| ax.grid(True) | |
| st.pyplot(fig) | |
| with col2: | |
| st.subheader("Data Table") | |
| df = pd.DataFrame(table_data, columns=["V_in (V)", "V_Ge (V)", "V_o (V)"]) | |
| st.dataframe(df.style.format({"V_Ge": "{:.2f}", "V_o": "{:.0f}"}), height=600) | |
| st.markdown("### Circuit Behavior Summary") | |
| st.write(""" | |
| - **Positive Half Cycle (V_in β₯ 0):** | |
| - Clipped to 0V when input β₯ 0.3V | |
| - Output stays at 6V when input < 0.3V | |
| - **Negative Half Cycle (V_in < 0):** | |
| - Output always remains at 6V | |
| - Germanium forward voltage (V_Ge) = 0.3V | |
| """) | |
| if __name__ == "__main__": | |
| main() |