0% found this document useful (0 votes)
4 views26 pages

Python Programming Lab Manual

The document outlines a series of laboratory experiments conducted by a student named Guggilapu Jnanesh at Gayatri Vidya Parishad College, focusing on signal processing using Python. It includes experiments on generating basic signals, calculating energy and power of signals, sampling signals, and performing operations on signals, with detailed procedures, code examples, and theoretical explanations. Each experiment is assessed with a lab assessment sheet detailing activities and marks.

Uploaded by

prudhvi.raj9743
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views26 pages

Python Programming Lab Manual

The document outlines a series of laboratory experiments conducted by a student named Guggilapu Jnanesh at Gayatri Vidya Parishad College, focusing on signal processing using Python. It includes experiments on generating basic signals, calculating energy and power of signals, sampling signals, and performing operations on signals, with detailed procedures, code examples, and theoretical explanations. Each experiment is assessed with a lab assessment sheet detailing activities and marks.

Uploaded by

prudhvi.raj9743
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

GVPECE

GAYATRI VIDYA PARISHAD COLLEGE FOR DEGREE AND PG COURSES (A)


RUSHIKONDA, VISAKHAPATNAM 530045|website:[Link]
(Approved by AICTE| Permanently Affiliated to Andhra University |Reaccredited by NAAC| ISO 9001:2015)
ENGINEERING AND TECHNOLOGY PROGRAM
DEPARTMENT OF ELECTRONICS & COMMUNICATION ENGINEERING
(PROGRAM ACCREDITED BY NBA)

LAB ASSESSEMENT SHEET

1. NAME OF THE LABORATORY : PROBLEM SOLVING USING PYTHON LAB

2. NAME OF THE STUDENT : GUGGILAPU JNANESH

3. YEAR & SEMESTER : II/IV [Link]

4. ROLL NUMBER : 5231421031

5. NAME OF THE EXPERIMENT : Generation of Basic SIGNALS

6. DATE OF EXECUTION : 08/11/2024

7. DATE OF SUBMISSION :

S. No ACTIVITY
MARKS(OUT OF 10)
1. INITIAL PREPARATION

2. DRESS CODE & ID CARD

3. OBSERVATIONS

4. VIVA VOCE

5. PRESENTATION OF THE
LABORATORY REPORT

TOTAL MARKS (OUT OF 50)

Date: SIGNATURE OF THE


FACULTY
GVPECE

EXPERIMENT NO 21

TITLE: Generation of Basic SIGNALS using PYTHON


SOFTWARE USED : PYTHON 3.10(64-BIT)
THEORY:
A signal is a form of communication or message that carries information or instructions. It can be in
the form of sound, light, or any other type of wave that can be detected and interpreted by a receiver.
Signals are used in various fields such as telecommunications, electronics, and even in our everyday
lives.
There are various types of signals, depending on how they are transmitted and the nature of the
information they carry. Some common types are
1. Analog signals
2. Digital signals
3. Electromagnetic signals
4. Audio signals
5. Video signals.
Each type of signal has its own unique characteristics and applications

CODE:
import numpy as np

import [Link] as plt

t = [Link](0, 2*[Link], 100)

f=1

A=1

sinusoidal_signal=A*[Link](2*[Link]*f*t)

complex_exponential_signal =[Link](1j*2*[Link]*f*t)

[Link](2,1,1)

[Link](t,sinusoidal_signal)

[Link]('SinusoidalSignal')

[Link]('Time')
GVPECE

[Link]('Amplitude')

[Link](2,1,2)

[Link](t,[Link](complex_exponential_signal), [Link](complex_exponential_signal),label='Real')

[Link]('ComplexExponentialSignal')

[Link]('Time')

[Link]('Amplitude')

[Link]()

plt.tight_layout()

[Link]()

PROCEDURE: 1. Open IDLE 3.7.0(64-bit) window.


2. Click on new file. A new page is created
3. Then write the code given.
4. Then save the code with ‘.py’ extension
5. Click on run=>run module.
6. Verify the output.

PRECAUTIONS:
● Program must be written carefully to avoid errors.
● Programs should be saved before executing the code.
● Check the error before running of programs.

CONCLUSION:
Hence, Generation of Basic Signals is done using PYTHON 3.7.0(64-Bit).
GVPECE

Experiment-21
Name: G Jnanesh
Roll no.:5231421031
OUTPUT:
GVPECE

GAYATRI VIDYA PARISHAD COLLEGE FOR DEGREE AND PG COURSES (A)


RUSHIKONDA, VISAKHAPATNAM 530045|website:[Link]
(Approved by AICTE| Permanently Affiliated to Andhra University |Reaccredited by NAAC| ISO 9001:2015)
ENGINEERING AND TECHNOLOGY PROGRAM
DEPARTMENT OF ELECTRONICS & COMMUNICATION ENGINEERING
(PROGRAM ACCREDITED BY NBA)

LAB ASSESSEMENT SHEET

1. NAME OF THE LABORATORY : PROBLEM SOLVING USING PYTHON LAB

2. NAME OF THE STUDENT : GUGGILAPU JNANESH

3. YEAR & SEMESTER : II/IV [Link]

4. ROLL NUMBER : 5231421031

5. NAME OF THE EXPERIMENT : Find the ENERGY & POWER of a Signal

6. DATE OF EXECUTION : 08/11/2024

7. DATE OF SUBMISSION :

S. No ACTIVITY
MARKS(OUT OF 10)
1. INITIAL PREPARATION

2. DRESS CODE & ID CARD

3. OBSERVATIONS

4. VIVA VOCE

5. PRESENTATION OF THE
LABORATORY REPORT

TOTAL MARKS (OUT OF 50)

Date: SIGNATURE OF THE FACUL


GVPECE

EXPERIMENT NO 22

TITLE: Find the ENERGY & POWER of a given SIGNAL.


SOFTWARE USED : PYTHON 3.10(64-BIT)
THEORY:
Energy of a Signal:
Definition: The energy of a signal is a measure of its intensity or magnitude. In the context of
discrete signals (such as a list of numerical values).It is often computed as the sum of the squares of
the individual values in the signal.
Mathematically:

Formula:
Power of a Signal:

Definition: Power is another measure related to the intensity of a signal. It represents the average
energy per unit time. In the context of discrete signals, power is often calculated by dividing the
energy by the length of the signal.
Mathematically:
Formula: P=N/E; where E is the energy of the signal and N is the
number of samples.

CODE:
def compute_energy_power(signal):
energy=sum(value**2 for value in signal)
power=energy/len(signal)
return energy,power
user_defined_signal=[4,2,3,4,5]
energy_result,power_result=compute_energy_power(user_defined_signal)
print(f"Signal:{user_defined_signal}")
print(f"Energy of the signal:{energy_result}")
GVPECE

print(f"Power of the signal:{power_result}")

PROCEDURE: 1. Open IDLE 3.7.0(64-bit) window.


2. Click on new file. A new page is created
3. Then write the code given.
4. Then save the code with ‘.py’ extension
5. Click on run=>run module.
6. Verify the output.

PRECAUTIONS:
● Program must be written carefully to avoid errors.
● Programs should be saved before executing the code
● Check the error before running of programs

CONCLUSION:
Hence, ENERGY & POWER of a Signal is done using PYTHON 3.7.0(64-Bit).
GVPECE

Experiment-22
Name: G Jnanesh
Roll no.:5231421031

OUTPUT:
GVPECE

GAYATRI VIDYA PARISHAD COLLEGE FOR DEGREE AND PG COURSES (A)


RUSHIKONDA, VISAKHAPATNAM 530045|website:[Link]
(Approved by AICTE| Permanently Affiliated to Andhra University |Reaccredited by NAAC| ISO 9001:2015)
ENGINEERING AND TECHNOLOGY PROGRAM
DEPARTMENT OF ELECTRONICS & COMMUNICATION ENGINEERING
(PROGRAM ACCREDITED BY NBA)

LAB ASSESSEMENT SHEET

1. NAME OF THE LABORATORY : PROBLEM SOLVING USING PYTHON LAB

2. NAME OF THE STUDENT : GUGGILAPU JNANESH

3. YEAR & SEMESTER : II/IV [Link]

4. ROLL NUMBER : 5231421031

5. NAME OF THE EXPERIMENT : Sampling of SIGNAL

6. DATE OF EXECUTION : 08/11/2024

7. DATE OF SUBMISSION :

S. No ACTIVITY
MARKS(OUT OF 10)
1. INITIAL PREPARATION

2. DRESS CODE & ID CARD

3. OBSERVATIONS

4. VIVA VOCE

5. PRESENTATION OF THE
LABORATORY REPORT

TOTAL MARKS (OUT OF 50)

Date: SIGNATURE OF THE


FACULTY
GVPECE

EXPERIMENT NO 23

TITLE: Sampling of SIGNAL


SOFTWARE USED : PYTHON 3.10(64-BIT)
THEORY:
Sampling theorem:
The sampling theorem specifies the minimum-sampling rate at which a continuous-time signal
needs to be uniformly sampled so that the original signal can be completely recovered or
reconstructed by these samples alone. This is usually referred to as Shannon's sampling theorem in
the literature.
Statement: A continuous time signal can be represented in its samples and can be recovered
back when sampling frequency fs is greater than or equal to the twice the highest frequency
component of message signal. i. e.

fs≥2fm.
CODE:
import numpy as np

import [Link] as plt

# Set the parameters for the sine wave

frequency = 10 # Frequency of the sine wave (in Hz)

amplitude = 1 # Amplitude of the sine wave

duration = 1 # Duration of the signal (in seconds)

# Generate the time axis

sampling_rate = 100 # Initial sampling rate (in samples per second)

time = [Link](0, duration, 1 / sampling_rate)

# Generate the sine wave signal

signal = amplitude * [Link](2 * [Link] * frequency * time)

# Plot the original signal

[Link]()

[Link](time, signal)

[Link]("Original Signal")
GVPECE

[Link]("Time (s)")

[Link]("Amplitude")

[Link]()

# Resample the signal at different sampling rates

new_sampling_rates = [50, 25, 10] # New sampling rates to test

for new_sampling_rate in new_sampling_rates:

new_time = [Link](0, duration, 1 / new_sampling_rate)

new_signal = [Link](new_time, time, signal)

# Plot the resampled signal

[Link]()

[Link](new_time, new_signal)

[Link](f"Resampled Signal (Sampling Rate: {new_sampling_rate})")

[Link]("Time (s)")

[Link]("Amplitude")

[Link]()

PROCEDURE: 1. Open IDLE 3.7.0(64-bit) window.


2. Click on new file. A new page is created
3. Then write the code given.
4. Then save the code with ‘.py’ extension
5. Click on run=>run module.
6. Verify the output.

PRECAUTIONS:
● Program must be written carefully to avoid errors.
● Programs should be saved before executing the code
● Check the error before running of programs

CONCLUSION:
Hence, Sampling of Signal is done using PYTHON 3.7.0(64-Bit).
GVPECE

Experiment-23
Name: G Jnanesh
Roll no.:5231421031
OUTPUT:
GVPECE
GVPECE

GAYATRI VIDYA PARISHAD COLLEGE FOR DEGREE AND PG COURSES (A)


RUSHIKONDA, VISAKHAPATNAM 530045|website:[Link]
(Approved by AICTE| Permanently Affiliated to Andhra University |Reaccredited by NAAC| ISO 9001:2015)
ENGINEERING AND TECHNOLOGY PROGRAM
DEPARTMENT OF ELECTRONICS & COMMUNICATION ENGINEERING
(PROGRAM ACCREDITED BY NBA)

LAB ASSESSEMENT SHEET

8. NAME OF THE LABORATORY : PROBLEM SOLVING USING PYTHON LAB

9. NAME OF THE STUDENT : GUGGILAPU JNANESH

10. YEAR & SEMESTER : II/IV [Link]

11. ROLL NUMBER : 5231421031

12. NAME OF THE EXPERIMENT : OPERATION on SIGNALS

13. DATE OF EXECUTION : 08/11/2024

14. DATE OF SUBMISSION :

S. No ACTIVITY
MARKS(OUT OF 10)
1. INITIAL PREPARATION

2. DRESS CODE & ID CARD

3. OBSERVATIONS

4. VIVA VOCE

5. PRESENTATION OF THE
LABORATORY REPORT

TOTAL MARKS (OUT OF 50)

Date: SIGNATURE OF THE


FACULTY
EXPERIMENT NO 24

TITLE: OPERATION on SIGNALS using PYTHON.


SOFTWARE USED : PYTHON 3.10(64-BIT)
THEORY:
⮚ Time shifting of signal:
Time shifting, also known as time delay or time lag, is a fundamental operation in
signal processing where the entire signal is shifted or delayed in time. There are two
types of shifting.
[Link] shifting
[Link] shifting
1. RIGHT TIME SHIFT OF A SIGNAL: A time right shift refers to moving
a signal along the time axis in the rightward direction. It involves delaying the signal
or causing a shift towards later instances in the time domain. For example, if you have
a signal and perform a time right shift, you're essentially pushing the entire waveform
to occur later in time. This shift can be achieved by adjusting the time values
associated with each data point in the signal, moving them further along the time axis.
2. LEFT TIME SHIFT OF A SIGNAL: A time left shift refers to moving a
signal along the time axis in the leftward direction. Essentially, it involves bringing
the signal earlier in time or causing a shift towards earlier instances. For instance, in a
time series or signal, if you shift the entire waveform to the left by a certain amount of
time, it means the signal is being advanced or occurring earlier in the time domain.
This shift can be achieved by altering the time values associated with each data
point in the signal.
⮚ Time reversal of a signal:
Time reversal of a signal involves flipping the signal in time, essentially reversing the
order of its values. It is also called as time folding of a signal x(t) can be obtained by
folding the signal about t=0. This operation is very useful in convolution. It is denoted
by x(-t). It is also called reflection of signal about the time origin t=0This operation
can have various applications in signal processing, such as inverting the direction of
playback in audio signals or reversing the sequence of samples in digital
signal processing.
⮚ Amplitude scaling of a signal:
Amplitude scaling of a signal refers to the process of changing the magnitude of the
signal without altering its shape or other characteristics. This can be achieved by
multiplying the signal by a constant factor. Amplitude scaling involves multiplying
the entire signal by a constant factor, often denoted as A: y(t)=A⋅x(t), where y(t) is the
scaled signal and x(t) is the original signal.
⮚ Time scaling of a signal:
The process of multiplying a constant to the time axis of a signal is known as time
scaling of the signal. The time scaling of signal may be time compression or time
expansion depending upon the value of the constant or scaling factor. The time
scaling operation of signals is very useful when data is to be fed at some rate and is to
be taken out at a different rate. The time scaling of a continuous time signal x(t) can

by,𝑥(𝑡) → 𝑦(𝑡) = 𝑥(𝛼𝑡)Where, α is a constant, called the scaling factor.


be accomplished by replacing ‘t’ by ‘𝛼t’ in the function. Mathematically, it is given

CODE:
1). Time shifting of signal:-
RIGHT SHIFTING:

import numpy as np
import [Link] as plt
from scipy import signal
def right_shift_square_wave(frequency, duration, sampling_rate, shift_amount):
time = [Link](0, duration, int(sampling_rate * duration), endpoint=False)
square_wave = [Link](2 * [Link] * frequency * time)
shifted_time = time + shift_amount
shifted_square_wave = [Link](shifted_time, time, square_wave, left=0, right=1)
return time, square_wave, shifted_time, shifted_square_wave
# Parameters
frequency = 1.0 # Frequency of the square wave
duration = 5.0 # Duration of the signal
sampling_rate = 1000 # Sampling rate in Hz
shift_amount = 0.5 # Right shift amount in seconds
# Generate wave and shifted wave
time, square_wave, shifted_time, shifted_square_wave =
right_shift_square_wave(frequency, duration, sampling_rate, shift_amount)
# Plot the original and shifted square wave signals
[Link](figsize=(10, 4))
[Link](2, 1, 1)
[Link](time, square_wave)
[Link]('Original Square Wave Signal')
[Link]('Time [s]')
[Link]('Amplitude')
[Link](2, 1, 2)
[Link](shifted_time, shifted_square_wave)
[Link](f'Shifted Square Wave Signal (Right Shift by {shift_amount} seconds)')
[Link]('Time [s]')
[Link]('Amplitude')
plt.tight_layout()
[Link]()

LEFT SHIFTING:

import numpy as np
import [Link] as plt
from scipy import signal
def right_shift_square_wave(frequency, duration, sampling_rate, shift_amount):
time = [Link](1, duration, int(sampling_rate * duration), endpoint=False)
square_wave = [Link](2 * [Link] * frequency * time)
shifted_time = time - shift_amount
shifted_square_wave = [Link](shifted_time, time, square_wave, left=-1, right=0)
return time, square_wave, shifted_time, shifted_square_wave
frequency = 1.0 # Frequency of the square wave
duration = 5.0 # Duration of the signal
sampling_rate = 1000 # Sampling rate in Hz
shift_amount = 0.5 # Right shift amount
time, square_wave, shifted_time, shifted_square_wave
=right_shift_square_wave( frequency, duration, sampling_rate, shift_amount)
# Plot the original and shifted square wave signals
[Link](figsize=(10, 4))
[Link](2, 1, 1)
[Link](time, square_wave)
[Link]('Original SquareWaveSignal')
[Link]('Time')
[Link]('Amplitude')
[Link](2, 1, 2)
[Link](shifted_time, shifted_square_wave)
[Link](f'Shifted Square Wave Signal (left Shift by {shift_amount} seconds)')
[Link]('Time')
[Link]('Amplitude')
plt.tight_layout()
[Link]()

2) Time reversal of a signal:

import numpy as np
import [Link] as plt
# Generating a sine wave
time = [Link](0, 2 * [Link], 0.1)
amplitude = [Link](time)
# Reversing the signal
reversed_amplitude = [Link](amplitude)
# Plotting the original and reversed signal
[Link](figsize=(10, 4))
[Link](1, 2, 1)
[Link](time, amplitude)
[Link]('Original Signal')
[Link](1, 2, 2)
[Link](time, reversed_amplitude)
[Link]('Reversed Signal')
plt.tight_layout()
[Link]()

3) Amplitude scaling of a signal:

import numpy as np
import [Link] as plt
def amplitude_scaling(signal, scale_factor):
scaled_signal = signal * scale_factor
return scaled_signal
# Generate a sample signal (e.g., a sine wave)
time = [Link](0, 1, 1000, endpoint=False) # 1 second, 1000 samples
frequency = 5 # 5 Hz
amplitude = 1
signal = amplitude * [Link](2 * [Link] * frequency * time)
# Define the scaling factor
scale_factor = 2.0
# Scale the signal
scaled_signal = amplitude_scaling(signal, scale_factor)
# Plot the original and scaled signals
[Link](figsize=(10, 6))
[Link](time, signal, label='Original Signal')
[Link](time, scaled_signal, label=f'Scaled Signal (x {scale_factor})', linestyle='dashed')
[Link]('Amplitude Scaling of a Signal')
[Link]('Time')
[Link]('Amplitude')
[Link]()
[Link](True)
[Link]()

4) Time scaling of a signal:

import numpy as np
import [Link] as plt
def original_signal(t):
# Define the original signal function here.
# Example: x(t) = sin(2 * pi * t)
return [Link](2 * [Link] * t)
def time_scaling(t, a):
# Perform time scaling: y(t) = x(a * t)
return original_signal(a * t)
def main():
# Generate time values
t = [Link](0, 1, 1000)
# Scaling factor
scaling_factor = 2 # You can adjust this value
# Original signal
x = original_signal(t)
# Scaled signal
y = time_scaling(t, scaling_factor)
# Plot the original and scaled signals
[Link](figsize=(10, 5))
[Link](t, x, label='Original Signal')
[Link](t, y, label=f'Scaled Signal (a = {scaling_factor})')
[Link]('Time Scaling of a Signal')
[Link]('Time')
[Link]('Amplitude')
[Link]()
[Link](True)
[Link]()
if __name__ == "__main__": # This line was corrected
main()

PROCEDURE: 1. Open IDLE 3.7.0(64-bit) window.


2. Click on new file. A new page is created
3. Then write the code given.
4. Then save the code with ‘.py’ extension
5. Click on run=>run module.
6. Verify the output.

PRECAUTIONS:
● Program must be written carefully to avoid errors.
● Programs should be saved before executing the code
● Check the error before running of programs

CONCLUSION:

Hence, Basic Operations of Signals is done using PYTHON 3.7.0(64-Bit).


Experiment-24
Name: G Jnanesh
Roll no.:5231421031

OUTPUT: RIGHT SHIFTING OF A SIGNAL

Experiment-24
Name: G Jnanesh
Roll no.:5231421031

OUTPUT: LEFT SHIFTING OF A SIGNAL

Experiment-24
Name: G Jnanesh
Roll no.:5231421031

OUTPUT: TIME REVERSAL OF A SIGNAL

Experiment-24
Name: G Jnanesh
Roll no.:5231421031

OUTPUT: AMPLITUDE SCALING OF A SIGNAL


Experiment-24
Name: G Jnanesh
Roll no.:5231421031

OUTPUT: TIME SCALING OF A SIGNAL

You might also like