Practical No.1 Aim:-To Study Basic Concepts of MATLAB. Theory
Practical No.1 Aim:-To Study Basic Concepts of MATLAB. Theory
Theory:-
2.The Desktop
When you start MATLAB, the desktop appears, containing tools (graphical user
interfaces) for managing files, variables, and applications associated with MATLAB. The
following illustration shows the default desktop. You can customize the arrangement of
tools and documents to suit your needs. For more information about the desktop tools, see
Desktop Tools and Development Environment.
3.Quitting the MATLAB Program
To end your MATLAB session, select File > Exit MATLAB in the desktop, or
type quit in the Command Window. You can run a script file named finish.m
each time MATLAB quits that, for example, executes functions to save the
workspace.
Confirm Quitting
MATLAB can display a confirmation dialog box before quitting. To set this
option, select File > Preferences > General > Confirmation Dialogs, and
select the check box for Confirm before exiting MATLAB.
Theory: A continuous-time signal x(t) is said to be periodic with period T if it satisfy the
condition
x (t+T) = x(t) for all t -∞<t<+∞ ………….eq1
A signal is periodic if the above condition is not satisfied for at least one value of T.
The smallest value of T that satisfies the above condition is known as fundamental period.
Complex exponential and sinusoidal signals are examples for continuous-time periodic signals.
Consider a sinusoidal signal
x(t)=Asin(wt+θ) ……………………eq2
Where A is tha amplitude, w is tha frequency in radians per second (rad/sec), and θ the phase in
radians. The frequency f0 in hertz is given by f0 = w /2π or periodic signal we have
X(t+T)=x(t) ………………eq3
For x(t)=Asin(wt+θ) ………………eq4
X (t+T) = Asin [w(t+T)+ θ)]
Equation 5 and 2 are equal if
wT = 2π , T =2π/ w
Thu the sinusoidal is periodic with period 2π/ w The sum of two periodic signals x1(t) and x2(t)
with periods T1 and T2 respectively may or may not be periodic, then the ratio T1/T2 can be
written as the ratio a/b of two integers a and b. If T1/T2 = a/b, then bT1 = aT2, and since a and b
are integers, x1(t) and x2(t) are periodic with period bT1. If a and b are co prime (i. e. a and b
have no common integer factors other than 1) then T = bT1 is the fundamental period of the sum
of two signals.
Program:
Unit:
n=input ('Enter the length of the step sequence N='); % Get the length of the require
sequence from the user
t=0:n-1; % defines the time axis
y=ones(1,n); % defines an 1 x n matrix which is filled with ones
stem(t,y); %displays the data as lines
ylabel ('Amplitude'); % name the Y axis
xlabel ('Time Index'); %Name the x axis
TITLE ('Unit Step Signal'); % Giving the title for the plot.
Output:
Theory:
Convolution is a formal mathematical operation, just as multiplication, addition, and integration.
Addition takes two numbers and produces a third number, while convolution takes two signals
and produces a third signal. Convolution is used in the mathematics of many fields, such as
probability and statistics. In linear systems, convolution is used to describe the relationship
between three signals of interest: the input signal, the impulse response, and the output signal.
In this equation, x1(k), x2(n-k) and y(n) represent the input to and output from the system at time
n. Here we could see that one of the input is shifted in time by a value every time it is multiplied
with the other input signal. Linear Convolution is quite often used as a method of implementing
filters of various types.
Program:
clc;
clear all;
close all;
disp('linear convolution program');
x=[x,zeros(1,n)];
subplot(2,2,1), stem(x);
title('i/p sequencce x(n)is:');
xlabel('---->n');
ylabel('---->x(n)');grid;
h=[h,zeros(1,m)];
subplot(2,2,2), stem(h);
title('i/p sequencce h(n)is:');
xlabel('---->n');
ylabel('---->h(n)');grid;
disp('convolution of x(n) & h(n) is y(n):');
y=zeros(1,m+n-1);
for i=1:m+n-1
y(i)=0;
for j=1:m+n-1
if(j<i+1)
y(i)=y(i)+x(j)*h(i-j+1);
end
end
end y
subplot(2,2,[3,4]),stem(y);
title('convolution of x(n) & h(n) is :');
xlabel('---->n');
ylabel('---->y(n)');grid;
Output:
Equipment required:
Theory: Circular convolution is another way of finding the convolution sum of two input
signals. It resembles the linear convolution, except that the sample values of one of the input
signals is folded and right shifted before the convolution sum is found. Also note that circular
convolution could also be found by taking the DFT of the two input signals and finding the
product of the two frequency domain signals. The Inverse DFT of the product would give the
output of the signal in the time domain which is the circular convolution output. The two input
signals could have been of varying sample lengths. But we take the DFT of higher point, which
ever signals levels to. For example, if one of the signal is of length 256 and the other spans 51
samples, then we could only take 256-point DFT. So the output of IDFT would be containing
256 samples instead of 306 samples, which follows N1+N2 – 1 where N1 & N2 are the lengths
256 and 51 respectively of the two inputs. Thus the output which should have been 306 samples
long is fitted into 256 samples. The256 points end up being a distorted version of the correct
signal. This process is called circular convolution.
Program:
clc;
clear all;
close all;
m=length(x);
n=length(h);
subplot(2,2,1), stem(x);
xlabel('---->n');
ylabel('---->x(n)');
grid;
subplot(2,2,2), stem(h);
xlabel('---->n');
ylabel('---->h(n)');
grid;
if(m-n~=0)
if(m>n)
h=[h,zeros(1,m-n)];
n=m;
end
x=[x,zeros(1,n-m)];
m=n;
end
y=zeros(1,n);
y(1)=0;
a(1)=h(1);
for j=2:n
a(j)=h(n-j+2);
end
%circular convolution
for i=1:n
y(1)=y(1)+x(i)*a(i);
end
for k=2:n
y(k)=0;
% circular shift
for j=2:n
x2(j)=a(j-1);
end
x2(1)=a(n);
for i=1:n
if(i<n+1)
a(i)=x2(i);
y(k)=y(k)+x(i)*a(i);
end
end
end
y subplot(2,2,[3,4]),stem(y);
xlabel('---->n');
ylabel('---->y(n)'); grid;
OUTPUT:
Theory:
In mathematics, the discrete Fourier transform (DFT) converts a finite sequence of equally-
spaced samples of a function into a same-length sequence of equally-spaced samples of the
discrete-time Fourier transform (DTFT), which is a complex-valued function of frequency. The
interval at which the DTFT is sampled is the reciprocal of the duration of the input sequence. An
inverse DFT is a Fourier series, using the DTFT samples as coefficients of complex sinusoids at
the corresponding DTFT frequencies. It has the same sample-values as the original input
sequence. The DFT is therefore said to be a frequency domain representation of the original
input sequence. If the original sequence spans all the non-zero values of a function, its DTFT is
continuous (and periodic), and the DFT provides discrete samples of one cycle. If the original
sequence is one cycle of a periodic function, the DFT provides all the non-zero values of one
DTFT cycle.
The DFT is the most important discrete transform, used to perform Fourier analysis in many
practical applications.[1] In digital signal processing, the function is any quantity or signal that
varies over time, such as the pressure of a sound wave, a radio signal, or daily temperature
readings, sampled over a finite time interval (often defined by a window function). In image
processing, the samples can be the values of pixels along a row or column of a raster image. The
DFT is also used to efficiently solve partial differential equations, and to perform other
operations such as convolutions or multiplying large integers.
Since it deals with a finite amount of data, it can be implemented in computersby numerical
algorithms or even dedicated hardware. These implementations usually employ efficient fast
Fourier transform (FFT) algorithms; so much so that the terms "FFT" and "DFT" are often used
interchangeably. Prior to its current usage, the "FFT" initialism may have also been used for the
ambiguous term "finite Fourier transform".
Program:
Output:
X=
8.0000 + 0.0000i
3.0000 + 1.0000i
-6.0000 - 0.0000i3.0000 - 1.0000i
ans =
0
0.3218
-3.1416
-0.3218
function [Rxx]=autom(x)
% [Rxx]=autom(x)
% This function Estimates the autocorrelation of the sequence
of
% random variables given in x as: Rxx(1), Rxx(2),…,Rxx(N),
where N is
% Number of samples in x.
N=length(x);
Rxx=zeros(1,N);
for m=1: N+1
for n=1: N-m+1
Rxx(m)=Rxx(m)+x(n)*x(n+m-1);
end;
end;
To use the above function, you need to save this under autom.m and then it may be
used as follows:
N=1024;
f1=1;
FS=200;
n=0:N-1;
x=sin(2*pi*f1*n/FS);
t=[1:N]*(1/FS);
subplot(2,1,1);
plot(t,x);
title('Sinwave of frequency 1000Hz [FS=8000Hz]');
xlabel('Time, [s]');
ylabel('Amplitude');
grid;
Rxx=autom(x);
subplot(2,1,2);
plot(Rxx);
grid;
title('Autocorrelation function of the sinewave');
xlabel('lags');
ylabel('Autocorrelation');
Conclusion: Thus we performed practical successfully.
Practical No: 7
Theory:
In signal processing, a finite impulse response (FIR) filter is a filter whose impulse response (or
response to any finite length input) is of finite duration, because it settles to zero in finite time.
This is in contrast to infinite impulse response (IIR) filters, which may have internal feedback
and may continue to respond indefinitely (usually decaying).
The impulse response (that is, the output in response to a Kronecker delta input) of an Nth-order
discrete-time FIR filter lasts exactly N + 1 samples (from first nonzero element through last
nonzero element) before it then settles to zero.
input values, so can be no greater than times the largest value appearing in the input.
Can easily be designed to be linear phase by making the coefficient sequence symmetric.
This property is sometimes desired for phase-sensitive applications, for example data
communications, seismology, crossover filters, and mastering.
The main disadvantage of FIR filters is that considerably more computation power in a general
purpose processor is required compared to an IIR filter with similar sharpness or selectivity,
especially when low frequency (relative to the sample rate) cutoffs are needed. However many
digital signal processors provide specialized hardware features to make FIR filters approximately
as efficient as IIR for many applications.
An FIR filter is designed by finding the coefficients and filter order that meet certain
specifications, which can be in the time-domain (e.g. a matched filter) and/or the frequency
domain (most common). Matched filters perform a cross-correlation between the input signal
and a known pulse-shape. The FIR convolution is a cross-correlation between the input signal
and a time-reversed copy of the impulse-response. Therefore, the matched-filter's impulse
response is "designed" by sampling the known pulse-shape and using those samples in reverse
order as the coefficients of the filter.
When a particular frequency response is desired, several different design methods are common:
1. Window design method
2. Frequency Sampling method
3. Weighted least squares design
4. Parks-McClellan method
Program:
clc;
clear all;
close all;
rp=input('Enter the passband ripple(rp):');
rs=input('Enter the stopband ripple(rs):');
fp=input('Enter the passband frequency(fp):');
fs=input('Enter the stopband
frequency(fs):');
f=input('Enter the sampling frequency(f):');
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=boxcar(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(m);
ylabel('Gain(db)->');
xlabel('(a)Normalised frequency->');
%High pass filter
b=fir1(n,wp,'high',y);
[h,o]=freqz(b,1,256);
m=20*log10(abs(h));
subplot(2,2,2);
plot(m);
ylabel('Gain(db)->');
xlabel('(b)Normalised frequency->');
%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(m);
ylabel('Gain(db)->');
xlabel('(c)Normalised frequency->');
%Band stop filter
wn=[wp*ws];
b=fir1(n,wn,'stop',y);
[h,o]=freqz(b,1,256);
m=20*log10(abs(h));
subplot(2,2,4);
plot(m);
ylabel('Gain(db)->');
xlabel('(d)Normalised frequency->');
Output:
Program:
clear all;
clc;
rp = input(‘pass ripple freq’);
rs = input(‘stop ripple freq’);
fp = input(‘pass band freq’);
fs = input(‘stop band freq’);
f = input(‘sample freq’);
w1 = 2*fp/f;
w2= 2*fs/f;
[nJ= buttord(w1 ,w2,rp,rs);
wn= [w1,w2];
[b,a]= butter(n,wn,’bandpass’);
w=0:0.1:pi;
[h,p]= freqz(b,a,w);
g= 20*log10(abs(h));
A=angle(h); subplot (2,2,1);
plot(p/pi,g); ylabel(‘amp’);
xlabel(‘ferq’);
title(‘amp,freq’);
subplot (2,2,2);
plot(p/pi,A);
xlabel(‘normal. freq’);
ylabel(‘phase’);
title(‘normal. freq,phas&);