Professional Documents
Culture Documents
: 1
GENERATION OF SIGNALS
AIM:
6. Sine signal
7. Triangular signal
8. Gaussian signal
9. Parabolic signal
REQUIRED SOFTWARE:
Matlab
MATLAB PROGRAM:
n=10
t=-n:1:n
i=[zeros(1,n) 1 zeros(1,n)]
subplot(3,1,1)
stem(t,i)
s=[zeros(1,n) 1 ones(1,n)]
subplot(3,1,2)
stem(t,s)
r=[zeros(1,n) 0 1:n]
subplot(3,1,3)
stem(t,r)
2.Exponential
a.increasing signal,
b. decreasing signal
n=10
t=-n:.01:n
einc=exp(t)
subplot(2,1,1)
plot(t,einc)
subplot(2,1,2)
edic=exp(-t)
plot(t,edic)
3. Sine Wave
n=10
t=0:.01:n
f1=150
fs=500
f=f1/fs
s=sin(2*pi*f*t)
plot(t,s)
4. Triangular Wave
n=100
t=0:.1:n
w=.5
y=sawtooth(t,w)
plot(t,y)
5. Parabolic :
n=10
t=-n:.01:n
y=power(t,2)
plot(t,y)
6.Gaussian Waveforms:
n=10
t=-n:.01:n
g=exp(-1*power(t,2))
plot(t,g)
grid on
OUTPUT GRAPH:
Triangular wave
Sine wave
Gaussian Function
Exponential function
AIM:
To write the programs for finding the linear and circular convolution of two signals using
MATLAB 2015a.
APPARATUS REQUIRED:
Matlab software
MATLAB PROGRAM:
Clc
clear all
close all
x=input('enter x: ')
h=input('enter h: ')
a=length(x)
b=length(h)
if(a>=b)
n=a;
else
n=b;
end
y=cconv(x,h,n)
t=0:n-1
stem(t,y)
OUTPUT
Linear convolution
enter x: [1 2 3 4]
x =1 2 3 4
enter h: [8 6 7 5 1 ]
h =8 6 7 5 1
m=4
n =5
c =8
t =0 1 2 3 4 5 6 7
y =8 22 43 69 56 45 23 4
Linearconvolutionwithoutfunction
Enter x: [1 2 3 4]
x =1 2 3 4
Enter h: [8 6 7 5 1]
h =8 6 7 5 1
Y =8 22 43 69 56 45 23 4
Circular convolution
enter x: [1 2 3 4]
x =1 2 3 4
enter h: [5 6 7 8]
h =5 6 7 8
a =4
b =4
y = 66 68 66 60
t =0 1 2 3
RESULT & INFERENCE:
Convolution of two signals both linear and circular is founded successfully using
function and without function.
Expt. No.: 3
CORRELATION OF SIGNALS
AIM:
To write the program for finding the correlation of two signals using MATLAB 2015a.
APPARATUS REQUIRED:
Matlab software
CORRELATION :
Program:
x1=input('function1 = ')
x2=input('function2 = ')
m=length(x1)
n=length(x2)
c=m+n-1
x3=fliplr(x1)
x4=fliplr(x2)
k=0
for i=1:m
for j=1:n
y1(i,j+k)=x1(i)*x4(j)
y2(i,j+k)=x1(i)*x3(j)
y3(i,j+k)=x2(i)*x4(j)
end
k=k+1
end
z1=sum(y1)
z2=sum(y2)
z3=sum(y3)
t=0:c-1
plot(t,z1,'r')
hold on
plot(t,z2,'b')
plot(t,z3,'g')
hold off
legend('cross','auto','auto2')
OUTPUT:
function1 = [1 2 3 4]
x1 =1 2 3 4
function2 = [5 6 7 8]
x2 =5 6 7 8
m=4
n=4
c =7
x3 = 4 3 2 1
x4 = 8 7 6 5
k=0
y1 = 8
y2 = 4
y3 = 40
y1 = 8 7
y2 = 4 3
y3 = 40 35
y1 = 8 7 6
y2 = 4 3 2
y3 = 40 35 30
y1 = 8 7 6 5
y2 = 4 3 2 1
y3 = 40 35 30 25
k= 1
y1 =
8 7 6 5
0 16 0 0
y2 =
4 3 2 1
0 8 0 0
y3 =
40 35 30 25
0 48 0 0
y1 =
8 7 6 5
0 16 14 0
y2 =
4 3 2 1
0 8 6 0
y3 =40 35 30 25
0 48 42 0
y1 =
8 7 6 5
0 16 14 12
y2 =
4 3 2 1
0 8 6 4
y3 =
40 35 30 25
0 48 42 36
y1 =
8 7 6 5 0
0 16 14 12 10
y2 =
4 3 2 1 0
0 8 6 4 2
y3 =
40 35 30 25 0
0 48 42 36 30
k=
y1 =
8 7 6 5 0
0 16 14 12 10
0 0 24 0 0
y2 =
4 3 2 1 0
0 8 6 4 2
0 0 12 0 0
y3 =
40 35 30 25 0
0 48 42 36 30
0 0 56 0 0
y1 =
8 7 6 5 0
0 16 14 12 10
0 0 24 21 0
y2 =
4 3 2 1 0
0 8 6 4 2
0 0 12 9 0
y3 =
40 35 30 25 0
0 48 42 36 30
0 0 56 49 0
y1 =
8 7 6 5 0
0 16 14 12 10
0 0 24 21 18
y2 =
4 3 2 1 0
0 8 6 4 2
0 0 12 9 6
y3 =
40 35 30 25 0
0 48 42 36 30
0 0 56 49 42
y1 =
8 7 6 5 0 0
0 16 14 12 10 0
0 0 24 21 18 15
y2 =
4 3 2 1 0 0
0 8 6 4 2 0
0 0 12 9 6 3
y3 =
40 35 30 25 0 0
0 48 42 36 30 0
0 0 56 49 42 35
k= 3
y1 =
8 7 6 5 0 0
0 16 14 12 10 0
0 0 24 21 18 15
0 0 0 32 0 0
y2 =
4 3 2 1 0 0
0 8 6 4 2 0
0 0 12 9 6 3
0 0 0 16 0 0
y3 =
40 35 30 25 0 0
0 48 42 36 30 0
0 0 56 49 42 35
0 0 0 64 0 0
y1 =
8 7 6 5 0 0
0 16 14 12 10 0
0 0 24 21 18 15
0 0 0 32 28 0
y2 =
4 3 2 1 0 0
0 8 6 4 2 0
0 0 12 9 6 3
0 0 0 16 12 0
y3 =
40 35 30 25 0 0
0 48 42 36 30 0
0 0 56 49 42 35
0 0 0 64 56 0
y1 =
8 7 6 5 0 0
0 16 14 12 10 0
0 0 24 21 18 15
0 0 0 32 28 24
y2 =
4 3 2 1 0 0
0 8 6 4 2 0
0 0 12 9 6 3
0 0 0 16 12 8
y3 =
40 35 30 25 0 0
0 48 42 36 30 0
0 0 56 49 42 35
0 0 0 64 56 48
y1 =
8 7 6 5 0 0 0
0 16 14 12 10 0 0
0 0 24 21 18 15 0
0 0 0 32 28 24 20
y2 =
4 3 2 1 0 0 0
0 8 6 4 2 0 0
0 0 12 9 6 3 0
0 0 0 16 12 8 4
y3 =
40 35 30 25 0 0 0
0 48 42 36 30 0 0
0 0 56 49 42 35 0
0 0 0 64 56 48 40
k=
z1 =
8 23 44 70 56 39 20
z2 =
4 11 20 30 20 11 4
z3 =
t=
0 1 2 3 4 5 6
RESULT & INFERENCE : Correlation of two signals if founded successfully.
Expt. No.: 4
SYSTEM REQUIREMENTS:
Matlab software
MATLAB PROGRAM:
clear all
close all
clc
n=512;
t=0:100;
f1=50;
f2=100;
f3=150;
f4=250;
fs=1000;
s=sin(2*pi*f1/fs*t)+sin(2*pi*f2/fs*t)+sin(2*pi*f3/fs*t)+sin(2*pi*f4/fs*t);
figure(1);
plot(t,s)
sf=fft(s,n)
h=0:fs/n:fs-fs/n
figure(2);
plot(h,abs(sf))
sn1=awgn(s,0)
sn2=awgn(s,-10)
sn3=awgn(s,10)
sf1=fft(sn1,n)
sf2=fft(sn2,n)
sf3=fft(sn3,n)
sm1=abs(sf1)
sm2=abs(sf2)
sm3=abs(sf3)
figure(3)
subplot(311)
plot(h,sm1)
subplot(312)
plot(h,sm2)
subplot(313)
plot(h,sm3)
SAMPLE OUTPUT:
s1-10Hz signal
1
0
-1
0 50 100 150 200 250
s2-20Hz signal
1
0
-1
0 50 100 150 200 250
s3-50Hz signal
Magnitude
1
0
-1
0 50 100 150 200 250
Time
s=s1+s2+s3(Sum of the signals)
5
0
-5
0 50 100 150 200 250
100
80
Magnitude
60
40
20
0
0 50 100 150
Frequency
-2
-4
0 50 100 150 200 250
100
50
0
0 50 100 150
Fig.3 Top: Input signal with noise Bottom: Spectra of the input signal with noise
ACTUAL OUTPUT:
RESULT& INFERENCE:
AIM:
To design an IIR band pass butterworth, Chebyshev type-I and type-II and elliptical
filters using MATLAB R2015.
APPARATUS REQUIRED:
System with MATLAB R2015a.
ALGORITHM:
1. Get the input sinusoids for varying frequencies
2. Get the pass band ripple and stop band attenuation
3. Get the order and filter cut off frequencies
4. Get the sampling frequency
5. Define the IIR band pass elliptical filter and get the filtered output
6. Compute the power spectrum
7. Plot the magnitude responses
MATLAB PROGRAM:
Write a MATLAB program to design an IIR band pass elliptical filter for the given
specifications. Plot the magnitude response and the corresponding power spectral density
output.
Input frequencies: f1= 10Hz; f2= 20Hz; f3= 40Hz; f4= 60Hz
clear all
close all
clc
n=512;
N=4;
t=0:100;
f1=10;
f2=20;
f3=40;
f4=60;
fs=150;
s=sin(2*pi*f1/fs*t)+sin(2*pi*f2/fs*t)+sin(2*pi*f3/fs*t)+sin(2*pi*f4/fs*t);
figure(1);
plot(t,s);
k1=15;
k2=45;
rp=0.1;
rs=0.2;
figure(2)
%butter
[b1,a1]=butter(N,[k1 k2]*2/fs);
[h1,w1]=freqz(b1,a1,n);
subplot(221)
plot(w1*fs/(2*pi),abs(h1));
%chebyshev type 1
[b2,a2]=cheby1(N,rp,[k1 k2]*2/fs);
[h2,w2]=freqz(b2,a2,n);
subplot(222);
plot(w2*fs/(2*pi),abs(h2));
%chebyshev type 2
[b3,a3]=cheby2(N,rs,[k1 k2]*2/fs);
[h3,w3]=freqz(b3,a3,n);
subplot(223);
plot(w3*fs/(2*pi),abs(h3));
%elliptocal
[b4,a4]=ellip(N,rp,rs,[k1 k2]*2/fs);
[h4,w4]=freqz(b4,a4,n);
subplot(224);
plot(w4*fs/(2*pi),abs(h4));
SAMPLE OUTPUT:
s1-10Hz signal
1
-1
0 50 100 150 200 250
s2-20Hz signal
1
-1
0 50 100 150 200 250
s3-40Hz signal
1
-1
0 50 100 150 200 250
s4-50Hz signal
1
-1
0 50 100 150 200 250
-1
-2
-3
-4
0 50 100 150 200 250
0.9
0.8
0.7
0.6
Gain(dB)
0.5
0.4
0.3
0.2
0.1
0
0 10 20 30 40 50 60 70 80
Frequency(Hz)
-2
-4
0 50 100 150 200 250
Time
Frequency spectrum of the filtered signal
PSD-Power Spectral Density
150
100
50
0
0 10 20 30 40 50 60 70 80
Frequency(Hz)
ACTUAL OUTPUT:
RESULT & INFERENCE:
s=sin(2*pi*f1/fs*t)+sin(2*pi*f2/fs*t)+sin(2*pi*f3/fs*t)+sin(2*pi*f4/fs*t);
figure(2)
plot(t,s);
k1=15;
k2=45;
rp=0.1;
rs=0.2;
[b,a]=ellip(N,rp,rs,[k1 k2]*2/fs);
%for stop band [b,a]=butter(N,[75 220]*2/fs,'stop');
[h,w]=freqz(b,a,n);
figure(3);
plot(w*fs/(2*pi),abs(h));
sf=filter(b,a,s);
c=fft(s,n);
d=fft(sf,n);
e=0:fs/n:fs-fs/n;
figure(4)
subplot(211)
plot(e,abs(c))
subplot(212)
plot(e,abs(d))
Expt. No.: 6
AIM:
To design a FIR filter using Hamming window with MATLAB R2015a.
APPARATUS REQUIRED:
System with MATLAB R2015a.
ALGORITHM:
1. Get the pass band and stop band ripples
2. Get the pass band and stop band edge frequencies
3. Get the sampling frequency.
4. Calculate the order of the filter
5. Find the window coefficients
6. Plot the magnitude responses
MATLAB PROGRAM:
Write a MATLAB program to design a FIR filter for LPF, HPF, BPF, BSF using Hamming
window for the given specification and plot their magnitude responses.
Pass band ripple = 0.02
Stop band ripple = 0.01
Pass band frequency = 1000
Stop band frequency = 1500
Sampling frequency = 5000
clear all
close all
clc
rp=0.02
rs=0.01
fpb=1000
fsb=1500
fs=5000
n=(-20*log10(sqrt(rp*rs))-13)/(14.6*(fsb-fpb)/fs)
N=ceil(n)
if(mod(N,2)>0)
N=N-1
end
W=hamming(N+1)
b1=fir1(N,fpb*2/fs,'low',W)
[h1,w1]=freqz(b1,1,512)
figure(1)
subplot(221)
plot(w1*fs/(2*pi),20*log10(abs(h1)))
b2=fir1(N,fpb*2/fs,'high',W)
[h2,w2]=freqz(b2,1,512)
subplot(222)
plot(w2*fs/(2*pi),20*log10(abs(h2)))
b3=fir1(N,[fpb fsb]*2/fs,'stop',W)
[h3,w3]=freqz(b3,1,512)
subplot(223)
plot(w3*fs/(2*pi),20*log10(abs(h3)))
b4=fir1(N,[fpb fsb]*2/fs,'bandpass',W)
[h4,w4]=freqz(b4,1,512)
subplot(224)
plot(w4*fs/(2*pi),20*log10(abs(h4)))
SAMPLE OUTPUT:
Magnitude response of FIR low pass filter Magnitude response of FIR high pass filter
50 50
0
0
Gain(dB)
Gain(dB)
-50
-50
-100
-150 -100
0 0.5 1 0 0.5 1
(a)Normalized frequency----> (b)Normalized frequency---->
Magnitude response of FIR band pass filter Magnitude response of FIR band stop filter
0 5
0
-50
Gain(dB)
Gain(dB)
-5
-100
-10
-150 -15
0 0.5 1 0 0.5 1
(c)Normalized frequency----> (d)Normalized frequency---->
Fig.1 Magnitude responses of FIR LPF, HPF, BPF and BSF using Hamming window
ACTUAL OUTPUT: