Spaces:
Sleeping
Sleeping
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,63 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import streamlit as st
|
2 |
+
import numpy as np
|
3 |
+
import matplotlib.pyplot as plt
|
4 |
+
import pandas as pd
|
5 |
+
|
6 |
+
def calculate_output(vin):
|
7 |
+
v_ge = np.where(vin >= 0.3, 0.3, np.where(vin < 0, vin, 0))
|
8 |
+
v_o = np.where((vin >= 0.3) | (vin < 0), 0, 6)
|
9 |
+
return v_ge, v_o
|
10 |
+
|
11 |
+
def main():
|
12 |
+
st.title("🇩🇪 Germanium Transistor Waveform Simulator")
|
13 |
+
st.caption("Analyze clipping behavior of Ge transistor (V_Ge = 0.3V) with 6V DC supply")
|
14 |
+
|
15 |
+
# User inputs
|
16 |
+
amplitude = st.slider("Input Amplitude (V)", 0, 15, 10)
|
17 |
+
time = np.linspace(0, 2*np.pi, 1000)
|
18 |
+
|
19 |
+
# Generate input waveform
|
20 |
+
vin = amplitude * np.sin(time)
|
21 |
+
|
22 |
+
# Calculate outputs
|
23 |
+
v_ge, v_o = calculate_output(vin)
|
24 |
+
|
25 |
+
# Create table data
|
26 |
+
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]
|
27 |
+
table_data = []
|
28 |
+
for point in sample_points:
|
29 |
+
v_ge_val = 0.3 if point >= 0.3 else (point if point < 0 else 0)
|
30 |
+
v_o_val = 0 if (point >= 0.3 or point < 0) else 6
|
31 |
+
table_data.append([point, round(v_ge_val, 2), v_o_val])
|
32 |
+
|
33 |
+
# Display results
|
34 |
+
col1, col2 = st.columns(2)
|
35 |
+
|
36 |
+
with col1:
|
37 |
+
st.subheader("Waveforms")
|
38 |
+
fig, ax = plt.subplots(figsize=(8, 4))
|
39 |
+
ax.plot(time, vin, label='Input (V_in)')
|
40 |
+
ax.plot(time, v_o, label='Output (V_o)', color='red')
|
41 |
+
ax.set_xlabel('Time')
|
42 |
+
ax.set_ylabel('Voltage (V)')
|
43 |
+
ax.legend()
|
44 |
+
ax.grid(True)
|
45 |
+
st.pyplot(fig)
|
46 |
+
|
47 |
+
with col2:
|
48 |
+
st.subheader("Data Table")
|
49 |
+
df = pd.DataFrame(table_data, columns=["V_in (V)", "V_Ge (V)", "V_o (V)"])
|
50 |
+
st.dataframe(df.style.format({"V_Ge": "{:.2f}", "V_o": "{:.0f}"}), height=600)
|
51 |
+
|
52 |
+
st.markdown("### Circuit Behavior Summary")
|
53 |
+
st.write("""
|
54 |
+
- **Positive Half Cycle (V_in ≥ 0):**
|
55 |
+
- Clipped to 0V when input ≥ 0.3V
|
56 |
+
- Output stays at 6V when input < 0.3V
|
57 |
+
- **Negative Half Cycle (V_in < 0):**
|
58 |
+
- Output always remains at 6V
|
59 |
+
- Germanium forward voltage (V_Ge) = 0.3V
|
60 |
+
""")
|
61 |
+
|
62 |
+
if __name__ == "__main__":
|
63 |
+
main()
|