Anda di halaman 1dari 32

CONTENTS

Topic

Page No.
1 3 4 6 8 11 13 15 17 18 19 20 21 22 24 26 28 29

1. Generation of unit impulse, unit step, unit ramp and sinusoidal signal 2. Generation of real exponential and logarithmic signal 3. Generation of complex exponential signal 4. Realization of sinc function 5. Shifting, scaling and folding of a discrete time sequence 6. Performing linear convolution 7. Discrete Fourier Transform 8. Verification of convolution property of DFT 9. Performing convolution using DFT 10. Realization of ASK Modulation 11. Realization of FSK Modulation 12. Realization of PSK Modulation 13. Realization of QPSK Modulation 14. Realization of OQPSK Modulation 15. Realization of CPFSK Modulation 16. Realization of MSK Modulation 17. Perform sampling of a continuous time signal 18. Realize ASK, FSK and PSK using Simulink

Experiment 1: To generate unit impulse, unit step unit ramp and sinusoidal signal using MATLAB. Program:
%Program to generate unit impulse, unit step, unit ramp and sine wave clear all close all clc t=-1:0.01:1; x_impulse=[zeros(1,100),1,zeros(1,100)]; x_step=[zeros(1,100),ones(1,101)]; x_ramp=[zeros(1,100),t(101:201)]; x_sin=sin(2*pi*3*t); subplot 221 plot(t,x_impulse) title('unit impulse') xlabel('t') ylabel('\delta (t)') axis([-1,1,-0.5,1.5]); subplot 222 plot(t,x_step) title('unit step') xlabel('t') ylabel('u(t)') axis([-1,1,-0.5,1.5]); subplot 223 plot(t,x_ramp) title('unit ramp') xlabel('t') ylabel('r(t)') axis([-1,1,-0.5,1.5]); subplot 224 plot(t,x_sin) title('sine wave') xlabel('t') ylabel('sin(t)')

Output:
unit impulse 1.5 1 1.5 1 u(t) 0.5 0 -0.5 -1 unit step

(t)

0.5 0 -0.5 -1

-0.5

-0.5

1.5 1 0.5 0 -0.5 -1 sin(t) -0.5 0 t 0.5 1 r(t)

1 0.5 0 -0.5 -1 -1

-0.5

0 t

0.5

Experiment 2: To generate real exponential and logarithmic signal using MATLAB Program:
%Logartihmic and Real Exponential clear all close all clc t=linspace(0,10); t1=linspace(-1,1); t2=linspace(1,5); a=1; w=1; x1=a*log(w*t); x2=a*exp(w*t1); subplot 211 plot(t,x1) title('Logarithmic Function x(t)=a log(wt)') xlabel('time') ylabel('magnitude') grid on subplot 212 plot(t1,x2) title('Exponential Function x(t)=a e^{wt}') xlabel('time') ylabel('magnitude') grid on

Output:
Logarithmic Function x(t)=a log(wt) 4 magnitude 2 0 -2 -4 0 1 2 3 4 5 time 6 7 8 9 10

1 0 -1

-0.8

-0.6

-0.4

-0.2

0 time

0.2

0.4

0.6

0.8

Experiment 3: Generation of Complex Exponential Signal Program:

clear all close all clc a=2; b=3; t=linspace(-3,3,600); x1=exp(complex(a,b)*t); x2=exp(complex(a,-b)*t); x3=exp(complex(-a,b)*t); x4=exp(complex(-a,-b)*t); subplot 421 plot(t,abs(x1)); xlabel('time') ylabel('Magnitude') title('Magnitude of x(t)=e^{(a+ib)t}') subplot 422 plot(t,angle(x1)/pi); xlabel('time') ylabel('phase/\pi') title('Phase of x(t)=e^{(a+ib)t}') subplot 423 plot(t,abs(x2)); xlabel('time') ylabel('Magnitude') title('Magnitude of x(t)=e^{(a-ib)t}') subplot 424 plot(t,angle(x2)/pi); xlabel('time') ylabel('phase/\pi') title('Phase of x(t)=e^{(a-ib)t}') subplot 425 plot(t,abs(x3)); xlabel('time') ylabel('Magnitude') title('Magnitude of x(t)=e^{(-a+ib)t}') subplot 426 plot(t,angle(x3)/pi); xlabel('time') ylabel('phase/\pi') title('Phase of x(t)=e^{(-a+ib)t}') subplot 427 plot(t,abs(x4)); xlabel('time') ylabel('Magnitude') title('Magnitude of x(t)=e^{(-a-ib)t}') subplot 428 plot(t,angle(x4)/pi); title('Phase of x(t)=e^{(-a-ib)t}') xlabel('time') ylabel('phase/\pi')

Output:

Experiment 4: To realize sinc function using MATLAB Theory:

Sinc function is defined as = sin

Where is in radian. In MATLAB, the library function sinc calculates the value of = sin

Program
% Program to generate a sinc signal clear all close all clc t=-10:0.1:10; for k=1:length(t) if(t(k)==0) x1(k)=1; else x1(k)=sin(pi*t(k))/(pi*t(k)); end end x2=sinc(t); subplot 211 plot(t,x1) title('Program output') xlabel('time') ylabel('Magnitude') subplot 212 plot(t,x2) title('Output using Sinc Function (in built)') xlabel('time') ylabel('Magnitude') disp('Maximum Error: ') max(abs(x1-x2))

Output:

Program output 1 1

Output using Sinc Function (in built)

0.8

0.8

0.6

0.6

Magnitude

0.2

Magnitude -5 0 time 5 10

0.4

0.4

0.2

-0.2

-0.2

-0.4 -10

-0.4 -10

-5

0 time

10

Experiment 5: To perform shifting, scaling and folding operation on a discrete time sequence. Theory:
Shifting, scaling and folding are operations on the time-scale of a signal. Shifting is performed to delay or advance the signal. Scaling is performed to vary the sampling rate (either over-sampling or under-sampling). Folding on the other hand is associated with time reversal. Shifting: x(n k) : delay the signal by k samples. x(n + k): advance the signal by k samples. Scaling: x(an), a > 1 : introduce (a-1) zeros between every pair samples so that the signal gets oversampled by a factor of a. x(an), a < 1 : Consider only those samples for which (a n) is an integer.

Folding: Folding is performed to reverse the time scale.

Program
%shift and scale positive time signal clear all close all clc x=[2 4 6 8 4 3 2 1]; L=length(x); n=0:L-1; %Folding yfl=fliplr(x); figure subplot 211 stem(n,x) title('Input') subplot 212 stem(n,yfl) title('Folded signal') %-------------------------------%Right Shifting (delaying) by k k=3;

yshr=[zeros(1,k),x]; nshr=[n,L+(0:k-1)]; %Left Shifting (advancing) by k yshl=[x,zeros(1,k)]; nshl=[-k:-1,n]; figure subplot 311 stem(n,x) title('Input') subplot 312 stem(nshr,yshr) title('Right-shifted signal') subplot 313 stem(nshl,yshl) title('Left-shifted signal') %---------------------------------%scale by a (undersampling) a=2; yscu=x(1:a:L); nscu=1:floor(L/a); %scaling by 1/a y=zeros(1,a*L); nsco=0:a*(L-1); k1=1; for k=1:a:a*L ysco(k)=x((k-1)/a+1); end figure subplot 311 stem(n,x) title('Input') subplot 312 stem(nscu,yscu) title('Undersampled signal') subplot 313 stem(nsco,ysco) title('Oversampled signal')

Output
Input 8 6 4 2 0

Folded signal 8 6 4 2 0

Input 10 5 0

Right-shifted signal 10 5 0

10

Left-shifted signal 10 5 0 -3

-2

-1

Input 10 5 0

Undersampled signal 10 5 0

1.5

2.5 Oversampled signal

3.5

10 5 0

10

12

14

10

Experiment 6: To perform linear convolution of two discrete time sequences using MATLAB Theory
Linear convolution is a very important operation in digital signal processing and communication. If x(n) be the input to a Linear Time Invariant (LTI) system with impulse response h(n) , then its output is given by the convolution of x(n) and h(n). Mathematically it can be written as = Convolution sum of two discrete time sequences x(n) and y(n) is defined as: =

If Lx be the length of x(n) and Lh be the length of h(n) then the number of non-zero terms in x(n)*h(n) is given by: = + 1

Program
%Program to convolution of two sequences (using matrix method) clear all close all clc x=input('Enter Input Sequence: '); xz=input('Enter zero position of input sequence:'); h=input('Enter Impulse Resonse: '); hz=input('Enter zero position of Impulse Resonse: '); lx=length(x); lh=length(h); l=lx+lh-1; nx=-xz+1:lx-xz; nh=-hz+1:lh-hz; x1=[x,zeros(1,lh)]; h1=[h,zeros(1,lx)]; y=zeros(1,l); for i=1:l for j=1:i; y(i)=y(i)+x1(j)*h1(i-j+1); end end y yz=xz+hz; ny=-(yz-1):l-(yz); conv(x,h) subplot 311 stem(nx,x); subplot 312

11

stem(nh,h) subplot 313 stem(ny,y)

Output
Input sequence 10 5 0 -2 10 5 0 -1 200 100 0 -4

-1.5

-1

-0.5

0.5

1.5

2.5

Impulse Response

-0.5

0.5

1.5

2.5

3.5

System output

-3

-2

-1

12

Experiment 7: To perform Discrete Fourier Transform (DFT) using MATLAB Theory:

Discrete Fourier Transform divides the frequency range = [0, 2] into N discrete samples. It is given by =

where k ranges from 0 to (N 1).

Program
% DFT_Using Transpose clear all close all clc N=input('Enter Length:'); x=input('Enter Sequence:'); N1=length(x); if(N>N1) x=[x,zeros(1,N-N1)]; elseif(N<N1) N=N1; end n=0:N-1; X=zeros(1,N); for k=1:N X(k)=X(k)+x*exp(-1i*2*pi*(k-1)*n/N)'; end disp('Input Sequence') x disp('Program Output') X disp('Result using fft function') X_ref=fft(x) Error=max(abs(abs(X_ref)-abs(X))) %Ploting Result X_mag=abs(X); X_phase=angle(X); subplot 311 stem(n,x) title('Input Sequence') subplot 312 stem(n,X_mag) title('Output Magnitude') subplot 313 stem(n,X_phase) title('Output Phase')

13

Result:

Input Sequence 10 0 -10

0.5

1.5

2.5

3.5

4.5

Output Magnitude 40 20 0

0.5

1.5

2.5

3.5

4.5

Output Phase 5 0 -5

0.5

1.5

2.5

3.5

4.5

14

Experiment 8: To verify convolution property of Discrete Fourier Transform.

Theory Convolution property of DFT states that if = and then, = =

Program
% Program to check that convolution in time domain is multiplication in % frequency domain clear all close all clc x=input('Enter 1st Sequence:'); y=input('Enter 2nd Sequence:'); lx=length(x); ly=length(y); %Performing convolution l=lx+ly-1; x1=[x,zeros(1,ly)]; y1=[y,zeros(1,lx)]; z1=zeros(1,l); for k1=1:l for k2=1:k1 z1(k1)=z1(k1)+x1(k2)*y1(k1-k2+1); end end % --------------------------------------------% Performing DFT of 1st sequence X=zeros(1,l); for k1=1:l for n1=1:l X(k1)=X(k1)+x1(n1)*exp(-1i*2*pi*(k1-1)*(n1-1)/l); end end % --------------------------------------------% Performing DFT of 2nd sequence Y=zeros(1,l); for k1=1:l for n1=1:l Y(k1)=Y(k1)+y1(n1)*exp(-1i*2*pi*(k1-1)*(n1-1)/l); end end % --------------------------------------------%Multiplying for k=1:l

15

Z(k)=X(k)*Y(k); end %IDFT z=zeros(1,l); for n1=1:l for k1=1:l z(n1)=z(n1)+Z(k1)*exp(1i*2*pi*(n1-1)*(k1-1)/l); end z(n1)=z(n1)/l; end disp('Result using Frequency domain multiplication') real(z) disp('Result using time domain convolution') z1

Output

16

Experiment 9: To perform convolution using DFT Program

%Convolution using DFT clear all close all clc x=input('Enter 1st Sequence:'); y=input('Enter 2nd Sequence:'); lx=length(x); ly=length(y); l=lx+ly-1; n=0:l-1; k=0:l-1; x1=[x,zeros(1,l-lx)]; y1=[y,zeros(1,l-ly)]; X1=x1*(exp(-2j*pi*n'*k/l)); Y1=y1*(exp(-2j*pi*n'*k/l)); Z=X1.*Y1; disp('Result using DFT:') z=(1/l)*Z*(exp(2j*pi/l)).^(k'*n) disp('Result using in-built function:') z1=conv(x,y) Error=max(abs(z1-z))

Output

17

Experiment 10: To realize amplitude shift keying (ASK) modulation using MATLAB. Program
%Program to generate ASK signal clear all; close all; clc; t=linspace(0,1); x1=sin(2*pi*3*t); b=input('Enter Bit Stream: '); l=length(b); Y=[]; X=[]; n=[]; for k=1:l n=[n,linspace(k-1,k)]; if(b(k)==0) X=[X,zeros(1,100)]; Y=[Y,zeros(1,100)]; elseif(b(k)==1) X=[X,ones(1,100)]; Y=[Y,x1]; else disp(['Error:',num2str(b(k)),' is not a bit']); return; end end subplot 211 plot(n,X) title('Input Sequence') subplot 212 plot(n,Y); title('Output ASK Sequenct')

Output
Input Sequence 1.5 1 0.5 0 -0.5

Output ASK Sequenct 1 0.5 0 -0.5 -1

18

Experiment 11: To realize frequency shift keying (FSK) modulation using MATLAB. Program
%Program to generate FSK signal clear all; close all; clc; t=linspace(0,1); x1=sin(2*pi*2*t); x2=sin(2*pi*4*t); b=input('Enter Bit Stream: '); l=length(b); Y=[]; X=[]; n=[]; for k=1:l n=[n,linspace(k-1,k)]; if(b(k)==0) X=[X,zeros(1,100)]; Y=[Y,x1]; elseif(b(k)==1) X=[X,ones(1,100)]; Y=[Y,x2]; else disp(['Error:',num2str(b(k)),' is not a bit']); return; end end subplot 211 plot(n,X) axis([0,l,-0.5,1.5]); title('Input Sequence') subplot 212 plot(n,Y); title('Output FSK Sequenct')

Output
Input Sequence 1.5 1 0.5 0 -0.5

Output FSK Sequenct 1 0.5 0 -0.5 -1

19

Experiment 12: To realize phase shift keying (PSK) modulation using MATLAB. Program:
%Program to generate PSK signal clear all; close all; clc; t=linspace(0,1); x1=sin(2*pi*3*t); b=input('Enter Bit Stream: '); l=length(b); Y=[]; X=[]; n=[]; for k=1:l n=[n,linspace(k-1,k)]; if(b(k)==0) X=[X,zeros(1,100)]; Y=[Y,-x1]; elseif(b(k)==1) X=[X,ones(1,100)]; Y=[Y,x1]; else disp(['Error:',num2str(b(k)),' is not a bit']); return; end end subplot 211 plot(n,X) axis([0,l,-0.5,1.5]); title('Input Sequence') subplot 212 plot(n,Y); title('Output PSK Sequenct')

Output:
Input Sequence 1.5 1 0.5 0 -0.5

Output PSK Sequenct 1 0.5 0 -0.5 -1

20

Experiment 13: To realize quadri-phase shift keying (QPSK) modulation using MATLAB. Program
%Program to generate QPSK signal %s1=10, s2=00, s3=01, s4=11 clear all; close all; clc; t=linspace(0,1,200); b=input('Enter Bit Stream: '); l=length(b); sym=[2 3 1 4]; Y=[]; X=[]; n=[]; if(mod(l,2)~=0) b=[b,0]; l=l+1; end for k=1:2:l X=[X,b(k)*ones(1,100),b(k+1)*ones(1,100)]; n=[n,linspace(k-1,k+1,200)]; z=sym(b(k)*2+b(k+1)+1); x1=cos(2*pi*3*t+(2*z-1)*pi/4); Y=[Y,x1]; end subplot 211 plot(n,X) title('Input Sequence') subplot 212 plot(n,Y) title('Output PSK Sequenct')

Output
Input Sequence 1.5 1 0.5 0 -0.5

Output PSK Sequenct 1 0.5 0 -0.5 -1

21

Experiment 14: To realize orthogonal quadri-phase shift keying (OQPSK) modulation using MATLAB. Program
%Program to implement QPSK using IP/QP approach clear all close all clc t=linspace(0,2,200); b=input('Enter Bit Stream: '); l=length(b); phi1=cos(2*pi*3*t); phi2=sin(2*pi*3*t); sym=[2 3 1 4]; if(mod(l,2)~=0) b=[b,0]; l=l+1; end X=[]; Y=[]; n=[]; Yi=[]; Yq=[]; temp=zeros(1,100); for k=1:2:l X=[X,b(k)*ones(1,100),b(k+1)*ones(1,100)]; n=[n,linspace(k-1,k+1,200)]; z=sym(b(k)*2+b(k+1)+1); s1=cos((2*z-1)*pi/4); s2=sin((2*z-1)*pi/4); x1=s1*phi1-[temp,s2*phi2(1:100)]; Y=[Y,x1]; Yi=[Yi,s1*phi1]; Yq=[Yq,[temp,s2*phi2(1:100)]]; temp=s2*phi2(101:200); end subplot 211 plot(n,X) title('Input Sequence') axis([0,l,-0.5,1.5]); subplot 212 plot(n,Y) title('Output PSK Sequenct') figure subplot 311 plot(n,X) title('Input Sequence') subplot 312 plot(n,Yi); title('In-Phase Component') subplot 313 plot(n,Yq); title('Quad-Phase Component')

22

Output
Input Sequence 1.5 1 0.5 0 -0.5

Input Sequence 1.5 1 0.5 0 -0.5 0 1 2 3 4 5 6 7 8

In-Phase Component 1 0 -1

23

Experiment 15: To realize continuous phase frequency shift keying (CPFSK) modulation using MATLAB. Program
%Program to perform CPFSK clear all close all clc x=input('Enter the bit-stream: '); Tb=input('Enter Tb value: '); l=length(x); % t=linspace(0,l-1,l*100); f1=5; f2=3; fc=(f1+f2)/2; h=(f1-f2)/2; x1=[]; t=[]; for z=1:l t1=linspace(0 ,1)+(z-1); t=[t,t1]; if(x(z)==1) x1=[x1,ones(1,100)]; theta((z-1)*100+1:z*100)=pi*h*t1/Tb; elseif(x(z)==0) x1=[x1,zeros(1,100)]; theta((z-1)*100+1:z*100)=-pi*h*t1/Tb; else disp('error'); return end Xmsk((z-1)*100+1:z*100)=cos(2*pi*fc*t1+theta((z-1)*100+1:z*100)); end subplot 311 plot(t,x1) axis([0,l,-0.5,1.5]); title('Input Sequence') subplot 312 plot(t,theta) title('Phase Shift') subplot 313 plot(t,Xmsk) title('CPFSK Output')

24

Output

Phase Shift 100 0 -100

CPFSK Output 1 0 -1

25

Experiment 16: To realize minimum shift keying (MSK) modulation using MATLAB. Program
%Program to perform MSK clear all close all clc x=input('Enter the bit-stream: '); Tb=input('Enter Tb value: '); l=length(x); % t=linspace(0,l-1,l*100); f1=5; f2=2; fc=(f1+f2)/2; h=1/2; x1=[]; t=[]; for z=1:l t1=linspace(0 ,1)+(z-1); t=[t,t1]; if(x(z)==1) x1=[x1,ones(1,100)]; theta((z-1)*100+1:z*100)=pi*h*t1/Tb; elseif(x(z)==0) x1=[x1,zeros(1,100)]; theta((z-1)*100+1:z*100)=-pi*h*t1/Tb; else disp('error'); return end Xmsk((z-1)*100+1:z*100)=cos(2*pi*fc*t1+theta((z-1)*100+1:z*100)); end subplot 311 plot(t,x1) axis([0,l,-0.5,1.5]); title('Input Sequence') subplot 312 plot(t,theta) title('Phase Shift') subplot 313 plot(t,Xmsk) title('CPFSK Output')

26

Output
Input Sequence 1.5 1 0.5 0 -0.5 0 1 2 3 4 5 6 7

Phase Shift 20 0 -20

CPFSK Output 1 0 -1

27

Experiment 17: To sample a continuous time signal Program:

%My Program to test sampling clear all close all clc t=linspace(0,1); l=length(t); x=sin(2*pi*3*t)+sin(2*pi*5*t); Fs=[6,10,20]; for k=1:3 Ts=1/Fs(k) Ns=l*Ts/(t(l)-t(1)); xn=x(1:Ns:l); n=t(1:Ns:l); subplot(3,1,k) plot(t,x); hold on stem(n,xn) hold off grid on title('') xlabel('time') ylabel('amplitude') if k==1 title('Under-sampling') elseif k==2 title('Nyquist Rate-sampling') elseif k==3 title('Over-sampling') end end

Output
Under-sampling amplitude 2 0 -2 0 0.1 0.2 0.3 0.5 0.6 0.7 time Nyquist Rate-sampling 0.4 0.8 0.9 1

amplitude

2 0 -2 0 0.1 0.2 0.3 0.4 0.5 0.6 time Over-sampling 0.7 0.8 0.9 1

amplitude

2 0 -2 0 0.1 0.2 0.3 0.4 0.5 time 0.6 0.7 0.8 0.9 1

28

Block

Scope

29

2. FSK
Block

Scope

30

3. PSK
Block:

Scope

31