DSE 03 - Digital Signal Processing - Practical 08 (Sudipta Majumder) - Merged

Download as pdf or txt
Download as pdf or txt
You are on page 1of 6

22/06/2023, 09:34 DSE 03 | Digital Signal Processing | Practical 08 [Sudipta Majumder]

8.band
Using a
gain rectangular
of unity, window,
cutoff design
frequency of a FIR low-pass
and filter
working with
at a
a pass-
sampling
17. frequency of . Take the length of the impulse response as
5kH z
1000H z

Solution
Code
In [1]: # importing necessary modules
import numpy as np
import matplotlib.pyplot as plt

fc = 1000 # cutoff frequency in Hz


fs = 5000 # sampling frequency in Hz
f = fc/fs
wc = 2*np.pi*f
M = 17 # Size of FIR filter
m = int((M-1)/2)

In [2]: # Impulse response function


def h(n):
if abs(n)!=m and abs(n)<M:
return (np.sin(wc*(n-m)))/(np.pi*(n-m))
elif n==m:
return 2*f
else:
return 0
# Frequency Response Function
def H(w):
r = hn[m]
for i in range(m):
r+=2*hn[i]*np.cos(w*(i-(M-1)/2))
return r

In [3]: hn = [h(i) for i in range(M)] # Calculation of Impulse response


# Displaying data
print(" Finite Impulse Response (FIR) Filter Design ".upper().center(100,'*'))
print(" Low-Pass Filter using Rectangular Window ".center(100))
print(f"Cutoff Frequency = {fc}, Sampling Frequency = {fs}, Filter Length, M = {M}".center(100))
print('-'.center(100,'-'))
print(" * * * * * Impulse Response * * * * * ".center(100))
for i in range(m+1):
if i!=m:
print(f"h({i}) = {round(h(i),6)} = h({M-1-i})".center(100))
else:
print(f"h({i}) = {h(i)}".center(100))

w = np.linspace(-np.pi,np.pi,1000) # Frequency domain


Hw = [H(i) for i in w] # Frequency response calculation
# Ploting Impulse response
plt.figure(figsize = (12,5))
plt.subplot(121)
plt.stem(hn)
plt.title("Impulse Response", fontsize=16)
plt.ylabel("h(n)", fontsize=12); plt.xlabel("Sample Index, n", fontsize=12);
plt.grid(alpha=0.6,ls='--')
# Plotting Frequency Response
plt.subplot(122)
plt.plot(w,Hw)
plt.title("Frequency Response", fontsize=16)
plt.ylabel("|H($\omega$)|", fontsize=12); plt.xlabel("frequency, $\omega$", fontsize=12)
plt.grid(ls='--')
plt.ylim(-0.5,2)

localhost:8888/nbconvert/html/Desktop/6th Sem Practical/DSE 03/DSE 03 %7C Digital Signal Processing %7C Practical 08 %5BSudipta Majumder%5D.ipynb… 1/2
22/06/2023, 09:34 DSE 03 | Digital Signal Processing | Practical 08 [Sudipta Majumder]

plt.xticks([-np.pi,-wc,0,wc,np.pi],['-$\pi$',f'{-2*f}$\pi$','0',f'{2*f}$\pi$','$\pi$'])
plt.show()

************************** FINITE IMPULSE RESPONSE (FIR) FILTER DESIGN ***************************


Low-Pass Filter using Rectangular Window
Cutoff Frequency = 1000, Sampling Frequency = 5000, Filter Length, M = 17
----------------------------------------------------------------------------------------------------
* * * * * Impulse Response * * * * *
h(0) = -0.023387 = h(16)
h(1) = 0.026728 = h(15)
h(2) = 0.050455 = h(14)
h(3) = -0.0 = h(13)
h(4) = -0.075683 = h(12)
h(5) = -0.062366 = h(11)
h(6) = 0.093549 = h(10)
h(7) = 0.302731 = h(9)
h(8) = 0.4

localhost:8888/nbconvert/html/Desktop/6th Sem Practical/DSE 03/DSE 03 %7C Digital Signal Processing %7C Practical 08 %5BSudipta Majumder%5D.ipynb… 2/2
22/06/2023, 09:34 DSE 03 | Digital Signal Processing | Practical 09 [Sudipta Majumder]

9. Design an FIR filter to meet the following specifications :


pass band edge , stop band edge
Fp = 2kH z , Pass band attenuation
Fs = 5kH z

Ap = 2dB , Stop band attenuation , Sampling frequency


As = 42dB fs = 20kH z

Solution
Code
In [1]: # importing required modules
import numpy as np
import matplotlib.pyplot as plt

Fp = 2000 # pass band edge frequency in Hz


Fs = 5000 # stop band edge frequency in Hz
fs = 20000 # sampling frequency in Hz
Ap = 2 # Pass band Attenuation in dB
As = 42 # Stop band Attenuation in dB

fc = int((Fp+Fs)/2) # Cutoff frequency in Hz


f = fc/fs
wc = 2*np.pi*f # cutoff frequency in radian
wp = 2*np.pi*(Fp/fs) # cutoff frequency in radian
ws = 2*np.pi*(Fs/fs) # cutofffrquency in radian
df = (Fs-Fp) # transition band
delta_p = (10**(0.05*Ap)-1)/(10**(0.05*Ap)+1)
delta_s = 10**(-0.05*As)
delta = min(delta_s,delta_p)
A = -20*np.log10(delta) # Actual Stopband Attenuation
M = int(np.ceil((A-7.95)/(14.36*df/fs))) # Size of FIR filter
if M%2==0:
M+=1
m = int((M-1)/2)

In [2]: # Impulse Response Fucntion


def h(n):
if abs(n)!=m and abs(n)<=M:
return (np.sin(wc*(n-m)))/(np.pi*(n-m))
elif n==m:
return wc/np.pi
else:
return 0
# Frequency response function
def H(w):
r = hn[m]
for i in range(m):
r+=2*hn[i]*np.cos(w*(i-(M-1)/2))
return r
# Hamming Window function
W = lambda n : 0.54-0.46*np.cos(2*np.pi*n/(M-1))

In [3]: # Impulse Response Calculation


hn = [h(i)*W(i) for i in range(M)]

# displaying data
print(" Finite Impulse Response (FIR) Filter Design ".upper().center(100,'*'))
print(" Low-Pass Filter using Rectangular Window ".center(100))
print(f"Cutoff Frequency = {fc} Hz, Sampling Frequency = {fs} Hz, Filter Length, M = {M}".center(100))
print(f"Pass band edge Frequency = {Fp} Hz, Stop band edge Frequency = {Fs} Hz".center(100))
print(f"Actual Stopband Attenuation, A = {A} dB, transition bandwidth = {df} Hz".center(100))
print('-'.center(100,'-'))
print(" * * * * * Impulse Response * * * * * ".center(100))
for i in range(m+1):
if i!=m:
print(f"h({i}) = {round(h(i),6)} = h({M-1-i})".center(100))

localhost:8888/nbconvert/html/Desktop/6th Sem Practical/DSE 03/DSE 03 %7C Digital Signal Processing %7C Practical 09 %5BSudipta Majumder%5D.ipynb… 1/2
22/06/2023, 09:34 DSE 03 | Digital Signal Processing | Practical 09 [Sudipta Majumder]

else:
print(f"h({i}) = {h(i)}".center(100))

# Frequency Response Calculation


w = np.linspace(-np.pi,np.pi,1000)
Hw = [abs(H(i)) for i in w]

#Impulse Response plot


plt.figure(figsize = (12,5))
plt.subplot(121)
plt.stem(hn)
plt.title("Impulse Response", fontsize=16)
plt.ylabel("h(n)", fontsize=12); plt.xlabel("Sample Index, n", fontsize=12);
plt.grid(alpha=0.6,ls='--')
# Frequency response plot
plt.subplot(122)
plt.plot(w,20*np.log10(Hw))
plt.title("Frequency Response", fontsize=16)
plt.ylabel("|H($\omega$)|", fontsize=12); plt.xlabel("frequency, $\omega$", fontsize=12)
plt.grid(ls='--')
tic_positions = [-np.pi,-ws,-wc,-wp,0,wp,wc,ws,np.pi]
tic_vals = ['-$\pi$','-$w_s$','-$w_c$','-$w_p$','0','$w_p$','$w_c$','$w_s$','$\pi$']
plt.xticks(tic_positions,tic_vals)
plt.show()

************************** FINITE IMPULSE RESPONSE (FIR) FILTER DESIGN ***************************


Low-Pass Filter using Rectangular Window
Cutoff Frequency = 3500 Hz, Sampling Frequency = 20000 Hz, Filter Length, M = 17
Pass band edge Frequency = 2000 Hz, Stop band edge Frequency = 5000 Hz
Actual Stopband Attenuation, A = 42.0 dB, transition bandwidth = 3000 Hz
----------------------------------------------------------------------------------------------------
* * * * * Impulse Response * * * * *
h(0) = 0.023387 = h(16)
h(1) = 0.044913 = h(15)
h(2) = 0.016394 = h(14)
h(3) = -0.045016 = h(13)
h(4) = -0.075683 = h(12)
h(5) = -0.016598 = h(11)
h(6) = 0.128759 = h(10)
h(7) = 0.283616 = h(9)
h(8) = 0.35

localhost:8888/nbconvert/html/Desktop/6th Sem Practical/DSE 03/DSE 03 %7C Digital Signal Processing %7C Practical 09 %5BSudipta Majumder%5D.ipynb… 2/2
(.) (https://jam.iitg.ac.in/)

(https://www.iitg.ac.in/)

Admission Brochure
(https://drive.google.com/file/d/1l_- Welcome, Sudipta Majumder
uj4zhtGO9fSEAwgt0JJPqsRu1QSqr/view)

Application Procedure JAM 2023 Round-2 Seat Allocation Result


(https://jam.iitg.ac.in/application-
procedure_admission.html)
Name: Sudipta Majumder
List of Documents Required
Registration Number(s): PH412A188
(https://jam.iitg.ac.in/documents_required.html)

Minimum Eligibility Requirements Allotted Academic Program: Joint M.Sc. - Ph.D.: PHYSICS
(MEQs)
(https://jam.iitg.ac.in/minimum- Admitting Institute: IIT Kharagpur
educational-qualifications.html)
Program Preference: 1
Seat Matrix
(https://drive.google.com/file/d/1gKtPstkul4mJktxFsdSToz7HOxY_o5C5/view) Category: SC

Allotment Category: SC
Admission Calendar
(https://drive.google.com/file/d/15_93C2nY_wMPoeFIFd5DYTAL6aEsfWkY/view)
PWD: No
Information for Category
Payment Status: Seat booking fee is received.
Certificate
(https://jam.iitg.ac.in/instruction_category_certificate.html)
Payment Reference Number: CPACUGWBB4

Admission Offer Status: Accepted and Freeze the offer.

Download Scorecard-PH (dlScorecard1.html) View Result

View Admission Form (viewDocsAdmissionForm.html)


To
The Controller of Examination,
Through Principal of Chakdaha College,
University of Kalyani,
Kalyani, Nadia.

SUB : Regarding arrangement for early conduction of 6th Sem Practical Exam to join IIT
M.Sc. Programme on time

Respected Sir,
I am Sudipta Majumder, a Physics Honours student of 6th Semester of the Department
of Physics, Chakdaha College. I have given the exam IIT JAM 2023, conducted by IIT
Guwahati, and have already been selected for 2 years Joint M.Sc.-Ph.D. programme at IIT
Kharagpur. The Registration date provided by them is 27th July so I have to reach the Campus
before the day they mentioned and the classes will start following the process. But the problem
is the University of Kalyani has decided to conduct the practical exams for the 6th Semester
from 1st to 5th August. So, this situation is too problematic for me to manage my studies. There
are many students like me in other subjects and colleges under Kalyani University who have
been suffering from the same problem.
It will be our pleasure if the University of Kalyani looks into this matter and kindly
conduct the practical exam in advance or provide some other solution to our problems on
our behalf.
Thanking you with anticipation.

-Yours faithfully,
Sudipta Majumder,
Physics Hons student of Chakdaha College,
Contact No. - 9883429797

You might also like