Dsp Lab Manual

32
(Affiliated to Kurukshetra University Kurukshetra) (Approved by AICTE, New Delhi) Practical Report On MATLAB (DIGITAL SIGNAL PROCESSING LAB) ECE-490E Submitted for partial fulfillment Of B. Tech. in ELECTRONICS AND COMMUNICATION ENGINEERING

Transcript of Dsp Lab Manual

Page 1: Dsp Lab Manual

(Affiliated to Kurukshetra University Kurukshetra)(Approved by AICTE, New Delhi)

Practical ReportOn

MATLAB (DIGITAL SIGNAL PROCESSING LAB)

ECE-490E

Submitted for partial fulfillmentOf B. Tech. in

ELECTRONICS AND COMMUNICATION ENGINEERING

SUBMITTED TO: SUBMITTED BY:

Er. Naresh Kumar Rashi GuptaH.O.D. ECE Department 4309102

ECE 3rd Year

Page 2: Dsp Lab Manual

INDEX

S.NO. EXPERIMENT NAME DATE PAGE NO.

SIGNATURE

1.

2.

3.

4.

5.

6.

7.

8.

9.

10.

Page 3: Dsp Lab Manual

EXPERIMENT-1

AIM: - Write a program to plot the following functions : a)impulse function

b)unit step c)unit ramp d) exponential e) sinusoidal.

REQUIREMENT: - Computer installed with MATLAB 7.1

PROGRAM CODE: -

t=(-1:.01:1);%range for time or division of x-axis

%To plot unit step

z=[zeros(100,1);ones(101,1)];

subplot(4,1,2);

stem(t,z);

xlabel('time');

ylabel('amp');

title('Fig-2 unit STEP Signal');

%To plot sin wave

x1=sin(2*pi*10*t);

subplot(4,1,4);

plot(t,x1);

xlabel('time');

ylabel('amp');

title('Fig-4 SIN Signal');

%To plot unit impulse signal

y=[zeros(100,1); 1 ;zeros(100,1)];

subplot(4,1,1);

stem(t,y);

xlabel('time');

Page 4: Dsp Lab Manual

ylabel('amp');

title('Fig-1 unit IMPLUSE Signal');

%To plot Ramp signal

subplot(4,1,3);

plot(t,t);

xlabel('time');

ylabel('amp');

title('Fig-3 RAMP Signal');

OUTPUT:

RESULT: - The Plot of various standard signals has been studied using MATLAB program.

Page 5: Dsp Lab Manual

EXPERIMENT-2

AIM: - To study the Modulation Process.

REQUIREMENT: - Computer installed with MATLAB 6.1

PROGRAM CODE: -

n=-10:1:10;

k=0:1:99;

f=10/158;

x=10-abs(n);

X=x*(exp(-j*2*pi/100).^(n'*k));

c=cos(2*pi*f*n);

z=x.*c;

Z=z*(exp(-j*2*pi/100).^(n'*k));

y=1/2*((exp(-j*2*pi*f*n).*x)+(exp(j*2*pi*f*n).*x));

Y=y*(exp(-j*2*pi/100).^(n'*k));

Error=Y-Z;

subplot(2,4,1);

stem(n,x);

title('Modulating Function');

xlabel('Time');

ylabel('Values');

subplot(2,4,2);

stem(k,X);

title('DFT of Modulating Function');

xlabel('Time');

ylabel('Values');

Page 6: Dsp Lab Manual

subplot(2,4,3);

plot(n,c);

title('CarrierFunction');

xlabel('Time');

ylabel('Values');

subplot(2,4,4);

stem(n,z);

title('Modulated Function');

xlabel('Time');

ylabel('Values');

subplot(2,4,5);

stem(k,Z);

title('DFT of Modulated Function');

xlabel('Time');

ylabel('Values');

subplot(2,4,6);

stem(n,y);

title('Modulated Function in exponential form');

xlabel('Time');

ylabel('Values');

subplot(2,4,7);

stem(k,Y);

title('DFT of Modulated Function in exponential form');

xlabel('Time');

ylabel('Values');

subplot(2,4,8);

Page 7: Dsp Lab Manual

stem(k,Error);

title('Error Plot');

xlabel('Time');

ylabel('Values');

GRAPHS: -

Graphs for the Process of Modulation

RESULT: - The Modulation Process has been studied using a MATLAB program.

EXPERIMENT: 3

Page 8: Dsp Lab Manual

AIM: - To study the Aliasing Effect.

REQUIREMENT: - Computer installed with MATLAB 6.1

PROGRAM CODE: -n=0:1:99;

f=5/158;

f1=1/158;

f2=10/158;

f3=50/158;

x=sin(2*pi*f*n);

c1=cos(2*pi*f1*n);

c2=cos(2*pi*f2*n);

c3=cos(2*pi*f3*n);

y1=x.*c1;

y2=x.*c2;

y3=x.*c3;

subplot(4,2,1);

plot(n,x);

title('Modulating Function');

xlabel('Values');

ylabel('Amplitude');

subplot(4,2,2);

plot(n,c1);

title('Carrier Function 1');

xlabel('Values');

ylabel('Amplitude');

Page 9: Dsp Lab Manual

subplot(4,2,3);

plot(n,c2);

title('Carrier Function 2');

xlabel('Values');

ylabel('Amplitude');

subplot(4,2,4);

plot(n,c3);

title('Carrier Function 3');

xlabel('Values');

ylabel('Amplitude');

subplot(4,2,5);

plot(n,y1);

title('Frequency<Nyquest Rate (aliasing)');

xlabel('Values');

ylabel('Amplitude');

subplot(4,2,6);

plot(n,y2);

title('Frequency=Nyquest Rate');

xlabel('Values');

ylabel('Amplitude');

subplot(4,2,7);

plot(n,y3);

title('Frequency>Nyquest Rate( no aliasing)');

xlabel('Values');

ylabel('Amplitude');

Page 10: Dsp Lab Manual

GRAPHS: -

Graphs for the Aliasing Effect

RESULT: - The Aliasing Effect has been studied.

EXPERIMENT-4

Page 11: Dsp Lab Manual

AIM: - Write a program to find the DFT of the sequence

REQUIREMENT: - Computer installed with MATLAB 7.1

PROGRAM CODE: -

clear all;x=[1 1 1 ]; %Given sequenceN=50;L=length(x);if(N<L) error('N must be less than L');end;x1=[x,zeros(1,N-L)]; %Appending of Zerosj = sqrt(-1); for k=0:N-1 %twiddle factor calculation for n=0:N-1 W=exp(-j*2*pi*n*k/N); x2(k+1 ,n+1)= W; endend X=x1*x2.'; %Computation of DFT by Dot product of Twiddle factor matrix & sequence magx=abs(X); anglex=angle(X); k=0:N-1; %To plot Mag. & Angle of output sequence subplot(2,1,1); stem(k,magx); xlabel('k'); ylabel('Mod of X'); title('Fig-1(a)Magnitude plot'); subplot(2,1,2); stem(k,anglex); xlabel('k'); ylabel('Angle of X'); title('Fig-1(b)Phase plot');

Page 12: Dsp Lab Manual

OUTPUT:

RESULT: - The DFT of the given discrete signal can be find out correctly with the help of this program code, it is checked with the help of above graphical results and manual calculations.

Page 13: Dsp Lab Manual

EXPERIMENT-5

AIM: - Write a program to plot the IDFT of a Sequence.

REQUIREMENT: - Computer installed with MATLAB 7.1

PROGRAM CODE: -

%To compute

clear all;

xk=[6,2i-2,-2,-2i-2]; %given Sequence

N=length(xk); %function to find length of sequence

for k=0:1:N-1 %loop from 0 to length(xk)-1

for n=0:1:N-1 %loop from 0 to length(xk)-1

p=exp(i*2*pi*n*k/N); %twiddle factor

x2(k+1,n+1)=p; %twiddle factor matrix

end %end of loop 1

end %end of loop 2

xn=((xk*x2.')./N); % Computation of IDFT

magx=abs(xn); %To compute Magnitude

anglex=angle(xn); % To compute angle

%To plot the Magnitude and Angle of a sequence

k=0:N-1;

subplot(2,1,1);

stem(k,magx);

xlabel('k');

ylabel('Mod of X');

title('Fig-1(a)Magnitude plot');

subplot(2,1,2);

Page 14: Dsp Lab Manual

stem(k,anglex);

xlabel('k');

ylabel('Angle of X');

title('Fig-1(b)Phase plot');

OUTPUT:

Result: The IDFT of the given DFT signal can be find out correctly with the help of this program code, it is checked with the help of above graphical results and manual calculations.

Page 15: Dsp Lab Manual

EXPERIMENT-6

AIM: - Write a program to study of Windows.

REQUIREMENT: - Computer installed with MATLAB 7.1

PROGRAM CODE: -N=64;

n=[0:1:N-1];

% Study of Rectangular Window

Wr=rectwin(N);

% Bartlett Window(Triangular Window

Wb=triang(N);

% Hamming Window

Wh=hamming(N);

% Blackman Window

Wbl=Blackman(N);

subplot(2,1,1),plot(n,Wr,n,Wb,n,Wh,n,Wbl);grid

legend('Rectangular','Bartlett','Hamming','Blackman',4);

xlabel('n');

ylabel('Amplitude');

title('Window Characteristics');

Wrdb=20*log(Wr);

Wbdb=20*log(Wb);

Whdb=20*log(Wh);

Wbldb=20*log(Wbl);

subplot(2,1,2),plot(n,Wrdb,n,Wbdb,n,Whdb,n,Wbldb);grid

legend('Rectangular','Bartlett','Hamming','Blackman',4);

Page 16: Dsp Lab Manual

xlabel('n');

ylabel('Amplitude in db');

title('Window Characteristics in db');

OUTPUT:

Result: The various windows have been studied with the help of the above program code in this experiment.

Page 17: Dsp Lab Manual

Experiment: 7

AIM: To design Butterworth Band Pass Filter.

clear all;

alphap=2; %Passband Attenuation in db

alphas=20; %Passband Attenuation in db

wp=[.2*pi,.4*pi %Passband Frequency In Radian

ws=[.1*pi,.5*pi %Stopband Frequency In Radian

[n,wn]=buttord(wp/pi,ws/pi,alphap,alphas);

[b,a]=butter(n,wn); %To design Butterworth filter

w=0.1:.01:pi;

[h,om]=freqz(b,a,w); %Returns the frequency response

vector h calculated

%at the frequencies (in radians per sample) supplied by the vector w

% To plot the Response w.r.t Normalized Freq.

m=20*log(abs(h));

an=angle(h);

subplot(2,1,1);

plot(om/pi,m);

grid;

Ylabel('Gain in DBn');

Xlabel('Normalized Freq.');

subplot(2,1,2);

plot(om/pi,an);

grid;

Ylabel('Phase in Radia');

Xlabel('Normalized Freq.');

Page 18: Dsp Lab Manual

Output:

RESULT: - The Plot of Butterworth Band Pass Filter has been studied using MATLAB

program.

Page 19: Dsp Lab Manual

Experiment: 8

AIM: To design Butterworth bandreject Filter

clear all;

alphap=2; %Passband Attenuation in db

alphas=20; %Passband Attenuation in db

wp=[.2*pi,.4*pi]; %Passband Frequency In Radian

ws=[.1*pi,.5*pi]; %Stopband Frequency In Radian

[n,wn]=buttord(wp/pi,ws/pi,alphap,alphas);%Function for Filter for order and cutoff freq.

[b,a]=butter(n,wn,'stop'); %To design Butterworth filter

w=0.1:.01:pi;

[h,om]=freqz(b,a,w); %Returns the frequency response

vector h calculated

%at the frequencies (in radians per sample) supplied by the vector w

% To plot the Response w.r.t Normalized Freq

m=20*log(abs(h));

an=angle(h);

subplot(2,1,1);

plot(om/pi,m);

grid;

Ylabel('Gain in DBn');

Xlabel('Normalized Freq.');

subplot(2,1,2);

plot(om/pi,an);

grid;

Ylabel('Phase in Radia');

Xlabel('Normalized Freq.');

Page 20: Dsp Lab Manual

Output:-

RESULT: - The Plot of Butterworth Band Reject Filter has been studied using

MATLAB program.

Page 21: Dsp Lab Manual

Experiment: 9

AIM: To design Butterworth High Pass Filter

clear all;

alphap=.2;%Passband Attenuation in db

alphas=30;%Passband Attenuation in db

fp=400;%Passband Frequency In Hz

fs=800;%Stopband Frequency In Hz

F=2000;%Sampling Frequency In Hz

omp=2*fp/F;% Frequency in Radians

oms=2*fs/F;% Frequency in Radians

[n,wn]=buttord(omp,oms,alphap,alphas);%Function for Filter

[b,a]=butter(n,wn,'high');

w=0:.01:pi;

[h,om]=freqz(b,a,w); %Returns the frequency response vector h calculated

%at the frequencies (in radians per sample) supplied by the vector w

% To plot the Response w.r.t Normalized Freq

m=20*log(abs(h));

an=angle(h);

subplot(2,1,1);

plot(om/pi,m);

grid;

Ylabel('Gain in DB');

Xlabel('Normalized Freq.');

subplot(2,1,2);

plot(om/pi,an);

grid;

Ylabel('Phase in Radian');

Page 22: Dsp Lab Manual

Xlabel('Normalized Freq.');

Output:-

RESULT: - The Plot of Butterworth High Pass Filter has been studied using MATLAB

program.

Page 23: Dsp Lab Manual

Experiment: 10

AIM:To design Butterworth Low Pass Filter.

clear all;

alphap=2;%Passband Attenuation in db

alphas=20;%Passband Attenuation in db

fp=400;%Passband Frequency In Hz

fs=800;%Stopband Frequency In Hz

F=2000;%Sampling Frequency In Hz

omp=2*fp/F;% Frequency in Radians

oms=2*fs/F;% Frequency in Radians

[n,wn]=buttord(omp,oms,alphap,alphas);%Function for Filter

[b,a]=butter(n,wn);

w=0:.01:pi;

[h,om]=freqz(b,a,w,'whole'); %Returns the frequency response vector h calculated

%at the frequencies (in radians per sample) supplied by the vector w

% To plot the Response w.r.t Normalized Freq

m=20*log(abs(h));

an=angle(h);

subplot(2,1,1);

plot(om/pi,m);

grid;

Ylabel('Gain in DB');

Xlabel('Normalized Freq.');

subplot(2,1,2);

plot(om/pi,an);

grid;

Ylabel('Phase in Radian');

Xlabel('Normalized Freq.');

Page 24: Dsp Lab Manual

Output:

RESULT: - The Plot of Butterworth Low Pass Filter has been studied using MATLAB

program.