Punjabi University, Patiala | Higher Education Institute ...
Matlab PUnjabi University
-
Upload
viney-bansal -
Category
Documents
-
view
222 -
download
0
Transcript of Matlab PUnjabi University
-
8/13/2019 Matlab PUnjabi University
1/20
1 | P a g e
Experiment No.1
Aim:Genration of different waveforms square,sine,triangular ,exponential.
Apparatus: MATLAB Software
Program:
% Square wave
t=0:0.01:10;
x=square (t/2*pi);
% figure
subplot(2,2,1)
plot(t,x);
xlabel('Time in second');
ylabel('Amplitude');
title('Square Wave');
% Sine wave
y=sin(t);
%figure;
subplot(2,2,2)
plot(t,y);
xlabel('Time in second');
ylabel('Amplitude');
title('Sine Wave');
%Traiangular Wave
k=1;
for i=0:pi/2:4*pi
z(k)=sin(i);
-
8/13/2019 Matlab PUnjabi University
2/20
2 | P a g e
k=k+1;
end
subplot(2,2,3)
plot(z);
xlabel('Time in second');
ylabel('Amplitude');
title('Triangular Wave');
%Exponential Function
n=1;
for j=0:0.01:10
e(n)=exp(j);
n=n+1;
end
subplot(2,2,4)
plot(e);
xlabel('Time in second');
ylabel('Amplitude');
title('Exponential Function');
-
8/13/2019 Matlab PUnjabi University
3/20
3 | P a g e
-
8/13/2019 Matlab PUnjabi University
4/20
4 | P a g e
Experiment No.2
AIM:Program for convolution of two sequences [y(n)=x1(n)*x2(n)].
Apparatus: MATLAB Software
Program:
x1=input('enter the first sequence x1(n)=');
x2=input('enter the first sequence x2(n)=');
% starting point of first sequence
nx1=input('enter the range of first sequence [-n:n]=');
% starting point of second sequence
nx2=input('enter the range of second sequence [-n:n]=');
nyb=nx1(1)+nx2(1);
nye=nx1(length(x1))+nx2(length(x2));
ny=[nyb:nye];
y=conv(x1,x2)
stem(ny,y);
Output:
-
8/13/2019 Matlab PUnjabi University
5/20
5 | P a g e
-
8/13/2019 Matlab PUnjabi University
6/20
6 | P a g e
Experiment No.3
AIM:Program to check the performance of linear difference equation.
Apparatus: MATLAB Software
Program:
%This program is used to calculate the output of a system
%which is described by linear difference equation
%Example
%Let the difference equation be
%y(n)-0.9y(n)=x(n)and
%coefficients are b=[1];a=[1,-0.9];
a=input('Enter the coefficient of input x=');
b=input('Enter the coefficient of input y=');
impz(a,b);
title('impulse Response');
xlabel('n');
ylabel('h(n)')
Output:
-
8/13/2019 Matlab PUnjabi University
7/20
7 | P a g e
-
8/13/2019 Matlab PUnjabi University
8/20
8 | P a g e
Experiment No.4
AIM:Compute and plot poles and zeros of Z-transform.
Apparatus: MATLAB Software
Program:
%Z-transform is basically used for checking the system stability and poles and
%zeros characterizes the system performance.User has to give numerator and
%denominator polynomial.
NUM=input(‘input the numerator polynomial:’);
DEN= input(‘input the denominator polynomial:’);
TRANF=tf(NUM,DEN();
[ZEROS POLES GAIN]=tf2zp(NUM,DEN);
%disp(‘poles of transfer function are’);
%disp(Poles)-
%disp(‘Zeros of transfer function are’);
%disp(ZEROS)
%disp(Gain of transfer function is’);
%disp(GAIN)
%zplane(NUM,DEN)
Output:
-
8/13/2019 Matlab PUnjabi University
9/20
9 | P a g e
-
8/13/2019 Matlab PUnjabi University
10/20
10 | P a g e
Experiment No.5
AIM:Program for finding magnitude and phase response of LTI system described by
Transfer function H(z).
Apparatus: MATLAB Software
Program:
LENGTH=input(‘input the length of DFT(For best result in power of 2):’);
THETA=0:pi/LENGTH:pi;
NUM=[0.05 0.033 0.008];
DEN=[0.06 4 1];
TRANSFER=tf(NUM,DEN)
[FREQ,W]=freqz(NUM,DEN,LENGTH);
grid on;
figure(1);
subplot(2,1,1)
k=0.2;
plot(abs(FREQ),’k’);
disp(abs(‘FREQ’));
title(‘Magnitude response’);
xlabel(‘FREQ index’);
ylabel(‘Magnitude’);
grid on;
subplot(2,1,2)
disp(angle(‘FREQ’));
plot(angle(FREQ),’k’);
title(‘Phase response’);
xlabel(‘Frequency index’);
ylabel(‘Phase’);
-
8/13/2019 Matlab PUnjabi University
11/20
11 | P a g e
grid on;
Output:
-
8/13/2019 Matlab PUnjabi University
12/20
12 | P a g e
Experiment No.6
AIM:Find the N point circular or linear convolution using circular convolution of the ginen two
Sequences.
Apparatus: MATLAB Software
Program:
%Circular convolution of given two sequences given by user.
%Convolution in time domain is simple multiplication in frequency domain
A_FIRST=input('Enter the elements of first sequence=');
B_FIRST=input('Enter the elements of Second sequence=');
LENGTH=length(A_FIRST);
FFT_A_FIRST=fft(A_FIRST);
FFT_B_FIRST=fft(B_FIRST);
TEMP1(1)=B_FIRST(1);
for i=2:LENGTH
TEMP1(i)=B_FIRST(LENGTH+2-i);
end
%CIRCULAR CONVOLUTION
for i=1:LENGTH
sum=0;
for j=1:LENGTH
sum=sum+A_FIRST(j)*TEMP1(j);
end
conv(i)=sum;
TEMP2(1)=TEMP1(LENGTH);
for k=2:LENGTH
TEMP2(k)=TEMP1(k-1);
-
8/13/2019 Matlab PUnjabi University
13/20
13 | P a g e
end
TEMP1=TEMP2;
end
disp('Convolved sequence1s:');
disp(conv);
figure(1)
subplot(3,1,1)
stem(A_FIRST,'k');
title('First input sequence');
subplot(3,1,2)
stem(B_FIRST,'k');
title('second input sequence');
subplot(3,1,3)
stem(conv,'k');
title('Convolved sequence');
Output:
-
8/13/2019 Matlab PUnjabi University
14/20
14 | P a g e
-
8/13/2019 Matlab PUnjabi University
15/20
15 | P a g e
Experiment No.7
AIM: Program for designing an IIR Filter .
Apparatus: MATLAB Software
Program:
% This program Take the Digital filter specification
% wp digital passband frequency
% ws digital stop band frequency,Rp Passband ripple
% As Stopband attenuation
% Example:wp=0.2*pi;ws=0.3*pi;
% Rp=1;As=15;
wp=input('Enter the digital passband frequency');
ws=input('Enter the digital stopband frequency');
Rp=input('Enter the passband ripple');
As=input('Enter the stop band attenuation');
T=1;
Omegap=(2/T)*tan(wp/2); %prewarp Prototype Passband freq.
Omegas=(2/T)*tan(ws/2); %prewarp Prototype Passband freq.
% Analog Prototype Calculation
N=ceil((log10((10^(Rp/10)-1)/(10^(As/10)-1)))/(2*log10(Omegap/Omegas)));
% fprint('Butterworth filter order=%2.0f/',N);
OmegaC=Omegap/((10^(Rp/10)-1)^(1/(2*N)));
% analog BW prototype cutoff
wn=2*atan((OmegaC*T)/2);
% Digital filter design
-
8/13/2019 Matlab PUnjabi University
16/20
16 | P a g e
wn=wn/pi %Digital Butter cutoff in pi
[b,a]=butter(N,wn);
Output:
-
8/13/2019 Matlab PUnjabi University
17/20
17 | P a g e
Experiment No.8
AIM: Program for designing an low- pass FIR Filter .
Apparatus: MATLAB Software
Program:
% Windows:a.Hamming window.
% b.hanning window.
% The FIR filters are designed with the window functions which are the'
% empirical formulae.
% The simple example of the filter is simulated using 'SINC' function.
% The filter coefficient are calculated for respective window function i.e.
% W(n).Then point-wise multiplication of H(n)and W(n) will give Fitered response,user can
see the difference is clear from the graphical diagram itself.
N=input('Input order of the filter:');%ORDER of filter.
% TRANSFER FUNCTION EVALUATION.
THETA=-pi:(2*pi/(N-1)):pi;
Hn=sinc(THETA);
disp('Original sequence is');
disp(Hn);
% HANNING RESPONSE.
Wn_HANN=hanning(N);
disp('Filter coefficients with Hanning window are');
disp(Wn_HANN);
FILTER_RESP_HANN=(Hn').*Wn_HANN;
-
8/13/2019 Matlab PUnjabi University
18/20
18 | P a g e
disp('Filtered response with Hanning window is:');
disp(FILTER_RESP_HANN);
figure(1);
subplot(2,1,1);
plot(Hn,'k');
title('Original sequence');
subplot(2,1,2);
plot(FILTER_RESP_HANN,'k');
title('Filtered response with Hanning window');
% HAMMING RESPONSE.
Wn_HAMM=hamming(N);
disp('Filter coefficients with Hamming window are');
disp(Wn_HAMM);
FILTER_RESP_HAMM=(Hn').*Wn_HAMM;
disp('Filtered response with Hamming window is:');
disp(FILTER_RESP_HAMM);
figure(2);
subplot(2,1,1);
plot(Hn,'k');
title('Original sequence');
subplot(2,1,2);
plot(FILTER_RESP_HAMM,'k');
title('Filtered response with Hamming window');
Output:
-
8/13/2019 Matlab PUnjabi University
19/20
19 | P a g e
-
8/13/2019 Matlab PUnjabi University
20/20
20 | P a g e