Sei sulla pagina 1di 16

MAPÚA INSTITUTE OF TECHNOLOGY

SCHOOL OF EE-ECE-CoE
INTRAMUROS, MANILA

SIGNALS SPECTRA, AND SIGNAL PROCESSING


LABORATORY
Module No.: __5__
Programming in MATLAB

October 14, 2020 _ October 14, 2020


DATE PERFORMED D A T E SU B M I T T E D

Name: Nagayo, Paolo Manuel A.


Course/Sec: ECE107L/B4
Grade
1. Create a program that will perform the following:
a. Ask the user the following inputs: filter order (N), cut-off frequency (fc), and
sampling frequency (fs).
b. Check if N is from 1 to 10, if satisfied, generate the BUTTERWORTH low-pass filter
frequency response and show the pole-zero plot.

MATLAB Output:
Enter Value of Filter Order (N): 8
Enter Value of Cut-off Frequency (Fc): 500
Enter Value of Sampling Frequency (Fs): 5000
Screenshot:
c. Check if N is from 11 to 20, if satisfied, generate the CHEBYCHEV TYPE 1 low-pass
filter frequency response and show the pole-zero plot with pass-band ripple of 0.1
dB.

MATLAB Output:
Enter Value of Filter Order (N): 17
Enter Value of Cut-off Frequency (Fc): 500
Enter Value of Sampling Frequency (Fs): 5000
Screenshot:
d. Check if N is from 21 to 30, if satisfied, generate the CHEBYCHEV Type 2 high-pass
filter frequency response and show the pole-zero plot with stop-band ripple at -
60dN.

MATLAB Output:
Enter Value of Filter Order (N): 22
Enter Value of Cut-off Frequency (Fc): 1000
Enter Value of Sampling Frequency (Fs): 5000
Screenshot:
e. Check if N is from 31 to 40, if satisfied ask for second cut-off frequency and
generate the CEBCHEV TYPE 2 band-pass filter frequency response and the pole-
zero plots with stop-band ripple at -50dB.

MATLAB Output:
Enter Value of Filter Order (N): 39
Enter Value of Cut-off Frequency (Fc): 500
Enter Value of Sampling Frequency (Fs): 5000
Second Cut-off Frequency: 1500
Screenshot:
f. Check if N is from 41 to 50, if satisfied ask for second cut-off frequency and
generate the ELLIPTIC band-stop filter frequency response and the pole-zero plots.
Assume that pass-band ripple is 0.5 dB and stop-band ripple at -60 dB.

MATLAB Output:
Enter Value of Filter Order (N): 49
Enter Value of Cut-off Frequency (Fc): 2500
Enter Value of Sampling Frequency (Fs): 22000
Second Cut-off Frequency: 9000
Screenshot:
g. Check if N is not within the range mentioned from procedure 1b to 1f and display
error message.

MATLAB Output:
Enter Value of Filter Order (N): 93
Enter Value of Cut-off Frequency (Fc): 500
Enter Value of Sampling Frequency (Fs): 5000
ERROR: The Filter order must be within the range 1<=N<=50

SYNTAX:
disp ('------------Experiment 5: Programming in MATLAB-----------------');
disp ('-----------------Input the following values---------------------');
N = input('Enter Value of Filter Order (N): ');
Fc = input('Enter Value of Cut-off Frequency (Fc): ');
Fs = input('Enter Value of Sampling Frequency (Fs): ');
w = Fc/(Fs/2);
if (0<w)&(w<1) %TO SATISFY THE FIRST CONDITION
%BUTTERWORTH lowpass
if (1<=N)&(N<=10)
[B,A] = butter(N,w,'low');
figure(1); zplane(B,A); figure(2); freqz(B,A);
%CHEBYCHEV TYPE 1 lowpass
elseif (11<=N)&(N<=20)
R=0.1;
[B,A] = cheby1(N,R,w,'low');
figure(1); zplane(B,A); figure(2); freqz(B,A);
%CHEBYCHEV TYPE 2 highpass
elseif (21<=N)&(N<=30)
R=60;
[B,A] = cheby2(N,R,w,'high');
figure(1); zplane(B,A); figure(2); freqz(B,A);
%CHEBYCHEV TYPE 2 bandpass
elseif (31<=N)&(N<=40)
Fc2 = input('Second Cut-off Frequency: ');
w2 = Fc2/(Fs/2);
W = [w w2];
R = 50;
[B,A] = cheby2(N,R,W,'bandpass');
figure(1); zplane(B,A); figure(2); freqz(B,A);
%ELLIPTIC band stop
elseif (41<=N)&(N<=50)
Fc2 = input('Second Cut-off Frequency: ');
w2 = Fc2/(Fs/2);
W = [w w2];
Rp = 0.5;
Rs = 60;
[B,A] = ellip(N,Rp,Rs,W,'stop');
figure(1); zplane(B,A); figure(2); freqz(B,A);
else disp('ERROR: The Filter order must be within the range
1<=N<=50');
end
else disp('ERROR: The normalized frequency must be within the range
0<w<1');
end

2. Create a function file that will perform the following:


a. input argument is a vector of 10 elements (including complex numbers)
b. output arguments are:
- Minimum value of the elements
- Maximum value of the elements
- Sum of all the elements
- Average of the elements
- Product of all the elements
- Real parts of the elements
- Imaginary part s of the elements
- Transpose of the vector
- A variable that must count the number of elements in the vector

Syntax:
function [emin,emax,esum,eave,epro,ereal,eimag,etrans,ecount] =
Nagayo_PaoloExp5Act2(A)
emin = min(A);
emax = max(A);
esum = sum(A);
eave = esum/(length(A));
epro = prod(A);
etrans = transpose(A);
ereal = real(A);
eimag = imag(A);
ecount = length(A);

Computer Response:
>> [a b c d e f g h i]=Nagayo_PaoloExp5Act2([6,13,3,1,7i,14,21,15i,17,19])
a=
1

b=
21

c=
94.0000 +22.0000i

d=
9.4000 + 2.2000i
e=
-2.3332e+09

f=
6 13 3 1 0 14 21 0 17 19

g=
0 0 0 0 7 0 0 15 0 0

h=
6.0000 + 0.0000i
13.0000 + 0.0000i
3.0000 + 0.0000i
1.0000 + 0.0000i
0.0000 + 7.0000i
14.0000 + 0.0000i
21.0000 + 0.0000i
0.0000 +15.0000i
17.0000 + 0.0000i
19.0000 + 0.0000i

i=
10

Questions:
1. What is the difference between a script file and a functions file?
The difference between a script file and a function file is that the script file contains
commands that performs a specific task that the user assigned while the function file
works the same way, however the function return output arguments.

2. What is the importance of creating script files in the course signal spectra and signal
processing?
The importance of creating script files in the course signal spectra and signal processing
is that it easily executes and performs specific commands which are mostly
computational and defining important parts of the said inputs.

Onedrive Link for Matlab Files: https://mymailmapuaedu-


my.sharepoint.com/:f:/g/personal/pmanagayo_mymail_mapua_edu_ph/ElYlRo8it
aZNgTdhSjg8sIsBnaZpjbVVhhE9wy7M6vJ2QQ?e=hskR7o

Potrebbero piacerti anche