Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Learn Introduction to Signals and Waveforms | Signal Processing for Electrical Engineers
Practice
Projects
Quizzes & Challenges
Quizzes
Challenges
/
Python for Electrical Engineers

bookIntroduction to Signals and Waveforms

Understanding common electrical signals is fundamental in electrical engineering, as these signals form the basis for analyzing and designing circuits, communication systems, and control systems. Among the most frequently encountered signals are the sine wave, square wave, and triangle wave. Each of these waveforms has unique characteristics and applications: sine waves represent pure frequencies and are used in AC power and communications; square waves are critical for digital systems and switching circuits; triangle waves often appear in signal generators and modulation schemes. Being able to represent and manipulate these signals in Python allows you to simulate and analyze real-world engineering problems efficiently.

123456789101112131415161718192021222324
import numpy as np import matplotlib.pyplot as plt # Signal parameters amplitude = 1.0 # Peak value frequency = 5.0 # Hertz phase = 0.0 # Radians sampling_rate = 1000 # Samples per second duration = 1.0 # Seconds # Time array t = np.linspace(0, duration, int(sampling_rate * duration), endpoint=False) # Sine wave calculation sine_wave = amplitude * np.sin(2 * np.pi * frequency * t + phase) # Plotting plt.figure(figsize=(8, 4)) plt.plot(t, sine_wave) plt.title("Sine Wave: 5 Hz") plt.xlabel("Time (s)") plt.ylabel("Amplitude") plt.grid(True) plt.show()
copy

In the code above, you generate a sine wave by defining its amplitude (the peak value of the wave), frequency (how many cycles occur per second), and phase (the horizontal shift of the wave). The sampling_rate determines how many points per second are used to represent the signal, which affects the smoothness of the plotted curve. The duration sets the length of time over which the signal is generated. By adjusting these parameters, you can observe how each one affects the shape and characteristics of the waveform. For instance, increasing the frequency results in more cycles within the same time period, while changing the amplitude scales the height of the wave.

123456789101112131415161718192021
import numpy as np import matplotlib.pyplot as plt # Signal parameters amplitude = 1.0 frequency = 5.0 sampling_rate = 1000 duration = 1.0 t = np.linspace(0, duration, int(sampling_rate * duration), endpoint=False) # Square wave using numpy's sign function square_wave = amplitude * np.sign(np.sin(2 * np.pi * frequency * t)) plt.figure(figsize=(8, 4)) plt.plot(t, square_wave) plt.title("Square Wave: 5 Hz") plt.xlabel("Time (s)") plt.ylabel("Amplitude") plt.grid(True) plt.show()
copy

1. What are the key parameters that define a sine wave?

2. Why is visualization of signals important in engineering?

3. Which Python library is commonly used for plotting signals?

question mark

What are the key parameters that define a sine wave?

Select the correct answer

question mark

Why is visualization of signals important in engineering?

Select the correct answer

question mark

Which Python library is commonly used for plotting signals?

Select the correct answer

Everything was clear?

How can we improve it?

Thanks for your feedback!

Section 2. Chapter 1

Ask AI

expand

Ask AI

ChatGPT

Ask anything or try one of the suggested questions to begin our chat

bookIntroduction to Signals and Waveforms

Swipe to show menu

Understanding common electrical signals is fundamental in electrical engineering, as these signals form the basis for analyzing and designing circuits, communication systems, and control systems. Among the most frequently encountered signals are the sine wave, square wave, and triangle wave. Each of these waveforms has unique characteristics and applications: sine waves represent pure frequencies and are used in AC power and communications; square waves are critical for digital systems and switching circuits; triangle waves often appear in signal generators and modulation schemes. Being able to represent and manipulate these signals in Python allows you to simulate and analyze real-world engineering problems efficiently.

123456789101112131415161718192021222324
import numpy as np import matplotlib.pyplot as plt # Signal parameters amplitude = 1.0 # Peak value frequency = 5.0 # Hertz phase = 0.0 # Radians sampling_rate = 1000 # Samples per second duration = 1.0 # Seconds # Time array t = np.linspace(0, duration, int(sampling_rate * duration), endpoint=False) # Sine wave calculation sine_wave = amplitude * np.sin(2 * np.pi * frequency * t + phase) # Plotting plt.figure(figsize=(8, 4)) plt.plot(t, sine_wave) plt.title("Sine Wave: 5 Hz") plt.xlabel("Time (s)") plt.ylabel("Amplitude") plt.grid(True) plt.show()
copy

In the code above, you generate a sine wave by defining its amplitude (the peak value of the wave), frequency (how many cycles occur per second), and phase (the horizontal shift of the wave). The sampling_rate determines how many points per second are used to represent the signal, which affects the smoothness of the plotted curve. The duration sets the length of time over which the signal is generated. By adjusting these parameters, you can observe how each one affects the shape and characteristics of the waveform. For instance, increasing the frequency results in more cycles within the same time period, while changing the amplitude scales the height of the wave.

123456789101112131415161718192021
import numpy as np import matplotlib.pyplot as plt # Signal parameters amplitude = 1.0 frequency = 5.0 sampling_rate = 1000 duration = 1.0 t = np.linspace(0, duration, int(sampling_rate * duration), endpoint=False) # Square wave using numpy's sign function square_wave = amplitude * np.sign(np.sin(2 * np.pi * frequency * t)) plt.figure(figsize=(8, 4)) plt.plot(t, square_wave) plt.title("Square Wave: 5 Hz") plt.xlabel("Time (s)") plt.ylabel("Amplitude") plt.grid(True) plt.show()
copy

1. What are the key parameters that define a sine wave?

2. Why is visualization of signals important in engineering?

3. Which Python library is commonly used for plotting signals?

question mark

What are the key parameters that define a sine wave?

Select the correct answer

question mark

Why is visualization of signals important in engineering?

Select the correct answer

question mark

Which Python library is commonly used for plotting signals?

Select the correct answer

Everything was clear?

How can we improve it?

Thanks for your feedback!

Section 2. Chapter 1
some-alt