Program 1 Aim
Program 1 Aim
Program 1 Aim
AIM:
What Is MATLAB
Basics of Matlab:
Matlab windows:
(C) WORKSHOP: This sub window lists all variable that you have generated so far
and shows their type and size.
(D) COMAND HISTORY: All command typed on MATLAB prompt in the command
window get recorded in this window.
2.FIGURE WINDOW :the output of all graphics command typed in the command
window are flushed to the graphics or the figure window , a separate gray window with
(default) white back ground color
3. EDITOR WINDOW:
This is where user writes, edit, create and save his program in program files called m
files
User can use any text editor to carry out these tasks
FILETYPES;
Matlab can read and write several types of files .here mainly 5 types of files for storing
data and programs
1. MFILES: These standards ASCII. Text files ,with ,m extension to the files name
2. MAT files: These are binary data files with .MAT extension to the file name, mat
file are created by mat lab where user save command
3. FIG- these are binary figure files with .fig extension that can be opened again as
figures
4. PFILES; these are compiled m files with .p extension that can be executed in
matlab directory these files are created with pcode command.
5. MEX-FILES; these are matlab capable FORTAN & C program with .mex
extension to the files names
COMMANDS IN MATLAB:
SUBPLOT: Subplot divides the current figure into rectangular panes that are numbered
row wise. Each pane contains an axes. Subsequent plots are output to the current
pane. Subplot (m,n,p) creates an axes in the pth pane of a figure divided into an m-by-n
matrix of rectangular panes. The new axes becomes the current axes. If p is a vector, it
specifies an axes having a position that covers all the subplot positions listed in p.
subplot(m,n,p,'replace') If the specified axes already exists, delete it and create a new
axes. subplot(m,n,p,'align') positions the individual axes so that the plot boxes align, but
does not prevent the labels and ticks from overlapping. subplot(h) makes the axes with
handle h current for subsequent plotting commands. subplot('Position',[left bottom width
height]) creates an axes at the position specified by a four-element vector. left, bottom,
width, and height are in normalized coordinates in the range from 0.0 to 1.0. h =
subplot(...) returns the handle to the new axes.
DISP: disp(X) displays an array, without printing the array name. If X contains a text
string, the string is displayed. Another way to display an array on the screen is to type
its name, but this prints a leading "X =," which is not always desirable. Note that disp
does not display empty arrays.
STEM: A two-dimensional stem plot displays data as lines extending from a baseline
along the x-axis. A circle (the default) or other marker whose y-position represents the
data value terminates each stem. stem(Y) plots the data sequence Y as stems that
extend from equally spaced and automatically generated values along the x-axis. When
Y is a matrix, stem plots all elements in a row against the same x value.
CLC: clc clears all input and output from the Command Window display, giving you a
"clean screen." After using clc, you cannot use the scroll bar to see the history of
functions, but you still can use the up arrow to recall statements from the command
history.
EXP: The exp function is an elementary function that operates element-wise on arrays.
Its domain includes complex numbers
PLOT: plot(Y) plots the columns of Y versus their index if Y is a real number. If Y is
complex, plot(Y) is equivalent to plot(real(Y),imag(Y)). In all other uses of plot, the
imaginary component is ignored. plot(X1,Y1,...) plots all lines defined by Xn versus Yn
pairs. If only Xn or Yn is a matrix, the vector is plotted versus the rows or columns of the
matrix, depending on whether the vector's row or column dimension matches the matrix.
% impulse function %
clc;
clear all;
a=input('enter the range');
t=-a:1:a;
y=[zeros(1,a),ones(1),zeros(1,a)];
subplot(3,3,1);
stem(t,y);
xlabel('time');
ylabel('amplitude');
% unit function %
clc;
clear all;
a=input('enter the range');
t=-a:1:a;
y=[zeros(1,a),ones(1,a+1)];
subplot(3,3,3);
stem(t,y);
xlabel('time');
ylabel('amplitude');
% sinusodial function %
clc;
clear all;
t=0:pi/10:2*pi;
y=sin(t);
subplot(3,3,7);
plot(t,y);
set(gca,'xtick',0:pi:2*pi);
set(gca,'XTickLabel',{'0','pi','2pi'})
xlabel('time');
ylabel('amplitude');
%exponentialfunction%
a=input('enter the value of a');
n2=input('enter the value of n2');
t=0:1:n2-1;
y=exp(a*t);
subplot(3,3,9);
stem(t,y);
title('exponential function')
xlabel('time');
ylabel('amplitude');
INPUT:-
subplot(1,3,1);
stem(x);
title('first sequence');
xlabel('time');
ylabel('amplitude');
subplot(1,3,2);
stem(h);
title('second sequence');
xlabel('time');
ylabel('amplitude');
subplot(1,3,3);
stem(y);
title('convolution sequence');
xlabel('time');
ylabel('amplitude');
INPUT::
enter the first sequece[1 2 3 4 5]
enter the second sequence[1 2 3 4 5]
output sequence
1 4 10 20 35 44 46 40 25
OUTPUT PLOTS:
PROGRAM 4
AIM:
%crosscorelation%
clc;
x=input('enter the first sequence');
h=input('enter the second sequence');
y=xcorr(x,h);
disp('output sequence');
disp(y);
subplot(3,1,1);
stem(x);
title('first sequence');
xlabel('time');
ylabel('amplitude');
subplot(3,1,2);
stem(h);
title('second sequence');
xlabel('time');
ylabel('amplitude');
subplot(3,1,3);
stem(y);
title('crosscorelation sequence');
xlabel('time');
ylabel('amplitude');
INPUTS::
enter the first sequence[1 2 3 4 5]
enter the second sequence[2 4 6 8 10]
output sequence
10.0000 28.0000 52.0000 80.0000 110.0000 80.0000 52.0000 28.0000
10.0000
OUTPUT PLOTS:
PROGRAM 5
AIM:
%auto correlation%
clc;
x=input('enter the first sequence');
y=xcorr(x,x);
disp('output sequence');
disp(y);
subplot(3,1,1);
stem(x);
title('input sequence');
xlabel('time');
ylabel('amplitude');
subplot(3,1,2);
stem(y);
title('autocorrelation sequence');
xlabel('time');
ylabel('amplitude');
INPUTS::
enter the first sequence[3 2 1 4 5]
output sequence
15.0000 22.0000 16.0000 32.0000 55.0000 32.0000 16.0000 22.0000
15.0000
OUTPUT PLOTS:
PROGRAM 6
AIM:
%buterworth low pass filter%
clc;
rp=input('enter the passband ripple');
rs=input('enter the stopband ripple');
wp=input('enter the passband frequency');
ws=input('enter the stopband freq');
fs=input('enter the sampling band freq');
w1=2*wp/fs;
w2=2*ws/fs;
[n,wn]=buttord(w1,w2,rp,rs);
[b,a]=butter(n,wn,'low');
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);
title('response of buterworth low passfiler');
ylabel('gain in DB');
xlabel('normalized freq');
subplot(2,1,2);
plot(om/pi,an);
xlabel('normalized angle');
ylabel('phase in radians');
INPUTS::
enter the passband ripple0.15
enter the stopband ripple60
enter the passband frequency1500
enter the stopband freq3000
enter the sampling band freq7000
OUTPUT PLOTS:
PROGRAM 7
AIM:
%buterworth high pass filter%
clc;
rp=input('enter the passband ripple');
rs=input('enter the stopband ripple');
wp=input('enter the passband frequency');
ws=input('enter the stopband freq');
fs=input('enter the sampling band freq');
w1=2*wp/fs;
w2=2*ws/fs;
[n,wn]=buttord(w1,w2,rp,rs);
[b,a]=butter(n,wn,'high');
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);
title('response of buterworth high passfilter');
ylabel('gain in DB');
xlabel('normalized freq');
subplot(2,1,2);
plot(om/pi,an);
xlabel('normalized angle');
ylabel('phase in radians');
INPUT::
enter the passband ripple0.2
enter the stopband ripple40
enter the passband frequency2000
enter the stopband freq3500
enter the sampling band freq8000
OUTPUT PLOTS:
PROGRAM 8
AIM:
%FFT%
clc;
x=input('enter the sequence');
n=input('enter the length of fft');
y=fft(x,n);
stem(y,x);
ylabel('imaginary axis---->');
xlabel('real axix----->');
INPUT::
enter the sequence[0 1 2 3 4 5 6 7]
enter the length of fft 8
OUTPUT::
PROGRAM 9
AIM: write a program for the real and complex exponential sequences.
n=0:1:N;
y=k*(a.^n);
subplot(3,1,1);
stem(n,y);
xlabel('time');
ylabel('amplitude');
n1=0:1:N1;
c=a1+b1*j;
x=p*(c.^n1);
subplot(3,1,2);
stem(n1,real(x));
xlabel('time');
ylabel('amplitude');
subplot(3,1,3);
stem(n1,imag(x));
xlabel('time');
ylabel('amplitude');
disp('result is');
disp(x);
INPUT::
enter the value of gain,k:2
enter the value of a,a:2
enter the value of N:7
enter the value of gain,p:1
enter the value of real part,a1:3
enter the value of imaginary part,b1:2
enter the value of N14
result is
1.0e+002 *
OUTPUT PLOT:
PROGRAM 10:
AIM: write a program to design chebyshev low pass filter.
w1=2*wp/fs;
w2=2*ws/fs;
[n,wn]=cheb1ord(w1,w2,rp,rs);
[b,a]=cheby1(n,rp,wn);
w=0:.01:pi;
[h,om]=freqs(b,a,w);
m=20*log10(abs(h));
an=angle(h);
subplot(2,1,1);
plot(om/pi,m);
title('response of chebyshev low passfiler');
ylabel('gain in DB');
xlabel('normalized freq');
subplot(2,1,2);
plot(om/pi,an);
xlabel('normalized angle');
ylabel('phase in radians');
INPUTS::
OUTPUT PLOT:
PROGRAM 11
AIM; Write a program to define a function to compute dtft of finite length signal. Plot the
magnitude and phase plots using sub plots.Use this function to obtain dtft of a 21 point
Triangular pulse over the domain -10<n<10.plot the result over -pi<w<pi using MATLAB.
Step1(function):-
%function[magx,angx,k,]=dtftf(n,x);
k=-500:500;
w=(pi/500)*k;
X=x*(exp(-j*pi/500)).^(n'*k);
magX=abs(X);
angX=angle(X);
n=[-10:10];
x=n;
%[magX,angX,k]=dtftf(n,x);
subplot(2,1,1);
plot(k/500,magX);
xlabel('frequency');
ylabel('magnitude');
subplot(2,1,2);
plot(k/500,angX);
xlabel('frequency');
ylabel('angle');
OUTPUT PLOTS:-