File size: 3,230 Bytes
d92700d
c3d54d3
d92700d
7eee483
d92700d
 
 
097d8e4
 
d92700d
097d8e4
 
 
 
 
 
 
 
 
 
 
 
d92700d
097d8e4
 
 
 
 
 
 
 
 
 
7eee483
097d8e4
8dcaad2
097d8e4
 
8dcaad2
097d8e4
 
 
 
8dcaad2
d92700d
097d8e4
 
 
 
 
 
 
 
 
 
 
 
c3d54d3
097d8e4
 
 
 
 
 
 
 
c3d54d3
097d8e4
 
 
 
 
 
 
 
 
 
 
 
 
 
 
d92700d
097d8e4
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
import streamlit as st
from streamlit.components.v1 import html
import numpy as np
import pandas as pd
import plotly.graph_objects as go
from scipy.signal import square, sawtooth

# Title of the app
st.title("Circuit Simulator with Waveform Analysis")

# Embed CircuitJS1
st.header("Build Your Circuit")
circuitjs_html = """
<div>
    <iframe src="https://www.falstad.com/circuit/circuitjs.html" 
            width="100%" 
            height="600px" 
            style="border:none;">
    </iframe>
</div>
"""
html(circuitjs_html, height=600)

# Add a description or instructions
st.markdown("""
### Instructions:
1. Use the CircuitJS1 simulator above to design and simulate electrical circuits.
2. You can add components, connect them, and simulate the circuit in real-time.
3. Explore the menu options in CircuitJS1 for advanced features.
""")

# Analysis and Waveform Section
st.header("Circuit Analysis and Waveform Visualization")

# Dummy analysis function (replace with actual analysis logic)
def analyze_circuit():
    # Placeholder for analysis logic
    # For now, we'll return dummy data
    return pd.DataFrame({
        "Total Voltage (V)": [5.0],
        "Current (A)": [0.01],
        "Resistance (Ω)": [500],
        "Diode Drop (V)": [0.7]
    })

# Waveform generation function
def generate_waveform(waveform_type):
    t = np.linspace(0, 0.05, 1000)  # Time vector
    if waveform_type == "Sine":
        wave = np.sin(2 * np.pi * 50 * t)  # 50 Hz sine wave
    elif waveform_type == "Square":
        wave = square(2 * np.pi * 50 * t)  # 50 Hz square wave
    elif waveform_type == "Triangular":
        wave = sawtooth(2 * np.pi * 50 * t)  # 50 Hz triangular wave
    else:
        wave = np.zeros_like(t)  # Default to zero
    return t, wave

# Run Analysis Button
if st.button("▶️ Run Analysis"):
    # Perform circuit analysis
    results = analyze_circuit()
    
    # Display analysis results
    st.subheader("🔍 Analysis Results")
    st.dataframe(results)

    # Waveform visualization
    st.subheader("📈 Waveform Visualization")
    waveform_type = st.selectbox("Select Waveform Type", ["Sine", "Square", "Triangular"])
    t, wave = generate_waveform(waveform_type)
    
    # Plot waveform
    fig = go.Figure()
    fig.add_trace(go.Scatter(x=t, y=wave, mode="lines", name=waveform_type))
    fig.update_layout(
        title=f"{waveform_type} Waveform",
        xaxis_title="Time (s)",
        yaxis_title="Amplitude",
        template="plotly_white"
    )
    st.plotly_chart(fig)

# Instructions for Analysis
with st.expander("❓ How to use"):
    st.markdown("""
    1. **Build Your Circuit**:
       - Use the CircuitJS1 simulator above to design your circuit.
       - Add components like resistors, capacitors, diodes, etc.
       - Simulate the circuit to ensure it works as expected.
       
    2. **Run Analysis**:
       - Click the "Run Analysis" button to get the circuit's electrical properties.
       - View the observation table for voltage, current, and resistance.
       
    3. **Waveform Visualization**:
       - Select a waveform type (Sine, Square, Triangular) to visualize.
       - The waveform will be displayed based on the circuit's AC behavior.
    """)