Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
Lab Manual
of
MATLAB
SSSIST Sehore
List of Experiment
1. Study of MATLAB 7.0
5. Program
6. To implement a causal IIR filter implemented in the Direct Form II structure, the function direct2 given below can be employed. 7. To implement a causal IIR filter implemented in the Direct Form II structure, the function direct2 given below can be employed 8. Program illustrates the design of a causal IIR filter, its simulation in transposed Direct Form II, and its application in filtering a signal. 9. Program up-sampler. 10. Illustration of Down-Sampling by an Integer Factor 11. Use fir2 to create a bandlimited input sequence 12. Program P10 4 can be employed to study the frequency-domain properties of the downsampler 13. FIR filter using Rectangular Window 14. FIR filter using Hamming Window
15. Circular Convolution of two sequences using MATLAB
SSSIST Sehore
Experiment No. 1
Program for Linear Convolution clc; clear all; close all; x=input('ENTER THE FIRST SEQUENCE '); h=input('ENTER THE SECOND SEQUENCE '); y=conv(x,h); stem(y); xlabel('Amplitude---->'); ylabel('time----->'); title('LINEAR CONVOLUTION');
SSSIST Sehore
Experiment No. 2
Program for the design of a Butterworth band stop filter. % Program P7_1 % Design of a Butterworth Bandstop Digital Filter Ws = [0.4 0.6]; Wp = [0.3 0.7]; Rp = 0.4; Rs = 50; % Estimate the Filter Order [N1, Wn1] = buttord(Wp, Ws, Rp, Rs); % Design the Filter [num,den] = butter(N1,Wn1,stop); % Display the transfer function disp(Numerator coefficients are );disp(num); disp(Denominator coefficients are );disp(den); % Compute the gain response [g,w] = gain(num,den); % Plot the gain response plot(w/pi,g);grid axis([0 1 -60 5]); xlabel(\omega /\pi); ylabel(Gain, dB); title(Gain Response of a Butterworth Bandstop Filter);
SSSIST Sehore
Experiment No. 3
Program for implement a causal IIR filter implemented in the Direct Form II structure, the function direct2 given below can be employed.
function [y,sf] = direct2(p,d,x,si); % Y = DIRECT2(P,D,X) filters input data vector X with % the filter described by vectors P and D to create the % filtered data Y. The filter is a "Direct Form II" % implementation of the difference equation: % y(n) = p(1)*x(n) + p(2)*x(n-1) + ... + p(np+1)*x(n-np) % - d(2)*y(n-1) - ... - d(nd+1)*y(n-nd) % [Y,SF] = DIRECT2(P,D,X,SI) gives access to initial and % final conditions, SI and SF, of the delays. dlen = length(d); plen = length(p); N = max(dlen,plen); M = length(x); sf = zeros(1,N-1); y = zeros(1,M); if nargin ~= 3, sf = si; end if dlen < plen, d = [d zeros(1,plen - dlen)]; else p = [p zeros(1, dlen - plen)]; end p = p/d(1); d = d/d(1); for n = 1:M; wnew = [1 -d(2:N)]*[x(n) sf]; K = [wnew sf]; y(n) = K*p; sf = [wnew sf(1:N-2)]; end
SSSIST Sehore
Experiment No. 4
Program to the design of a causal IIR filter, its simulation in transposed Direct Form II, and its application in filtering a signal. % Program P8_3 % Illustration of Filtering by an IIR Filter clf; % Generate the input sequence k = 0:50; w2 = 0.7*pi;w1 = 0.2*pi; x1 = 1.5*cos(w1*k); x2 = 2*cos(w2*k); x = x1+x2; % Determine the filter transfer function [N, Wn] = ellipord(0.25, 0.55, 0.5, 50); [num, den] = ellip(N,0.5, 50,Wn); % Generate the output sequence y = filter(num,den,x); % Plot the input and the output sequences subplot(2,1,1); stem(k,x); axis([0 50 -4 4]); xlabel(Time index n); ylabel(Amplitude); title(Input Sequence); subplot(2,1,2); stem(k,y); axis([0 50 -4 4]); xlabel(Time index n); ylabel(Amplitude); title(Output Sequence);
SSSIST Sehore
Experiment No. 5
Program for design of up-sampler % Illustration of Up-Sampling by an Integer Factor clf; n = 0:50; x = sin(2*pi*0.12*n); y = zeros(1, 3*length(x)); y([1: 3: length(y)]) = x; subplot(2,1,1) stem(n,x); title(Input Sequence); xlabel(Time index n);ylabel(Amplitude); subplot(2,1,2) stem(n,y(1:length(x))); title(Output Sequence); xlabel(Time index n);ylabel(Amplitude);
SSSIST Sehore
Experiment No. 6
Program to Down-Sampling by an Integer Factor clf; n = 0: 49; m = 0: 50*3 - 1; x = sin(2*pi*0.042*m); y = x([1: 3: length(x)]); subplot(2,1,1) stem(n, x(1:50)); axis([0 50 -1.2 1.2]); title(Input Sequence); xlabel(Time index n); ylabel(Amplitude); subplot(2,1,2) stem(n, y); axis([0 50 -1.2 1.2]); title(Output Sequence); xlabel(Time index n); ylabel(Amplitude);
SSSIST Sehore
Experiment No. 7
Program to use fir2 to create a band limited input sequence clf; freq = [0 0.45 0.5 1]; mag = [0 1 0 0]; x = fir2(99, freq, mag); % Evaluate and plot the input spectrum [Xz, w] = freqz(x, 1, 512, whole); subplot(2,1,1); plot(w/pi, abs(Xz)); axis([0 1 0 1]); grid xlabel(\omega/\pi); ylabel(Magnitude); title(Input Spectrum); subplot(2,1,2); % Generate the up-sampled sequence L = input(Type in the up-sampling factor = ); y = zeros(1, L*length(x)); y([1: L: length(y)]) = x; % Evaluate and plot the output spectrum [Yz, w] = freqz(y, 1, 512, whole); plot(w/pi, abs(Yz)); axis([0 1 0 1]); grid xlabel(\omega/\pi); ylabel(Magnitude); title(Output Spectrum);
SSSIST Sehore
Experiment No. 8
Program to study the frequency-domain properties of the down sampler % Program P10_4 % Effect of Down-sampling in the Frequency Domain % Use fir2 to create a bandlimited input sequence clf; freq = [0 0.42 0.48 1]; mag = [0 1 0 0]; x = fir2(101, freq, mag); % Evaluate and plot the input spectrum [Xz, w] = freqz(x, 1, 512); subplot(2,1,1); plot(w/pi, abs(Xz)); grid xlabel(\omega/\pi); ylabel(Magnitude); title(Input Spectrum); % Generate the down-sampled sequence M = input(Type in the down-sampling factor = ); y = x([1: M: length(x)]); % Evaluate and plot the output spectrum [Yz, w] = freqz(y, 1, 512); subplot(2,1,2); plot(w/pi, abs(Yz)); grid xlabel(\omega/\pi); ylabel(Magnitude); title(Output Spectrum);
SSSIST Sehore
Experiment No. 9
Program to design of FIR filter using Rectangular Window clc; close all; clear all; rp=input('enter the passband ripple'); rs=input('enter the stopband ripple'); fp=input('enter the passband ripple'); fs=input('enter the stopband ripple'); f=input('enter the sampling frequency'); wp=2*fp/f; ws=2*fs/f; num=-20*log10(sqrt(rs*rp))-13; dem=14.6*(fs-fp)/f; n=ceil(num/dem); if(rem(n,2)~=0) n=n1; n=n-1; end y=RECTWIN(n1); %bandpass filter wn=[wp ws]; b=fir1(n,wn,y); [h,o]=freqz(b,1,256); m=20*log10*(abs(h)); an=angle(h); subplot(2,1,1); plot(o/pi,m); xlabel('normalised freq-->'); ylabel('gain in db-->'); subplot(2,1,2); plot(0/pi,an); xlabel('normalised freq-->'); ylabel('phase in radians-->');
SSSIST Sehore
Experiment No. 10
Program to design of FIR filter using Hamming Window clc; clear all; close all rp=input('enter the passband ripple'); rs=input('enter the stopband ripple'); fp=input('enter the passband freq'); fs=input('enter the stopband freq'); f=input('enter the sampling freq'); wp=2*fp/f;ws=2*fs/f; num=-20*log10(sqrt(rp*rs))-13; dem=14.6*(fs-fp)/f; n=ceil(num/dem); n1=n+1; if(rem(n,2)~=0); n1=n; n=n-1; end y=hamming(n1); %LOW -PASS FILTER b=fir1(n,wp,y); [h,o]=freqz(b,1,256); m=20*log10(abs(h)); subplot(2,2,1);plot(o/pi,m); ylabel('gain in db-->'); xlabel('(a)normalised frequency-->'); title('LOW-PASS FILTER'); %BAND PASS FILTER wn=[wp ws]; b=fir1(n,wn,y); [h,o]=freqz(b,1,256); m=20*log10(abs(h)); subplot(2,2,3);plot(o/pi,m); ylabel('gain in db-->'); xlabel('(c)normalised frequency-->'); title('BAND PASS FILTER');
SSSIST Sehore
Experiment No. 11
Program to design of Circular Convolution clc; clear all; close all; g=input('1 sequence'); h=input('2 sequence'); N1=length(g); N2=length(h); N=max(N1,N2); N3=N1-N2; if(N3>=0) h=[h,zeros(1,N3)]; else g=[g,zeros(1,-N3)]; end for n=1:N y(n)=0; for i=1:N j=n-i+1; if(j<=0) j=N+j; end end y(n)=[y(n)+g(i)*h(j)]; stem(y) end
SSSIST Sehore
Experiment No. 12
Program to design of IIR filter design clc; close all; clear all; rp=input('enter the pass band ripple'); rs=input('enter the stop band ripple'); wp=input('enter the pass band freq'); ws=input('enter the stop band freq'); fs=input('enter the sampling feq'); w1=2*wp/fs; w2=2*ws/fs; [h,wn]=buttord(w1,w2,rp,rs); [b,a]=butter(h,wn); w=0:.01:pi; [h,om]=freqz(b,a,w); m=20*log10(abs(h)); an=angle(h); subplot(2,1,1); plot(om/pi,m); ylabel('gain in db....>'); xlabel('(a) normalised frequency>'); subplot(2,1,2); plot(om/pi,an); xlabel('(b) normalised frequency'); ylabel('phase in radian');
SSSIST Sehore
Experiment No. 13
Program to design of Analog to Digital Converter function beq = a2dT(d,n) % BEQ = A2DT(D, N) generates the decimal % equivalent BEQ of the binary representation % of a vector D of decimal numbers with N bits % for the magnitude part obtained by truncation % m = 1; d1 = abs(d); while fix(d1) > 0 d1 = abs(d)/(10^m); m = m+1; end beq = 0; for k = 1:n beq = fix(d1*2)/(2^k) + beq; d1 = (d1*2) - fix(d1*2); end beq = sign(d).*beq*10^(m-1);