Saturday, May 2, 2026
Home Blog Page 8

POWER SPECTRUM DETERMINATION OF GIVEN SIGNAL AND LOWPASS FIR FILTER IMPLEMENTATION

POWER SPECTRUM DETERMINATION OF GIVEN SIGNAL

THEORY: The power spectrum describes the distribution of signal power over a frequency spectrum. The most frequently used way of generating a power spectrum is with using a discrete Fourier transform, but also other techniques such as the maximum entropy method can also be used. The power spectrum also can be defined because the Fourier transform of auto correlation function.

Steps involved in performing power spectrum operation for a given signal

Step I: let’s consider input sequence x

Step II: And the given sampling frequency, input frequency and length of the spectrum.

Step III: In order to find power spectrum of input sequence by using matlab command spectrum.

Step IV: And plot power spectrum using specplot.

Program:

clc;

clear all;

close all;

N=1024;

fs=8000;

f=input(‘enter the frequency[1 to 5000]:’);

n=0:N-1;

x=sin(2*pi*(f/fs)*n)

pxx=spectrum(x,N);

specplot(pxx,fs);

grid on

xlabel(‘freq(hz)’);

ylabel(‘magnitude(db)’);

title(‘power spectrum of x(n)’);

Enter the frequency [1 to 5000]:2000

LOWPASS FIR FILTER IMPLEMENTATION

THEORY:

Where the FIR filters are also known as digital filters with finite impulse response. They are also referred as non-recursive digital filters because they do not have the feedback.

An FIR filter has two most important advantages when compared with an IIR design:

Firstly, there’s no feedback circuit within the structure of an FIR filter. Due to not having a feedback circuit, an FIR filter is inherently stable. Meanwhile, for an IIR filter, we’d like to see the steadiness.
Secondly, it also provide a linear-phase response. As a matter of fact, a linear-phase response is that the most frequently used advantage of an FIR filter when compared with an IIR design otherwise, for the same filtering specifications; an IIR filter will lead to a lower order.

FIR FILTER DESIGN

An FIR filter is meant by finding the coefficients and filter order that meet certain specifications, which may be within the time-domain (e.g. a matched filter) and while in the frequency domain (most common). Matched filters perform a cross-correlation between the input and a known pulse-shape. The FIR convolution may be a cross-correlation between the input and a time-reversed copy of the impulse-response. When a specific frequency response is desired, several different design methods are common:

1. Window design method

2. Frequency sampling method

3. Weighted least squares design

WINDOW DESIGN METHOD

In the window design method, one first designs a perfect IIR filter then truncates the infinite impulse response by multiplying it with a finite length window function. The result’s a finite impulse response filter whose frequency response is modified from that of the IIR filter.

Steps involved in low pass FIR filter design:

Step I: Let’s enter the pass band frequency (fp) and stop band frequency (fq).

Step II: Get the sampling frequency (fs), length of window (n) for the low pass FIR filter.

Step III: Let’s calculate the cut off frequency, fn

Step IV: Using boxcar, hamming, blackman Commands to design window.

Step V: Design filter by using above parameters.

Step VI: To find frequency response of the filter by using matlab command freqz.

Step VII: And plot the magnitude response and phase response of the filter.

Program:

clc;

clear all;

close all;

n=20;

fp=200;

fq=300;

fs=1000;

fn=2*fp/fs;

window=blackman(n+1);

b=fir1(n,fn,window);

[H W]=freqz(b,1,128);

subplot(2,1,1);

plot(W/pi,abs(H));

title(‘magnitude response of lpf’);

ylabel(‘gain in db——–>’);

xlabel(‘normalized frequency——>’);

subplot(2,1,2);

plot(W/pi,angle(H));

title(‘phase response of lpf’);

ylabel(‘angle——–>’);

xlabel(‘normalized frequency——>’);

CHARACTER ORIENTED PROTOCOL AND BIT ORIENTED PROTOCOL

CHARACTER ORIENTED PROTOCOL:

The character-oriented protocol is of an 8-bit size frame, the header which covers the source and destination address and some other control information, whereas the trailer carries error detection or error correction redundancy bits. In order to separate one frame from the next frame, the designer added a flag bit at the beginning and end of the frame. The most popular protocol which used to exchange only text by the data link layer.

If the receiver encounters other information rather than text in the middle of the data the user thinks of the end of the problem. To overcome this problem a byte-stuffing strategy was added to character-oriented framing. If the same pattern of the data found in the frame a special byte is added to the data section is called character stuffing (byte stuffing). This is called an escape character (ESC), which has a predetermined bit pattern. If we add ESC character in the middle of the data section means it treated has the next character as data, not a delimiting flag.

But it again creates a problem if the data contain an Escape character followed by a flag, by this the receiver will remove the ESC  character from the data section but keeps the flag, which is incorrectly interpreted because of the end of the frame. To over the encountered problem, if the escape character is part of the text, an extra ESC character added to show that the second one is the part of the text.

BIT ORIENTED PROTOCOL:

Bit stuffing is the process of adding one extra 0 whenever five consecutive is follow a 0 in the data so that the receiver does not mistake the pattern 0111110 for a flag. In this, the data section of a frame is a sequence of bits to be interpreted by the upper layer as text, audio, video, and audio, etc.  Where in addition to the header, the designer will require a delimiter to separate one frame from other frames. Well, most protocols use a special 8-bit pattern flag as the delimiter to determine the starting and end of the frame.  

Ethernet Standards

GIGABIT ETHERNET:

In order to provide higher order data rates it resulted in gigabit ethernet protocol. It standard is defined by IEEE as 802.3z. The main for designing gigabit ethernet is.

  • It upgraded with the data rates upto 1 Gbps.
  • It has same 48 bit address.
  • Which has the same frame format compared with other standards.

In the full-duplex mode gigabit ethernet there is no collision; whereas the maximum length of the cable is determined by the signal attenuation in the cable.

Still there is use of half duplex in gigabit ethernet but it is rare. For this case the switch is replaced by hub.

While the physical layer is some complicated when compared with the traditional or standard methods. Let us discuss some features in the physical layer.

Gigabit is designed in such a way that we can connect two or more stations. If there is only one station it is connected in point-to-point. If their more than one station it is connected in a star topology with switch or hub at the center.

Gigabit ethernet can be categorized based on the wire implementation it may be two or four wire implementation. In two-wire implementation designer can use fiber-optic cable (100Base –SX, short wave, or 100 Base-LX, long range) or STP (shielded twisted pair)(1000 Base-CX)
. While in four-wire implementation designer can use category 5 twisted pair cable (1000 Base-T).

Gigabit ethernet using 8B/10B encoding scheme because Manchester encoding scheme involves high bandwidth. Where 8B/10B encoding scheme prevents long sequence of 0 or 1’s in the stream, but the resulting stream is 1.25 Gbps.

Where in four wire implementation it is not possible to use 2 wire for input and 2 wire for output, because  each wire would need to carry 500 Mbps, which exceeds the category of 5 UTP to overcome the drawback designer used 4D-PAM5 encoding scheme to reduce the bandwidth.

Thus all, the four wire are involved in both input and output; while each wire carries 250Mbps, which is in the range of the category 5 UTP cable.

To Plot FFT (Fast Fourier Transform Algorithms) For the Given Sequence

Theory:

FFT is a most efficient algorithm used in speech processing, frequency estimation and communication. FFT utilizes full advantage of two symmetry properties in order to provide efficient algorithm for DFT. while considering a divide and conquer approach, a computationally efficient algorithm can be developed. This methods depends on the decomposition of an N-point DFT into successively smaller size then DFTs. While in the N-point sequence, the term N can be expressed as N = r1r2r3, …, rm, then N = r m, can be decimated into r-point sequences For each r point sequence, r-point DFT are often computed. Hence the DFT is of size r. if the number r is called the radix of the FFT algorithm while the number m indicates the number of stages in computation. If the value of r = 2, it is called radix-2 FFT.

Steps involved in finding the FFT of the given sequence:

  • Let’s consider an input sequence as x[n].
  • Let’s find the length for the input sequence using length command.
  • In order to find FFT and IFFT by using the matlab commands fft and ifft.
  • Let’s plot the magnitude and phase response for the given sequence.
  • And finally display the results.

Program:

clc;

clear all;

close all;

x=input(‘Enter the sequence : ‘)

N=length(x)

xK=fft(x,N)

xn=ifft(xK)

n=0:N-1;

subplot (2,2,1);

stem(n,x);

xlabel(‘n—->’);

ylabel(‘amplitude’);

title(‘input sequence’);

subplot (2,2,2);

stem(n,abs(xK));

xlabel(‘n—->’);

ylabel(‘magnitude’);

title(‘magnitude response’);

subplot (2,2,3);

stem(n,angle(xK));

xlabel(‘n—->’);

ylabel(‘phase’);

title(‘Phase response’);

subplot (2,2,4);

stem(n,xn);

xlabel(‘n—->’);

ylabel(‘amplitude’);

title(‘IFFT’);

Output:

Enter the sequence: [3 2 4 5 1]

x = 3     2     4     5     1

N =5

xK =15.0000 + 0.0000i  -3.3541 – 0.3633i   3.3541 – 1.5388i   3.3541 + 1.5388i  -3.3541 + 0.3633i

xn =3.0000    2.0000    4.0000    5.0000    1.0000

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.