Generation of Basic Signals: AIM: To Write A MATLAB Program To Generate Various Type of Signals. Algorithm
Generation of Basic Signals: AIM: To Write A MATLAB Program To Generate Various Type of Signals. Algorithm
Generation of Basic Signals: AIM: To Write A MATLAB Program To Generate Various Type of Signals. Algorithm
Progm 1
GENERATION OF BASIC SIGNALS
AIM: To write a MATLAB program to generate various type of signals.
ALGORITHM:
PROGRAM:
clc;
clear all;
close all;
stem(t3,y3);
ylabel('Amplitude---->');
xlabel('(c)n---->');
OUTPUT:
Dr.A.I.T. Medical Electronics--2010 2
Digital Signal Processing Lab Manual Prof. SHIVASHANKAR and JAYANTHI. G
Progm 2
VERIFICATION OF SAMPLING THEOREM
AIM: To write a MATLAB program to verify sampling theorem.
ALGORITHM:
PROGRAM:
clc;
clear all;
close all;
%critical sampling
f=1400;
t=0:1/f:13/f;
x=cos(2*pi*400*t)+cos(2*pi*700*t);
Xm=abs(fft(x));
n=0:length(x)-1;
figure(1)
stem(100*n,Xm),grid,zoom;
xlabel('frequency'); ylabel('magnitude');
title('criticle sampling');
%under sampling
f=700;
t=0:1/f:6/f;
x=cos(2*pi*400*t)+cos(2*pi*700*t);
Xm=abs(fft(x));
k=0:length(x)-1;
figure(2)
stem(100*k,Xm),grid,zoom;
xlabel('frequency'); ylabel('magnitude');
title('under sampling');
%over sampling
f=2000;
t=0:1/f:27/f;
x=cos(2*pi*400*t)+cos(2*pi*700*t);
Dr.A.I.T. Medical Electronics--2010 4
Digital Signal Processing Lab Manual Prof. SHIVASHANKAR and JAYANTHI. G
Xm=abs(fft(x));
k=0:length(x)-1;
figure(3)
stem(100*k,Xm),grid,zoom;
xlabel('frequency'); ylabel('magnitude');
title('over sampling');
OUTPUT:
Progm 3
LINEAR CONVOLUTION OF TWO GIVEN
SEQUENCES
ALGORITHM:
PROGRAM:
stem(h);
ylabel('Amplitude---->');
xlabel('time---->');
title('h(n)');
subplot(2,2,3);
stem(y);
ylabel('Amplitude---->');
xlabel('time---->');
title('y(n)');
Dr.A.I.T. Medical Electronics--2010 7
Digital Signal Processing Lab Manual Prof. SHIVASHANKAR and JAYANTHI. G
z=deconv(y,h);
subplot(2,2,4);
stem(z);
ylabel('Amplitude---->');
xlabel('time---->');
title('z(n)');
disp('The deconvoluted signal is:');z
OUTPUT:
y=
1 3 3 3 3 -3 -10
z=
1 2 3 4 5
Progm 4
ALGORITHM:
PROGRAM:
j=N+j;
end
y(n)=y(n)+g(i)*h(j);
end
end
subplot(3,2,1);
stem(g);
ylabel('Amplitude---->');
xlabel('time---->');
title(‘I signal’);
subplot(3,2,2);
stem(h);
ylabel('Amplitude---->');
xlabel('time---->');
title(`II signal’);
subplot(3,2,3);
stem(y);
ylabel('Amplitude---->');
xlabel('timen---->');
title('circular conv signal');
disp('The resultant signal is; ');y
OUTPUT:
PROGRAM:
x1=input('Enter the first seq');
x2=input('Enter the sec seq');
l1=length(x1);
l2=length(x2);
N=max(l1,l2);
a=fft(x1,N)
b=fft(x2,N)
c=a.*b
y=ifft(c,N);
disp('CIRCULAR CONVOLUTION');
y
disp([]);
pause
n=0:1:N-1;
stem(n,y);
xlabel('Time index n');
Dr.A.I.T. Medical Electronics--2010 11
Digital Signal Processing Lab Manual Prof. SHIVASHANKAR and JAYANTHI. G
ylabel('Amplitude');
title('CIRCULAR CONVOLUTION');
Progm 5
ALGORITHM:
y(n) = x(n) N
h(n)
PROGRAM:
%cross correlation
x=[5,1,3];
h=[1,2,3];
b1=xcorr(x,h);
y1=abs(b1);
disp(y1)
subplot(1,2,1);
stem(y1,'r');
ylabel('Amplitude');
xlabel('Time');
title('Cross Correlation');
% auto correlation
b2=xcorr(x,x);
y2=abs(b2);
disp(y2)
subplot(1,2,2);
stem(y2);
ylabel('Amplitude');
xlabel('Time');
title('Auto Correlation');
OUTPUT:
Progm 6
ALGORITHM:
5. The linear and circular convoluted signal using fft algorithm is calculated
6. Plot them using ‘stem’ function.
7. End the program.
PROGRAM:
%circular convolution
P=max(length(x1),length(x2));
X1=fft(x1,P);
X2=fft(x2,P);
Yc=X1.*X2;
Ycir=ifft(Yc);
disp('the circular convolution of x1(n) and x2(n) using fft()')
disp('and ifft() yeilds the result:');
disp(Ycir);
OUTPUT:
Progm 7
ALGORITHM:
5. The linear and circular convoluted signal using fft algorithm is calculated and is
denoted as ylin2 and yc respectively.
6. Plot them using ‘stem’ function.
7. End the program.
PROGRAM: OUTPUT:
clear all; 8 8
close all; 7 7
6 6
%folded signal
x=[2,5,6,7,8,3]; 5 5
n=0:5; 4 4
subplot(1,2,1); 3 3
stem(n,x);
title('ORIGINAL SIGNAL'); 2 2
subplot(1,2,2); 1 1
stem(-n,x);
0 0
title('FOLDED SIGNAL'); 0 2 4 6 -6 -4 -2 0
OUTPUT:
Enter the sequence: [1,2,3,4]
Enter the shifting value: 2
X[n+k] X[n-k]
4 4
3 3
2 2
1 1
0 0
-2 -1 0 1 2 3 4 5
X[-n+k] X[-n-k]
4 4
3 3
2 2
1 1
0 0
Dr.A.I.T. -5 -4 -3 Medical
-2 Electronics-
-1 -2010
0 1 2 17
Digital Signal Processing Lab Manual Prof. SHIVASHANKAR and JAYANTHI. G
Progm 7
ALGORITHM:
PROGRAM:
OUTPUT:
ALGORITHM:
PROGRAM:
ylabel('Amplitude---->');
xlabel('(c)n---->');
disp('The resultant signal is:');y
OUTPUT:
Progm 8
ALGORITHM:
PROGRAM: (A)
num=[2,-3.4,1.5];
den=[1,-1.6,.8];
[h,t]=impz(num,den);
figure(1);
subplot(1,2,1);
stem(t,h);
title('Impulse response');
ns=ones(1,20);
y=filter(num,den,ns);
subplot(1,2,2);
stem(y);
title('Step response');
figure(2);
freqz(num,den);
title('Frequency response');
OUTPUT:
Impulse response Step response
2 2
1.5
1.5
1
1
0.5
0.5
0
Frequency response
20
0
-0.5
Magnitude (dB)
10
-1 -0.5
0 50 100 0 5 10 15 20
0
-10
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1
Normalized Frequency ( rad/sample)
100
Phase (degrees)
50
a = [1 -0.9];
b = 0.1;
n = input('Enter number of points for impulse response');
w = input('Enter number of points for frequency response:');
figure(1);
[h,t] = impz(b,a,n);
stem(t,h);
title('Impulse response of given system');
figure(2);
freqz(b,a,w);
title('Frequency response of givenImpulse
system');
response of given system
0.1
0.09
OUTPUT:
0.08
Enter number of points for impulse response10
Enter
0.07 number of points for frequency response:10
0.06
0.05
0.04
0.03
0.02
0.01
Dr.A.I.T. Medical Electronics--2010 24
0
0 1 2 3 4 5 6 7 8 9
Digital Signal Processing Lab Manual Prof. SHIVASHANKAR and JAYANTHI. G
-10
-20
-30
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1
Normalized Frequency ( rad/sample)
0
Phase (degrees)
-20
-40
-60
-80
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1
Normalized Frequency ( rad/sample)
(C) y(n)+0.6y(n-1)=3x(n)+x(n-1);
a = [1 0.6];
b = [3 1];
n = input('Enter number of points for impulse response:');
w = input('Enter number of points for frequency response:');
figure(1);
[h,t] = impz(b,a,n,5);
stem(t,h);
title('Impulse response of given system');
figure(2);
freqz(b,a,w);
title('Frequency response of given system');
OUTPUT:
2.5
Frequency response of given system
14
2
Magnitude (dB)
12
1.5
10
1
8
0.5
6
0 0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1
Normalized Frequency ( rad/sample)
-0.5
20
-1
Phase (degrees)
10
Progm 7
ALGORITHM:
PROGRAM:
y=hamming(n1);
%lowpass filter
b=fir1(n,wp,y);
[h,om]=freqz(b,1,256);
m=20*log10(abs(h));
subplot(2,2,1);
plot(om/pi,m);
ylabel('Gain in dB---->');
xlabel('Frequency in rad/sec---->');
%highpass filter
b=fir1(n,wp,'high',y);
[h,om]=freqz(b,1,256);
m=20*log10(abs(h));
subplot(2,2,2);
plot(om/pi,m);
ylabel('Gain in dB---->');
xlabel('Frequency in rad/sec---->');
%bandpass filter
wn=[wp ws];
b=fir1(n,wn,y);
[h,om]=freqz(b,1,256);
m=20*log10(abs(h));
subplot(2,2,3);
plot(om/pi,m);
ylabel('Gain in dB---->');
Dr.A.I.T. Medical Electronics--2010 28
Digital Signal Processing Lab Manual Prof. SHIVASHANKAR and JAYANTHI. G
xlabel('Frequency in rad/sec---->');
%bandstop filter
b=fir1(n,wn,'stop',y);
[h,om]=freqz(b,1,256);
m=20*log10(abs(h));
subplot(2,2,4);
plot(om/pi,m);
ylabel('Gain in dB---->');
xlabel('Frequency in rad/sec---->');
OUTPUT:
n=
26
ALGORITHM:
PROGRAM:
clc;
close all;
clear all;
rp=input('Enter the passband ripple: ');
rs=input('Enter the stopband ripple: ');
fp=input('Enter the passband frequency: ');
fs=input('Enter the stopband frequency: ');
f=input('Enter the sampling frequency: ');
beta=input('Enter the beta value: ');
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
disp('The order is:');n
y=kaiser(n1,beta);
%lowpass filter
b=fir1(n,wp,y);
[h,om]=freqz(b,1,256);
m=20*log10(abs(h));
subplot(2,2,1);
plot(om/pi,m);
ylabel('Gain in dB---->');
xlabel('Frequency in rad/sec---->');
%highpass filter
b=fir1(n,wp,'high',y);
[h,om]=freqz(b,1,256);
m=20*log10(abs(h));
subplot(2,2,2);
plot(om/pi,m);
Dr.A.I.T. Medical Electronics--2010 31
Digital Signal Processing Lab Manual Prof. SHIVASHANKAR and JAYANTHI. G
ylabel('Gain in dB---->');
xlabel('Frequency in rad/sec---->');
%bandpass filter
wn=[wp ws];
b=fir1(n,wn,y);
[h,om]=freqz(b,1,256);
m=20*log10(abs(h));
subplot(2,2,3);
plot(om/pi,m);
ylabel('Gain in dB---->');
xlabel('Frequency in rad/sec---->');
%bandstop filter
b=fir1(n,wn,'stop',y);
[h,om]=freqz(b,1,256);
m=20*log10(abs(h));
subplot(2,2,4);
plot(om/pi,m);
ylabel('Gain in dB---->');
xlabel('Frequency in rad/sec---->');
OUTPUT:
n=
26
ALGORITHM:
PROGRAM:
OUTPUT:
-50
-100
-150
0 50 100 150 200 250 300 350 400 450 500
Frequency
0
P h a s e (d e g re e s )
-100
-200
-300
0 50 100 150 200 250 300 350 400 450 500
Frequency (Hz)
OUTPUT:
-100
Gain in dB
-200
-300
0 50 100 150 200 250 300 350 400 450 500
Frequency
-100
Phase (degrees)
-200
-300
-400
-500
0 50 100 150 200 250 300 350 400 450 500
Frequency (Hz)
Dr.A.I.T. Medical Electronics--2010 35
Digital Signal Processing Lab Manual Prof. SHIVASHANKAR and JAYANTHI. G
OUTPUT:
-100
Gain in dB
-200
-300
0 50 100 150 200 250 300 350 400 450 500
Frequency
100
0
Phase (degrees)
-100
-200
-300
-400
0 50 100 150 200 250 300 350 400 450 500
Frequency (Hz)
OUTPUT:
Enter the sampling freq2000
Enter the lower cut off freq300
Enter the upper cut off freq500
Enter the order of the filter3
Enter the ripple factor17
-50
Gain in dB
-100
-150
-200
0 100 200 300 400 500 600 700 800 900 1000
Frequency
0
Phase (degrees)
-200
-400
-600
-800
0 100 200 300 400 500 600 700 800 900 1000
Frequency (Hz)
[n,wn]=BUTTORD(wp,ws,rp,rs);
[b,a]=BUTTER(n,wn,'high');
w=0:.01:pi;
[h,w]=FREQZ(b,a,w,'whole');
m=20*log10(abs(h));
an=angle(h);
subplot(2,1,1),plot(w/pi,m);
grid
xlabel('normalised frequency');
ylabel('gain in db');
title('magnitude response');
subplot(2,1,2), plot(w/pi,an);
grid;
xlabel('normalised frequency');
ylabel('phase in radian');
title('phase response');
OUTPUT: