Thursday, March 5, 2026
Home Blog Page 7

LIST in python

0

LIST

  • List is an ordered sequence of items.
  • It is one of the most used data type in python and is very flexible.
  • All the items in list do not need to be of same type.
  • List is one of 4 built-in data types in Python used for collection of data, the other 3 are Tuple , set and Dictionary.
  • List is created using square brackets.

Example:1

nums=[12,34,56,78,89,12]
print(nums)

output: [12, 34, 56, 78, 89, 12]

 Items in a list

  • Items in a list are changeableordered  and allow duplicate values.
  • List items are indexed, starting from [0] index value.

Ordered

  • Here the term  ordered refers that, it means the items have a defined order, and this order cannot be changed.
  • If  in case any new items are added to the list  that will be placed at the end of the list.

Changeable

  • Here the term changeable indicates that the values in a list can be removed, added  or  changed after the creation of list.

Allow Duplicates

In a list  it allows us to  have the  repeated values

Example2

>> lst=[12, 34, 45, 67, 89,12]

>>print(lst)

Indexing in list

  • In list indexing is as in string i.e., left to right for reversal printing then indexing is done from right to left.
  • If you want to pick up the third value that is second indexed value then

Example:

Numeric conversions and creation of complex number

0
  • We can able to convert from one numeric form to other numeric form.
  • The following are the different conversions
  • Integer to float conversion
  • Float to integer conversion
  • Integer to complex
  • Complex to integer

Integer to float conversion

Example

a=5

b= float(a)

print(b)

output:

5.0

Float to integer conversion

example

a=5.5

b= int(a)

print(b)

Output:  5

Integer to complex

Example:

a=5

b= complex(a)

print(b)

output:

(5+0j)

 How to Create complex  number?

The following is the way to create a complex number.

a=5

b=6

c=complex(a,b)

print(c)

output:

(5+6j)

Boolean

  •  In python Boolean represents true or false
  • The following example represents  how boolean type works
a=10

b=20

a<b

output: True

In python true is represented by 1 and false is represented by 0.

>>int (True)

Ans:1

>>Int(false)

Ans:0

Data types in Python

0


Data type specifies the type of data present inside a variable.
• Every value has a data type
• In python it is not required to specify the data type explicitly.
• Based on the value, the type will be assigned automatically.
• Python is dynamically typed language.


Python contains the following data types

• None
• Numeric
• List
• Tuple
• Set
• String
• Range
• Dictionary/ mapping
NONE:
• If a variable is not assigned with any value is called None.
Numeric
• Numeric type of data is classified into four types

  1. Int
  2. Float
  3. Complex
  4. Bool
    Integer
    Integer includes the values that are integers.
    Integer type variables stores the values that are in integer format.
    • Example:
    num= 4
    print(num)
    output :4
    Float:
    • Float includes decimal numbers.
    Example
    • num= 5.5
    print(num)
    output:
    5.5
    Complex:

    • It includes real and imaginary values.
    • Example:>>num=7+8j
    num= ‘7+8j’
    print(num)
    output:
    7+8j
    Note: In all the above data types we are not specifying the data type before the variable. This means that in python thee is no need to type the data type explicitly. It considers the type of the data based in the given input value

Types of Variables, Assigning, declaring and deleting variables.

0

Types of variables

There are two types of variables in python  local and global variables.

•     In Python, global variable is a variable declared outside of the function or in global scope.

•    global variable can be accessed inside or outside of the scope  function

Local variables

Local variables are the variables that are used with in a function or method.

Global variables

Global variables are used when we use the variable in the entire program.

Assigning values to variables

•  Python allows us to assign values to the variables.

• Lets assume the value 5 is assigned to the variable ‘a’

Multiple assignment

• In multiple assignment , multiple variables are assigned with multiple values.

Example

Declaring and re-declaring the variables.

•  Lets first see how to declare a variable. Its that simple that assigning variable a value to hold.

Example

>>> a=9

>>> print(a)

9

Now we re declare the variable.

   a=9

print(a)

a= 33

print(a)

output:

33

Here the output gives the re assigned value instead of first value. This means that the first value is replaced by second  value.

Deleting the variable

• In python you can delete the variable that you  previously assigned  the value using del command.

Example

a=7

print(a)

del a

print(a)

Identifiers and Variables in Python

0

Identifiers in python

  • A name in python program is called identifier.
  • It can be a class name or function name or variable name

Rules to define identifier

  • Identifiers  include alphabets symbols(either lower case or upper case)
  • Identifiers include  digits(0 to 9)
  • Identifiers include underscore (_)symbol.
  • Identifiers should be case sensitive.

Don’t s while defining an identifier

  • We cannot use keywords as identifiers
  • Identifiers should not start with digit.

Special case of using underscore

  • If the identifier starts with underscore (_)symbol then it is private.

Variables in python

 What is a variable?

•   A variable refers to  memory location.

•   It is used to store the value .

•   Variable is used to give data to the computer for processing .

Specifying a variable

•   In python we don’t need to specify the type of variable because python is a dynamically typed to get variable type.

•  Variable names include  letters and digits but they have to begin with a letter or an underscore.

•   It is suggested to use  lowercase letters for variable name

Comments and Types of comments in python

0

  • Comments are very important  in  writing a program.
  • Python interpreter  ignores comment.
  • In python , commenting  is indicated by ‘#’ ,It is extended till the end of the physical line.
  • Though’ #’ indicates a comment , but when it is written along with string is not considered as a comment.
  • Python supports two types of comments.
  • Single line comments
  • Multi line comments

Single line comments

  • In this type of comment, hash(#) character is followed by the information that explains the further text.
  • In case user wants to specify a single line comment, then comment must start with (#)

Multi-line comments

  • In case if user has the comments that extend to multiple lines , One way of doing this is to use ‘#’ in the beginning of each line.
  • Multi-lined comments  should be given in triple quotes.

TYPES OF ETHERNET

FAST ETHERNET:

In order to compete with LAN protocols fast ethernet was designed.it can transmit data 10 times faster when compared with standard ethernet. It has 100mbps data rate, which has same minimum and maximum frame length when compared with standard ethernet. A new feature which added to fast ethernet is auto negotiation, which was designed particularly for the following uses.

It allows a device of 10 mbps is connected to a device of 100mbps capacity.

It allow one device to have multiple capabilities.

It also allowed to check the hub’s capabilities.

Fast ethernet was implemented at physical layer which is categorized has follows two-wire or four-wire. In two-wire implementation further categorized into 5 UTP (100Base-TX) or fiber-optic cable (100Base-Fx). And four-wire is implemented for 3 UTP (100 BaseT4).

The encoding scheme used for fast ethernet:

Manchester encoding scheme required 200-M baud bandwidth for the data rate of 100Mbps, which seems unsuitable for medium such as twisted-pair. For this reason, the fast ethernet was designed with an alternative encoding/decoding scheme.

100Base-TX:

It uses two pair of twisted-pair cable i.e., 5 UTP or STP. In order to obtain good performance and bandwidth MLT-3 scheme was implemented. Where MLT-3 scheme is not a self-synchronous line-coding scheme, for this we are providing 4B/5B block coding to provide bit synchronization by preventing the occurrence of a long sequence of 0s and 1s. Which will improves the data rate of 125 Mbps.

100Base-FX:

It uses two pair of twisted-pair of fiber-optic cables. This will handle high bandwidth requirement by using simple encoding schemes. In order to provide the above requirement designer provided NRZ-I encoding scheme which has a bit synchronization problem for long sequence of 0s.to over the above problem designer used 4B/5B encoding scheme which can improves the data rates from 100 to 125 mbps, which can be easily handled by fiber-optics.

 100Base-T4: It was designed by using 3 or higher UTP. This implementation will be done by using four-pair of UTP for transmitting 100mbps. In this encoding/decoding schemes are more complicated, for this reason, the designer used three pairs of UTP category 3, however, can handle only 75 M baud each. In order to convert 100 Mbps to  75 M baud designer used 8B/6T  to satisfies the above requirement.

To plot autocorrelation and frequency response of a system in differential equation form for the given sequences

0

Theory for autocorrelation:

Auto Correlation Function Autocorrelation function is a measure of similarity between a signal & its time-delayed version. It is represented with R(k). While the autocorrelation function of x(n) is determined by

R11 (k) =R(k)=

Steps to perform auto correlation:

  • And the given input sequence is x[n].
  • Let the given impulse response of sequence h (n).
  • In order to auto correlation by using the matlab command xcorr.
  • Let’s plot the sequence x[n], h[n], z[n].
  • Next step is to display the result.

Program:

clc;

close all;

clear all;

% Let’s the two input sequences

x=input(‘enter input sequence’)

subplot(1,2,1);

stem(x);

xlabel(‘n’);

ylabel(‘x(n)’);

title(‘input sequence’);

% And the auto correlation of the given input sequence

z=xcorr(x, x);

disp(‘The values of z are = ‘);

disp(z);

subplot(1,2,2);

stem(z);

xlabel(‘n’);

ylabel(‘z(n)’);

title(‘auto correlation of input sequence’);

OUTPUT:

Enter input sequence [2 4 5 6]

x = 2     4     5     6

And the values of z are =

   12.0000   34.0000   58.0000   81.0000   58.0000   34.0000   12.0000

The frequency response of the signal in differential equation form:

Systems respond differently to inputs of different frequencies. Where some of the systems may amplify components with certain frequencies, and attenuate components of other frequencies. And the way system output is related to the system input with different frequencies is called the frequency response of the system. We can convert it to polar notation in the complex plane. This will provides us the magnitude and an angle. We call the angle the phase.

Amplitude Response: For each frequency, the magnitude represents the system’s tendency to amplify or attenuate the input signal.

Phase Response: The phase represents the system’s tendency to modify the phase of the input sinusoids.

Steps for obtaining frequency response of the signal:

  • And the given numerator coefficients of the given transfer function or difference equation.
  • And the given denominator coefficients of the given transfer function or difference equation
  • Let’s pass these coefficients to matlab command freqz to find frequency response.
  • In order to find magnitude and phase response by using matlab commands abs and angle.
  • Let’s plot the magnitude and phase response.

Program:

clc;

clear all;

b=input(‘Enter the numerator coefficients:’);

a=input(‘Enter the denominator coefficients:’);

[h,w]=freqz(b,a);

subplot(2,1,1);

plot(w/pi,abs(h));

grid;

xlabel(‘Normalised Frequency’);

ylabel(‘Magnitude in dB’);

title(‘Magnitude Response’);

subplot(2,1,2);

plot(w/pi,angle(h));

grid;

xlabel(‘Normalized Frequency’);

ylabel(‘phase in radians’);

title(‘Phase Response’);

CATEGORIES OF ETHERNET

DIFFERENT TYPES OF ETHERNET:

Depending on the encoding and decoding operation Ethernet are categorized into four:

STANDARD ETHERNET:

Standard Ethernet is implemented using digital signaling with the data rates of 10 Mbps.  Whereas at the sender, the data is converted into a digital signal using Manchester scheme. While at the receiver it uses Manchester scheme in order to decode the received signal. Manchester scheme is self-synchronous used for providing a transition at each bit interval. Standard Ethernet are categorized in to four types. They are as shown in below figure.

10BASE5 🙁 THICK ETHERNET)

This is the first implementation of standard Ethernet it is also known as thick ethernet. Name is derived based on the size of the cable. It is the first implementation which used bus topology with an external transceiver connected via a tap to a thick coaxial cable. Where transceiver is used for transmitting and receiving and detecting collisions. In order to provide separate path for transmitting and receiving data via transceiver cable. The maximum length of the cable should not exceed 500m, otherwise there will be degradation of the signal.

                 Transceiver          Thick coaxial cable maximum 500 m

10BASE 2: (THIN ETHERNET)

Thin ethernet is the second implementation of standard ethernet it also uses the bus topology, but the cable very thinner and more flexible. In this, the transceiver is the part of the network interface card (NIC), which is installed inside the station. It is very less expensive when compared with the thick ethernet, Its installation is simpler because of flexible. And the length of the thin ethernet is 185m.

10BASE-T: (TWISTED PAIR)

Twisted pair ethernet is the third implementation of the standard ethernet, which uses star topology. In which stations are connected to a hub via two pair of twisted cable. In this two pair of twisted cable create two paths between the station and hub. The maximum length of the cable is 100m.

10BASE-F: (FIBER CABLE)

10BASE-F uses a star topology to connect stations to a hub, the stations are connected to the hub using two fiber-optics cables.

TO PLOT LINEAR CONVOLUTION FOR THE GIVEN FINITE SEQUENCE

0

linear Convolution Theory:

Convolution is a mathematical way of combining the two signals to form a third signal. It is the only most vital technique in Digital Signal Processing. Using the strategy of impulse decomposition, systems are described by a sign called the impulse response. Convolution is vital because it relates the three signals of interest: the input, the output, and therefore the impulse response. When convolution is used with linear systems. An input, x[n], enters a linear system with an impulse response, h[n], leading to an output, y[n].In equation form: x[n] * h[n] = y[n]. Expressed in words, the input convolved with the impulse response is adequate to the output. Just as addition is represented by the plus, +, and multiplication by the cross, x, convolution is represented by the star, *. The equation represents the linear convolution equation. Zero-padding is used in correlation to avoid mixing of convolution results at the output (due to circular convolution).

x[n] *h[n] = y[n]

Steps for performing linear operation:

  • Give input sequence x[n].
  • Give impulse response sequence h (n):
  • Find the convolution y[n] using the matlab command conv.
  • Plot x[n],h[n],y[n].

Program:

clc;

clear all;

close all;

x1=input(‘Enter the first sequence x1(n) = ‘);

x2=input(‘Enter the second sequence x2(n) = ‘);

L=length(x1);

M=length(x2);

N=L+M-1;

yn=conv(x1,x2);

disp(‘The values of yn are= ‘);

disp(yn);

n1=0:L-1;

subplot(311);

stem(n1,x1);

grid on;

xlabel(‘n1—>’);

ylabel(‘amplitude—>’);

title(‘First sequence’);

n2=0:M-1;

subplot(312);

stem(n2,x2);

grid on;

xlabel(‘n2—>’);

ylabel(‘amplitude—>’);

title(‘Second sequence’);

n3=0:N-1;

subplot(313);

stem(n3,yn);

grid on;

xlabel(‘n3—>’);

ylabel(‘amplitude—>’);

title(‘Convolved output’);

Output:

Enter the first sequence x1(n) = [2 3 5 1]

Enter the second sequence x2(n) = [2 4 2 5 3]

The values of yn are=

     4    14    26    38    35    36    20     3