Documente Academic
Documente Profesional
Documente Cultură
6
6
6
3
7
2
Adjoint of matrix A is
D=
-30 17 24
6 -5 0
24 -8 -24
Inverse of matrix A is
Inverse =
-1.2500 0.2500 1.0000
0.7083 -0.2083 -0.3333
1.0000
0 -1.0000
WAVE FORMS
PROGRAM 1
x = 0:0.01:pi;
y = sin(x);
plot(x,y)
t=0:0.1:5;
y=cos(t)
plot(t,y)
OUTPUT
1
0.8
0.6
0.4
0.2
0
-0.2
-0.4
-0.6
-0.8
-1
0.5
1.5
Program 2:
%TO Generate a UNIT step Sequence
N=21;
x=ones(1,N);
n=0:1:N-1;
subplot(2,2,1);
stem(n,x);
xlabel('n')
ylabel('x(n)');
title('UNIT STEP SEQUENCE');
OUTPUT
2.5
3.5
4.5
x(n)
0.5
10
n
15
20
x1(n)
1
0
-1
-2
%Exponential sequence
x2=.8.^(n);
subplot(2,2,3)
stem(n,x2);
xlabel('n');
ylabel('x2(n)');
title('Exponential sequences');
OUTPUT
10
n
15
20
Exponential sequences
x2(n)
0.5
10
n
% SInusoidal sequence
x3=sin(.1*pi*n);
subplot(2,2,4)
stem(n,x3);
xlabel('n');
ylabel('x3(n)');
xlabel('n');
ylabel('x3(n)');
title('Sinusoidal sequences');
OUTPUT
15
20
Sinusoidal sequences
x3(n)
0.5
0
-0.5
-1
10
n
15
20
4
3.5
3
y(n)
2.5
2
1.5
1
0.5
0
------->Amplitude
1
0.5
0
-0.5
-1
%SIN WAVEFORM
t=-5:0.1:5;
y=sin(t*pi/2);
subplot(2,2,2);
plot(t,y)
xlabel('-----t');
ylabel('----AMPLITUDE');
title('SIN WAVE FORM ');
OUTPUT
------->t
----AMPLITUDE
1
0.5
0
-0.5
-1
-5
%TAN WAVEFORM
t=0:0.1:5;
y=tan(t*pi/2);
subplot(2,2,3);
plot(t,y)
xlabel('-----t');
ylabel('----AMPLITUDE');
title('tan WAVE FORM ');
OUTPUT
0
-----t
16
----AMPLITUDE
x 10
1
0
-1
-----t
%COT WAVEFORM
t=0:0.1:5;
y=cot(t*pi/2);
subplot(2,2,4);
plot(t,y)
xlabel('-----t');
ylabel('----AMPLITUDE');
title('COT WAVE FORM ');
OUTPUT
15
----AMPLITUDE
x 10
0
-5
-10
-----t
Triangular Pulse
1
0.9
0.8
------->Amplitude
0.7
0.6
0.5
0.4
0.3
0.2
0.1
0
-20
-15
-10
-5
0
------->t
10
15
20
------>amplitude
10
15
20
25
------>t
30
35
40
45
50
magnitude
6
4
2
0
0.2
0.4
0.6
0.8
1
1.2
Normalised frequency
1.4
1.6
1.8
0.2
0.4
0.6
0.8
1
1.2
normalised frequency
1.4
1.6
1.8
phase in Radians
1
0.5
0
-0.5
-1
subplot(2,2,4);
plot(ph1/pi,angle(h1));
grid;
xlabel('Normalised frequency')
ylabel('phase in Radians');
1.5
Magnitude
magnitude
OUTPUT
0.5
0
0.5
Normalised frequency
0.5
0
-0.5
0
0.5
Normalised frequency
0.5
Normalised frequency
0.5
Normalised frequency
2
phase in Radians
phase in radians
-1
1
0
-1
------->Amplitude
0.5
0
-20
Triangular Pulse
-10
0
------->t
10
20
----->Amplitude
Rectangular Pulse
0.5
0
-20
-10
0
------>t
10
20
Periodic Sinc
----->Amplitude
1
0.5
0
-0.5
-4
-3
-2
-1
0
------>t
------>amplitude
10
15
20
25
------>t
30
35
40
45
50
------>amplitude
1
0.5
0
-0.5
-1
-10
-8
-6
-4
-2
0
------>t
10
1
0.5
0
-0.5
-1
100
200
300
400
500
600
700
----------->amplitude
2
1.5
1
0.5
0
3
----------->t
subplot(3,1,3);
plot(t,xa);
xlabel('----->t in msec');
ylabel('x(t)');
title('Reconstructed signalx(t)fromx(n)');
OUTPUT:
x(t)
1
0.5
0
-5
-4
-3
-2
-1
0
1
----->t in msec
ts=0.1 msec
0.2
0.4
0.6
0.8
x(n)
1.4
1.6
1.8
0
-1
1
----->n
1.2
end
subplot(2,2,1)
stem(1:1:N,comp_number);
title('input signal');
xlabel('time');
ylabel('amplitude')
subplot(2,2,2)
stem(1:1:length(re),re);
title('real part of signal')
xlabel('time');
ylabel('amplitude')
subplot(2,2,3)
stem(1:1:length(img),img)
title('imaginary part of signal')
xlabel('time');
ylabel('amplitude')
OUTPUT:
input signal
2
1
0
amplitude
4
amplitude
amplitude
0.5
1
1.5
time
imaginary part of signal
3
2
1
0
0.5
1
time
1.5
3
2
1
0
0.5
1
time
1.5
function y=convolve(x1,x2)
x1=5;
x2=6;
m=length(x1);
n=length(x2);
k=m+n-1;
x1=[x1 zeros(1,n-1)];
x2=[x2 zeros(1,m-1)];
y=zeros(1,k);
for i=1:k
for j=1:i
if i==1
y(i)=x1(1)*x2(1);
else
y(i)=y(i)+x1(i-j+1)*x2(j);
end
end
end
subplot(2,2,1)
stem(1:1:m,x1)
title('first Input signal')
xlabel('time')
ylabel('Amplitude')
subplot(2,2,2)
stem(1:1:n,x2)
title('Second Input signal')
xlabel('time')
ylabel('Amplitude')
subplot(2,2,3)
stem(1:1:k,y)
title('Convolved signal')
xlabel('time')
ylabel('Amplitude')
OUTPUT:
4
2
0
0.5
0.5
Amplitude
30
1
1.5
time
Convolved signal
6
Amplitude
Amplitude
4
2
0
0.5
1
time
1.5
20
10
0
1
time
1.5
wn(i)=0.54-.46*cos(2*pi*i/(n-1));
end
% LOW PASS FILTER
b=fir1(n,wp,wn);
[h,o]=freqz(b,1,256);
m=20*log10(abs(h));
subplot(2,2,1);
plot(o/pi,m);
title('Lowpass filter')
ylabel('gain in db')
xlabel('(a)Normalized Frequency ---->');
%HIGH PASS FILTER
b=fir1(n,wp,'high',wn);
[h,o]=freqz(b,1,256);
m=20*log10(abs(h));
subplot(2,2,2);
plot(o/pi,m);
title('High pass Filter')
ylabel('gain in db')
xlabel('(a)Normalized Frequency ---->');
%BAND PASS FILTER
bw=[wp ws];
b=fir1(n,bw,wn);
[h,o]=freqz(b,1,256);
m=20*log10(abs(h));
subplot(2,2,3);
plot(o/pi,m);
title('band pass filter')
ylabel('gain in db')
xlabel('(a)Normalized Frequency ---->');
%BAND STOP FILTER
b=fir1(n,wp,'stop',wn);
[h,o]=freqz(b,1,256);
m=20*log10(abs(h));
subplot(2,2,4)
plot(o/pi,m);
title('band stop Filter')
ylabel('gain in db')
xlabel('(a)Normalized Frequency ---->');
50
Lowpass filter
gain in db
gain in db
0
-50
-100
-20
-40
-60
-80
0
0.5
1
(a)Normalized Frequency ---->
0
-20
-40
-60
0
0.5
1
(a)Normalized Frequency ---->
band pass filter
50
gain in db
gain in db
20
0
0.5
1
(a)Normalized Frequency ---->
band stop Filter
0
-50
-100
0
0.5
1
(a)Normalized Frequency ---->
n1=n+1;
if rem(n,2)~=0
n=n-1;
end
%BLACKMAN WINDOW CO-EFFICIENTS
for i=1:n+1
wn(i)=0.54-.46*cos(2*pi*i/(n-1));
end
%LOW PASS FILTER
bw=[wp ws];
b=fir1(n,bw,wn);
[h,o]=freqz(b,1,256);
m=20*log10(abs(h));
subplot(2,2,2);
plot(o/pi,m)
ylabel('gain in db')
xlabel('(a)normalized freqency----->');
b=fir1(n,bw,'stop',wn);
[h,o]=freqz(b,1,256);
m=20*log10(abs(h));
subplot(2,2,3);
plot(o/pi,m)
ylabel('gain in db')
xlabel('(a)normalized freqency----->');
title('bsf')
b=fir1(n,wp,wn);
[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)normalized freqency----->');
b=fir1(n,wp,'high',wn);
[h,o]=freqz(b,1,256);
m=20*log10(abs(h));
subplot(2,2,4);
plot(o/pi,m)
ylabel('gain in db')
xlabel('(a)normalized freqency----->');
gain in db
gain in db
20
-20
-40
-60
-5
-10
0
0.5
(a)normalized freqency----->
0.5
(a)normalized freqency----->
0.5
(a)normalized freqency----->
20
-15
-40
-60
gain in db
gain in db
0.5
(a)normalized freqency----->
bsf
-20
%INOUT PLOTS
income = [3.2 4.1 5.0 5.6];
outgo = [2.5 4.0 3.35 4.9];
subplot(2,1,1); plot(income)
subplot(2,1,2); plot(outgo)
0
-20
-40
-60
6
5
4
3
1.5
2.5
3.5
1.5
2.5
3.5
5
4.5
4
3.5
3
2.5
%COMPUTE PSD
sx=fft(rx,1024);
% PLOTS
subplot(2,2,1);
plot(x);
title('inputsignal');
xlabel('Time');
ylabel('Amplitude');
subplot(2,2,2);
plot(10*log10(abs(sx)));
title('magnitude spectrum');
xlabel('Frequency');
ylabel('power in db');
subplot(2,2,3);
plot(angle(sx));
title('phase spectrum');
xlabel('Frequency');
ylabel('phase');
100.5
100
99.5
99
0.5
1
1.5
Time
phase spectrum
500
1000
Frequency
1500
phase
0.5
0
-0.5
-1
magnitude spectrum
41
power in db
Amplitude
101
40.5
40
39.5
39
500
1000
Frequency
1500
ampltude
ampltue
1.5
1
0.5
0
1
1.5
time
response of system
0.5
ampltude
10
0.5
0.5
1
time
1.5
0.5
0
-0.5
-1
1
time
1.5
subplot(2,2,2)
stem(10*log10(abs(X)))
title('MAGNITUDE RESPONSE OF PSD')
xlabel('Frequency')
ylabel('Amplitude')
subplot(2,2,3)
stem(angle(X))
title('PHASE RESPONSE OF PSD')
xlabel('Frequency')
ylabel('Phase')
OUTPUT
Input Signal
Amplitude
Amplitude
2
0
0.5
1
1.5
2
Time
PHASE RESPONSE OF PSD
Phase
0.5
0
-0.5
-1
0.5
1
1.5
Frequency
%BLACKMAN WINDOW
function x=blackman1(rp,rs,fp,fs,f)
rp=0.03;
rs=0.01;
fp=2000;
6
4
2
0
0.5
1
1.5
Frequency
fs=2500;
f=7000;
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
for i=1:n+1
wn(i)=0.42-0.5*cos(2*pi*i/(n-1))+0.08*cos(4*pi*i/(n-1));
end
%low pass filter
b=fir1(n,wp,wn);
[h,o]=freqz(b,1,256);
m=20*log10(abs(h));
subplot(2,2,1)
plot(o/pi,m)
title('low pass filter')
ylabel('gain in db')
xlabel('(a) Normalised Frequency------>');
%HPF
b=fir1(n,wp,'high',wn);
[h,o]=freqz(b,1,256);
m=20*log10(abs(h));
subplot(2,2,2)
plot(o/pi,m);
title('high pass filter')
ylabel('gain in db')
xlabel('(a) Normalized Frequency------->');
OUTPUT OF THE BLACK MAN WINDOW
0
-20
-40
-60
g a in in d b
g a in in d b
20
0
0.5
1
(a) Normalised Frequency------>
-20
-40
-60
-80
0
0.5
1
(a) Normalized Frequency------->
%POLE-ZERO PLOT
[z,p]=tf2zp(b,a);
subplot(2,2,4);
zplane(z,p);
2
1.5
1.5
0.5
0.5
impulse response
2
Radians
1
Imaginary Part
0.5
0
-0.5
-1
phase Response
seconds
10
15
0.5
0
-0.5
-1
-1
-0.5
0 0.5
Real Part
maginitude Response
1.5
phase Response
4
2
0
0.5
0
-2
0
impulse response
0.3
2
Radians
1
Imaginary Part
0.2
0.1
0
-0.1
-4
10
20
seconds
30
0.5
0
-0.5
-1
-1
0
Real Part
0.12
0.1
0.08
0.06
0.04
0.02
0
-8
-6
-4
-2
10
12
ylabel('Phase in radians-->');
xlabel('(b) Normalised Frequency--->');
title('phase of the system');
OUT PUT OF THE %CHEBYCHEV TYPE-1 LOW PASS FILTER
Enter the pass band ripple0. 2
Enter the stop band ripple45
Enter the pass band freq1300
Enter the stop band freq1500
Enter the Sampling Frequency10000
magnitude of the system
Gain in db--->
0
-100
-200
-300
-400
0.1
0.2
0.3
0.4
0.5
0.6
0.7
(a)Normalised Frequency--->
phase of the system
0.8
0.9
0.1
0.2
0.3
0.4
0.5
0.6
0.7
(b) Normalised Frequency--->
0.8
0.9
Phase in radians-->
4
2
0
-2
-4
w1=2*wp/fs;
w2=2*ws/fs;
[n,wn]=cheb1ord(w1,w2,rp,rs,'s');
[b,a]=cheby1(n,rp,wn,high,'s');
w=0:.01/pi:pi;
[h,om]=freqs(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--->');
title('magnitude of the system');
subplot(2,1,2);
plot(om/pi,an);
ylabel('Phase in radians-->');
xlabel('(b) Normalised Frequency--->');
title('phase of the system');
OUTPUT OF THE CHEBYCHEV TYPE-1 HIGH PASS FILTER
Enter the pass band ripple0.3
Enter the stop band ripple60
Enter the pass band freq1500
Enter the stop band freq2000
Enter the Sampling Frequency9000
Gain in db--->
0
-50
-100
-150
-200
0.1
0.2
0.3
0.4
0.5
0.6
0.7
(a)Normalised Frequency--->
phase of the system
0.8
0.9
0.1
0.2
0.3
0.4
0.5
0.6
0.7
(b) Normalised Frequency--->
0.8
0.9
Phase in radians-->
4
2
0
-2
-4
plot(om/pi,an);
ylabel('Phase in radians-->');
xlabel('(b) Normalised Frequency--->');
CHEBYCHEV TYPE-1 BAND PASS FILTER
Enter the pass band ripple0.4
Enter the stop band ripple35
Enter the pass band freq2000
Enter the stop band freq2500
Enter the Sampling Frequency10000
Gain in db--->
0
-200
-400
-600
0.1
0.2
0.3
0.4
0.5
0.6
0.7
(a)Normalised Frequency--->
0.8
0.9
0.1
0.2
0.3
0.4
0.5
0.6
0.7
(b) Normalised Frequency--->
0.8
0.9
Phase in radians-->
4
2
0
-2
-4
w2=2*ws/fs;
[n,wn]=cheb1ord(w1,w2,rp,rs,'s');
wn=[w1,w2];
[b,a]=cheby1(n,rp,wn,stop','s');
w=0:.01/pi:pi;
[h,om]=freqs(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);
ylabel('Phase in radians-->');
xlabel('(b) Normalised Frequency--->');
CHEBYCHEV TYPE-1 BAND STOP FILTER
Enter the pass band ripple0.25
Enter the stop band ripple40
Enter the pass band freq2500
Enter the stop band freq2750
Enter the Sampling Frequency7000
Gain in db--->
50
-50
0.1
0.2
0.3
0.4
0.5
0.6
0.7
(a)Normalised Frequency--->
0.8
0.9
0.1
0.2
0.3
0.4
0.5
0.6
0.7
(b) Normalised Frequency--->
0.8
0.9
Phase in radians-->
4
2
0
-2
-4
Gain in db--->
0
-20
-40
-60
0.1
0.2
0.3
0.4
0.5
0.6
0.7
(a)Normalised Frequency--->
0.8
0.9
0.1
0.2
0.3
0.4
0.5
0.6
0.7
(b) Normalised Frequency--->
0.8
0.9
Phase in radians-->
2
1
0
-1
-2
ylabel('Gain in db--->');
xlabel('(a)Normalised Frequency--->');
subplot(2,1,2);
plot(om/pi,an);
ylabel('Phase in radians-->');
xlabel('(b) Normalised Frequency--->');
CHEBYCHEV TYPE-2 HIGH PASS FILTER
Enter the pass band ripple0.25
Enter the stop band ripple40
Enter the pass band freq1400
Enter the stop band freq1800
Enter the Sampling Frequency7000
Gain in db--->
10
0
-10
-20
-30
0.1
0.2
0.3
0.4
0.5
0.6
0.7
(a)Normalised Frequency--->
0.8
0.9
0.1
0.2
0.3
0.4
0.5
0.6
0.7
(b) Normalised Frequency--->
0.8
0.9
Phase in radians-->
2
1
0
-1
-2
format long
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 Frequency');
w1=2*wp/fs;
w2=2*ws/fs;
[n,wn]=cheb2ord(w1,w2,rp,rs,'s');
wn=[w1,w2];
[b,a]=cheby2(n,rp,wn,'high','s');
w=0:.01/pi:pi;
[h,om]=freqs(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);
ylabel('Phase in radians-->');
xlabel('(b) Normalised Frequency--->');
CHEBYCHEV TYPE-2 BAND PASS FILTER
Enter the pass band ripple0.4
Enter the stop band ripple40
Enter the pass band freq1400
Enter the stop band freq2000
Enter the Sampling Frequency9000
Gain in db--->
50
0
-50
-100
0.1
0.2
0.3
0.4
0.5
0.6
0.7
(a)Normalised Frequency--->
0.8
0.9
0.1
0.2
0.3
0.4
0.5
0.6
0.7
(b) Normalised Frequency--->
0.8
0.9
Phase in radians-->
2
1
0
-1
-2
xlabel('(a)Normalised Frequency--->');
subplot(2,1,2);
plot(om/pi,an);
ylabel('Phase in radians-->');
xlabel('(b) Normalised Frequency--->');
CHEBYCHEV TYPE-2 BAND STOP FILTER
Enter the pass band ripple0.3
Enter the stop band ripple46
Enter the pass band freq1400
Enter the stop band freq2000
Enter the Sampling Frequency8000
Gain in db--->
5
0
-5
-10
-15
0.1
0.2
0.3
0.4
0.5
0.6
0.7
(a)Normalised Frequency--->
0.8
0.9
0.1
0.2
0.3
0.4
0.5
0.6
0.7
(b) Normalised Frequency--->
0.8
0.9
Phase in radians-->
2
1
0
-1
-2
Gain in db--->
0
-2
-4
-6
0.1
0.2
0.3
0.4
0.5
0.6
0.7
(a)Normalised Frequency--->
0.8
0.9
0.1
0.2
0.3
0.4
0.5
0.6
0.7
(b) Normalised Frequency--->
0.8
0.9
Phase in radians-->
0
-0.5
-1
-1.5
ylabel('Gain in db--->');
xlabel('(a)Normalised Frequency--->');
subplot(2,1,2);
plot(om/pi,an);
ylabel('Phase in radians-->');
xlabel('(b) Normalised Frequency--->');
OUTPUT OF THE BUTTERWORTH HIGH PASS FILTER
Enter the pass band ripple.6
Enter the stop band ripple.9
Enter the pass band freq1200
Enter the stop band freq1800
Enter the Sampling Frequency4000
b=
Columns 1 through 7
0.0011 -0.0096
0.0384 -0.0895
0.1342 -0.1342
0.0895
1.3708
0.1993
Columns 8 through 10
-0.0384
0.0096 -0.0011
a=
Columns 1 through 7
1.0000
1.7916
2.5319
Columns 8 through 10
0.0431
0.0058
0.0004
2.1182
0.6090
Gain in db--->
20
0
-20
-40
-60
0.1
0.2
0.3
0.4
0.5
0.6
0.7
(a)Normalised Frequency--->
0.8
0.9
0.1
0.2
0.3
0.4
0.5
0.6
0.7
(b) Normalised Frequency--->
0.8
0.9
Phase in radians-->
4
2
0
-2
-4
plot(om/pi,m);
ylabel('Gain in db--->');
xlabel('(a)Normalised Frequency--->');
subplot(2,1,2);
plot(om/pi,an);
ylabel('Phase in radians-->');
xlabel('(b) Normalised Frequency--->');
OUTPUT OF THE BUTTERWORTH BAND PASS FLTER
Enter the pass band ripple0.6
Enter the stop band ripple9
Enter the pass band freq100
Enter the stop band freq800
Enter the Sampling Frequency4000
Gain in db--->
0
-5
-10
-15
-20
0.1
0.2
0.3
0.4
0.5
0.6
0.7
(a)Normalised Frequency--->
0.8
0.9
0.1
0.2
0.3
0.4
0.5
0.6
0.7
(b) Normalised Frequency--->
0.8
0.9
Phase in radians-->
2
1
0
-1
-2
Gain in db--->
0
-10
-20
-30
-40
0.5
1
(a)Normalised Frequency--->
subplot(2,2,2);
plot(o/pi,m);
ylabel('Gain in db--->');
xlabel('(b)Normalised Frequency--->');
OUTPUT OF THE BARLETT HIGH PASS FLTER
Enter the pass band ripple0.04
Enter the stop band ripple0.02
Enter the pass band freq1500
Enter the stop band freq2000
Enter the Sampling Frequency8000
Gain in db--->
10
0
-10
-20
-30
0.5
1
(b)Normalised Frequency--->
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=bartlett(n1);
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--->');
OUTPUT OF THE BARLETT BAND PASS FLTER
Enter the pass band ripple0.04
Enter the stop band ripple0.02
Enter the pass band freq1500
Enter the stop band freq2000
Enter the Sampling Frequency8000
Gain in db--->
10
0
-10
-20
-30
-40
0.5
1
(c)Normalised Frequency--->
Gain in db--->
2
0
-2
-4
-6
-8
0.5
1
(d)Normalised Frequency--->
Magnitude (dB)
50
0
-50
-100
0.1
0.2
0.3
0.4
0.5
0.6
0.7
0.8
0.9
0.1
0.2
0.3
0.4
0.5
0.6
0.7
0.8
0.9
Phase (degrees)
1000
0
-1000
-2000
Magnitude (dB)
50
0
-50
-100
-150
0.1
0.2
0.3
0.4
0.5
0.6
0.7
0.8
0.9
0.1
0.2
0.3
0.4
0.5
0.6
0.7
0.8
0.9
Phase (degrees)
1000
0
-1000
-2000
%Filter a signal using a filter with various initial conditions (IC) or no initial conditions.
x = randn(100,1);
% Original signal.
b = fir1(50,.4);
% 50th-order linear-phase FIR filter.
hd = dfilt.dffir(b); % Direct-form FIR implementation.
% Do not set specific initial conditions.
y1 = filter(hd,x);
zf = hd.states;
%Now use nonzero initial conditions by setting ICs after before you filter.
hd.persistentmemory = true;
hd.states = 1;
% Uses scalar expansion.
y2 = filter(hd,x);
stem([y1 y2])
% Different sequences at the beginning.
OUTPUT:
1.5
0.5
-0.5
-1
-1.5
10
20
30
40
50
60
70
80
90
100
Communication
% Sample the signal 100 times per second, for 2 seconds.
%ammod-Amplitude modulation.
%ssbmod-Single sideband amplitude modulation.
%fft-Discrete Fourier transform.
%abs-Absolute value and complex magnitude.
Fs = 100;
t = [0:2*Fs+1]'/Fs;
Fc = 10; % Carrier frequency
x = sin(2*pi*t); % Sinusoidal signal
% Modulate x using single- and double-sideband AM.
ydouble = ammod(x,Fc,Fs);
ysingle = ssbmod(x,Fc,Fs);
% Compute spectra of both modulated signals.
zdouble = fft(ydouble);
zdouble = abs(zdouble(1:length(zdouble)/2+1));
frqdouble = [0:length(zdouble)-1]*Fs/length(zdouble)/2;
zsingle = fft(ysingle);
zsingle = abs(zsingle(1:length(zsingle)/2+1));
frqsingle = [0:length(zsingle)-1]*Fs/length(zsingle)/2;
% Plot spectra of both modulated signals.
figure;
subplot(2,1,1); plot(frqdouble,zdouble);
title('Spectrum of double-sideband signal');
subplot(2,1,2); plot(frqsingle,zsingle);
title('Spectrum of single-sideband signal');
OUTPUT:
60
40
20
0
10
15
20
25
30
35
40
45
50
40
45
50
100
50
10
15
20
25
30
35
AM Demodulation
%butter- Design Butterworth IIR digital filter using the specifications in filter
specification object.
%ammod- Amplitude modulation
%amdemod- Amplitude demodulation
t = .01;
Fc = 10000; Fs = 80000;
t = [0:1/Fs:0.01]';
s = sin(2*pi*300*t)+2*sin(2*pi*600*t); % Original signal
figure(1) ;plot(s) ;
title(Modulating signal) ;
[num,den] = butter(10,Fc*2/Fs); % Lowpass filter
figure(2) ;plot([num,den]) ;
title(Carrier signal) ;
y1 = ammod(s,Fc,Fs); % Modulate.
figure(3) ;plot(y1) ;
title(Modulated signal) ;
s1 = amdemod(y1,Fc,Fs,0,0,num,den); % Demodulate.
figure(4) ;plot(s1) ;
title(DeModulated signal) ;
OUTPUT:
Modulating signal
-1
-2
-3
100
200
300
400
500
600
700
800
900
Carrier signal
20
15
10
5
0
-5
-10
-15
-20
10
15
20
25
Modulated signal
-1
-2
-3
100
200
300
400
500
600
700
800
900
600
700
800
900
DeModulated signal
-1
-2
-3
100
200
300
400
500
%Freequency Modulation
%fmmod- Freequency Modulation
t = .01;
Fc = 10000; Fs = 80000;
t = [0:1/Fs:0.01]';
s = sin(2*pi*300*t)+2*sin(2*pi*600*t); % Original signal
figure(1) ;plot(s) ;
title(Modulating signal) ;
[num,den] = butter(10,Fc*2/Fs); % Lowpass filter
figure(2) ;plot([num,den]) ;
title(Carrier signal) ;
dev=50;
y1 = ammod(s,Fc,Fs,dev); % Modulate.
figure(3) ;plot(y1) ;
title(Modulated signal) ;
.
OUTPUT:
Modulating signal
-1
-2
-3
100
200
300
400
500
600
700
800
900
Carrier signal
20
15
10
5
0
-5
-10
-15
-20
10
15
20
25
Modulated signal
1
0.8
0.6
0.4
0.2
0
-0.2
-0.4
-0.6
-0.8
-1
100
200
300
400
500
600
700
800
900
%Phase Modulation
% Prepare to sample a signal for two seconds,
% at a rate of 100 samples per second.
Fs = 100; % Sampling rate
t = [0:2*Fs+1]'/Fs; % Time points for sampling
% Create the signal, a sum of sinusoids.
x = sin(2*pi*t) + sin(4*pi*t);
figure(1) ;plot(x) ;
Fc = 10; % Carrier frequency in modulation
phasedev = pi/2; % Phase deviation for phase modulation
y = pmmod(x,Fc,Fs,phasedev); % Modulate.
figure(2) ;plot(y) ;
title(Modulated signal);
z = pmdemod(y,Fc,Fs,phasedev); % Demodulate.
figure(3) ;plot(z) ;
title(Demodulated signal);
OUTPUT:
2
1.5
1
0.5
0
-0.5
-1
-1.5
-2
50
100
150
200
250
200
250
Modulated signal
1
0.8
0.6
0.4
0.2
0
-0.2
-0.4
-0.6
-0.8
-1
50
100
150
Unmodulated signal
2
1.5
1
0.5
0
-0.5
-1
-1.5
-2
50
100
150
200
250
15
10
1000
2000
3000
4000
5000
6000
7000
8000
0.4
0.6
9000 10000
1
0.8
0.6
0.4
0.2
0
-0.2
-0.4
-0.6
-0.8
-1
-1
-0.8
-0.6
-0.4
-0.2
0.2
0.8
15
10
1000
2000
3000
4000
5000
6000
7000
8000
9000 10000
%Quantization
%partition- To specify a partition in MATLAB
%codebook- codebook tells the quantizer which common value to assign
%quantiz-Produce quantization index and quantized output value
%legend-Graph legend for lines and patches
t = [0:.1:2*pi]; % Times at which to sample the sine function
sig = sin(t); % Original signal, a sine wave
partition = [-1:.2:1]; % Length 11, to represent 12 intervals
codebook = [-1.2:.2:1]; % Length 12, one entry for each interval
[index,quants] = quantiz(sig,partition,codebook); % Quantize.
plot(t,sig,'x',t,quants,'.')
legend('Original signal','Quantized signal');
axis([-.2 7 -1.2 1.2]
OUTPUT:
Original signal
Quantized signal
1
0.8
0.6
0.4
0.2
0
-0.2
-0.4
-0.6
-0.8
-1
0