You are on page 1of 42

DIGITAL SIGNAL PROCESSING LABORATORY 21071A0486

1. Circular Convolution
Aim: To find the circular convolution of x(n) = {1, 1, 2, 2} and h(n) = {1,2,3}

Software Used: MATLAB R2022A

Program:

clc; clear all; x = [1 1 2


2]; h = [1 2 3 ]; a =
length(x); b =
length(h); c =
max(a,b); x1 =[x
zeros(1,(c-a))]; h1 =[h
zeros(1,(c-b))]; z =
zeros(c,c); for i = 1:c
z(:,i) = circshift(h1',i-1);
end
y = z*x1';
disp('Circular convolved sequence is y(n) = ');
disp(y');

subplot(3,1,1); stem(x);
xlabel('Samples');
ylabel('Amplitude');
title('Input Sequence');
axis([0 c+1 0 5]);

subplot(3,1,2); stem(h);
xlabel('Samples');
ylabel('Amplitude');
title('Impulse Response Sequence');
axis([0 c+1 0 5]);

subplot(3,1,3);
stem(y'); xlabel('Samples');
ylabel('Amplitude');
title('Circular Convolved Sequence'); axis([0
c+1 0 12]);

VNRVJIET Page 1 Output: Circular convolved sequence is y(n) = {11 , 9 , 7, 9}


DIGITAL SIGNAL PROCESSING LABORATORY 21071A0486

Graph:

Result:

Circular convolution is performed for x(n) = {1, 1, 2, 2} and h(n) = {1,2,3} in MATLAB. y(n) is
obtained as {11 , 9 , 7, 9}. The theoretical/mathematical and practical values obtained are
same.

Linear Convolution
Aim: To find the linear convolution of x(n) = {1, 2, 3, 4} and h(n) = {-3, 2, 1}

Software Used: MATLAB R2022A

Program:

clc; clear all; x


= [1 2 3 4]; h
= [-3 2 1]; a =
length(x); b =
length(h); c =
a+b-1; y =
conv(x,h);

VNRVJIET Page 2
DIGITAL SIGNAL PROCESSING LABORATORY 21071A0486

if (c == length(y)) disp('Linear Convolved sequence


is y(n) = '); disp(y);
else disp('Error');
end

subplot(3,1,1); stem(x);
xlabel('Samples');
ylabel('Amplitude');
title('Input Sequence');
axis([0 5 -4 5]);

subplot(3,1,2); stem(h);
xlabel('Samples');
ylabel('Amplitude');
title('Impulse Response Sequence');
axis([0 5 -4 5]);

subplot(3,1,3); stem(y');
xlabel('Samples');
ylabel('Amplitude');
title('Linear Convolved Sequence');
axis([0 c+1 -6 12]);

Output: Linear Convolved sequence is y(n) = {-3, -4, -4, -4, 11, 4}

Graph:

VNRVJIET Page 3
DIGITAL SIGNAL PROCESSING LABORATORY 21071A0486

Result:

Linear convolution is performed for x(n) = {1, 2, 3, 4} and h(n) = {-3, 2, 1} in MATLAB. y(n) is
obtained as {-3, -4, -4, -4, 11, 4} . The theoretical/mathematical and practical values
obtained are same.

2. Generation of DTMF Signals


Aim: To generate DTMF (Dual-tone Multi-frequency) signal for a given input number and
plot the corresponding signal

Software Used: MATLAB R2022A

Program:

clc;
num = input('Enter number ','s');
fs = 800; T
= 1;
t = 0:1/fs:T;

x = 2*pi*[697,770,852,941]; y =
2*pi*[1209,1336,1477,1633]; %DTMF
matrix as row and column vector
VNRVJIET Page 4
DIGITAL SIGNAL PROCESSING LABORATORY 21071A0486

n = length(num)/2;

for i=1:length(num) switch

num(i)

case'1'
b=sin(x(1)*t)+sin(y(1)*t);

case'2'
b=sin(x(1)*t)+sin(y(2)*t);

case'3'
b=sin(x(1)*t)+sin(y(3)*t);

case'4'
b=sin(x(2)*t)+sin(y(1)*t);

case'5'
b=sin(x(2)*t)+sin(y(2)*t);

case'6'
b=sin(x(2)*t)+sin(y(3)*t);

case'7'
b=sin(x(3)*t)+sin(y(1)*t);

case'8'
b=sin(x(3)*t)+sin(y(2)*t);

case'9'
b=sin(x(3)*t)+sin(y(3)*t);

case'*'
b=sin(x(4)*t)+sin(y(1)*t);

case'0'
b=sin(x(4)*t)+sin(y(2)*t);

case'#'
b=sin(x(4)*t)+sin(y(3)*t);

case'A'
b=sin(x(1)*t)+sin(y(4)*t);

case'B'
b=sin(x(2)*t)+sin(y(4)*t);
VNRVJIET Page 5
DIGITAL SIGNAL PROCESSING LABORATORY 21071A0486

case'C'
b=sin(x(3)*t)+sin(y(4)*t);

case'D'
b=sin(x(4)*t)+sin(y(4)*t);

otherwise
fprintf('invalid number');

end

sound(b); subplot(n,2,i); plot(t,b);


xlabel('Samples');
ylabel('Amplitude'); title(['Plot for
' num2str(num(i))]); pause(1);

end

Output:

Input Number: 9553251597


A unique sound for each input number and corresponding plot is observed.

Graph:

VNRVJIET Page 6
DIGITAL SIGNAL PROCESSING LABORATORY 21071A0486

Result:

DTMF signals and corresponding sounds are generated for each number in the input string.
Respective plots are observed.

3. Discrete Fourier Transform (DFT) and Inverse


Discrete Fourier Transform (IDFT)
Aim: 1. To find the Discrete Fourier transform (DFT) and Inverse Discrete Fourier transform
(IDFT) of the given discrete sequence [ 0 1 1 2 ]
2. To find the DFT and IDFT of a sinusoidal input signal and plot it’s corresponding
magnitude and phase response

Software Used: MATLAB R2022A

Program:

1. DFT and IDFT of a discrete sequence:

clc;
clear all;
x = input('Enter the input sequence');
N = length(x);

VNRVJIET Page 7
DIGITAL SIGNAL PROCESSING LABORATORY 21071A0486

X = zeros(1,N);

for k = 1:N w =
2*pi*(k-1)/N; for
n = 1:N
X(k)= X(k)+x(n)*exp(-1j*w*(n-1)); end
end

Y = fft(x);
fprintf('DFT using code \n'); disp(X);
fprintf('DFT using inbuilt command \n'); disp(Y);

x1 = zeros(1,N); for n = 1:N w =


2*pi*(n-1)/N; for k = 1:N x1(n)=
x1(n)+X(k)*exp(1j*w*(k-1));
end
x1(n) = abs(x1(n))/N;
end

y1 = ifft(Y);
fprintf('Inverse DFT using code \n'); disp(x1);
fprintf('Inverse DFT using inbuilt command \n');
disp(y1);

Output:

Enter the input sequence [ 0 1 1 2]

DFT using code


4.0000 + 0.0000i -1.0000 + 1.0000i -2.0000 - 0.0000i -1.0000 - 1.0000i

DFT using inbuilt command


4.0000 + 0.0000i -1.0000 + 1.0000i -2.0000 + 0.0000i -1.0000 - 1.0000i

Inverse DFT using code


0.0000 1.0000 1.0000 2.0000

Inverse DFT using inbuilt command


0 1 1 2

2. DFT and IDFT of a sinusoidal input signal:

clc;

VNRVJIET Page 8
DIGITAL SIGNAL PROCESSING LABORATORY 21071A0486

clear all; fs
= 1000;
fm = input('Enter sine frequency');
T = 1; n = 0:1/fs:T;
x = sin(2*pi*fm/fs*n);

N = length(x);
X = zeros(1,N);

for k = 1:N w =
2*pi*(k-1)/N; for
n1 = 1:N
X(k)= X(k)+x(n1)*exp(-1j*w*(n1-1)); end
end

x1 = zeros(1,N); for
n1 = 1:N w =
2*pi*(n1-1)/N; for k
= 1:N
x1(n1)= x1(n1)+X(k)*exp(1j*w*(k-1));
end x1(n1) =
x1(n1)/N; end

Y = fft(x); y1
= ifft(Y);

subplot(3,2,1); plot(n,x);
xlabel('samples');
ylabel('amplitude');
title('Input sine');

subplot(3,2,2); plot(abs(Y));
xlabel('samples');
ylabel('amplitude');
title('FFT');
axis([-100 1100 0 600]);

subplot(3,2,3); plot(n,X);
xlabel('samples');
ylabel('amplitude');
title('DFT');
axis([-0.5 1.5 0 6]);

subplot(3,2,4); plot(phase(Y));
xlabel('samples');
ylabel('amplitude');
title('Phase response');

VNRVJIET Page 9
DIGITAL SIGNAL PROCESSING LABORATORY 21071A0486

axis([-100 1100 -5 10]);

subplot(3,2,5); plot(n,x1);
xlabel('samples');
ylabel('amplitude');
title('Inverse DFT');

subplot(3,2,6); plot(y1);
xlabel('samples');
ylabel('amplitude');
title('Inverse FFT');

Output: Enter sine frequency 3000 Graph:

Result:

DFT and Inverse DFT of a given sequence is found using both the theoretical formula and
inbuilt command. Both the results are observed to be same. Magnitude and Phase
response of sinusoidal input are plotted.

VNRVJIET Page 10
DIGITAL SIGNAL PROCESSING LABORATORY 21071A0486

4. Power Spectral Density


Aim: To find power spectral densities of given signals.

Software used: MATLAB R2022A

Program :

Method 1:

clc; clear
all; close
all;
fs=8000;
f1=1000;
f2=2000;
N=200;
n=0:N-1;

x=sin(2*pi*f1*n/fs)+2*sin(2*pi*f2*n/fs);
xf=abs(fft(x))/N; p=xf.*xf; f=(0:N-
1)*fs/N;
y=angle(xf);

subplot(3,1,1); plot(n,x);
xlabel('Samples');
ylabel('Amplitude');
title('Input Sine Signal');

subplot(3,1,2);
plot(f,p); xlabel('Frequency');
ylabel('Magnitude');
title(['Two sided PSD at ',num2str(f1),' and at ',num2str(f2),'with refernce to ',num2str(fs/2)]);

subplot(3,1,3); plot(f,10*log(p));
xlabel('frequency in Hz');
ylabel('magnitude in dB');
title('PSD in log scale');

Output: fs=8000, f1=1000, f2=2000

Graph:

VNRVJIET Page 11
DIGITAL SIGNAL PROCESSING LABORATORY 21071A0486

Method 2 :

clc; clear all;


t=0:100;
fm=1000;
fs=8000;
fo=fm/fs;
x=sin(2*pi*fo*t);
N=length(x);
n=0:N-1; f=(0:N-
1)*fs/N; k=n;
wf=exp(-j*2*pi/N)
nk=k'*n;
wfnk=wf.^nk;
X=x*wfnk;
X1=conj(X);
Z=fft(x);
Z1=conj(Z);
Y=(X.*X1)/N;
W=(Z.*Z1)/N;
subplot(2,1,1); plot(f,Y);
subplot(2,1,2);
plot(f,W);

Output: fs=8000,fm=1000

Graph:

VNRVJIET Page 12
DIGITAL SIGNAL PROCESSING LABORATORY 21071A0486

Result: Therefore, power spectral densities of given signals is found and plotted.

VNRVJIET Page 13
DIGITAL SIGNAL PROCESSING LABORATORY 21071A0486

5. Impulse Response and Step Response


Aim: To compute the impulse response and step response of a system based on it’s
coefficients and plot the response

Software used: MATLAB R2022A

Program:

a) Impulse Response:

clc; b = [1 2 4]; a = [1
-1.5 1.5 -1 0.5];
n=0:1:20;

x=zeros(1,length(n));
x(find(n==0))=1;

y=filter(b,a,x);
[z,t]=impz(b,a,length(n));

subplot(3,1,1) stem(n,x);
xlabel('time');
ylabel('amplitude');
title('Unit Impulse Input');
axis([-0.5 20 0 2]);

subplot(3,1,2)
stem(n,y); xlabel('time');
ylabel('amplitude');
title('Impulse Response (Filtered output)');

subplot(3,1,3) stem(t,z); xlabel('time');


ylabel('amplitude'); title('Impulse Response
(Using Built-in Func)');

b) Step Response:

clc; b = [1 1 2]; a = [1
-1.5 1.5 -1 0.5];

n = 0:20; x =
ones(1,length(n)); y =

VNRVJIET Page 14
DIGITAL SIGNAL PROCESSING LABORATORY 21071A0486

filter(b,a,x); [z,t] =
stepz(b,a,length(n));

subplot(3,1,1);
stem(n,x); xlabel('time');
ylabel('amplitude')
title('Input Step Signal');
axis([0 20 0 2]);

subplot(3,1,2);
stem(n,y); xlabel('time');
ylabel('amplitude');
title('Step Response (Using Filter)');

subplot(3,1,3); stem(t,z); xlabel('time');


ylabel('amplitude'); title('Step Response (Using
Built-in command)'); Output: Respective
response plots are observed

Graphs:

Impulse Response Plot

VNRVJIET Page 15
DIGITAL SIGNAL PROCESSING LABORATORY 21071A0486

Step Response Plot

Result: For the given filter coefficients the step and impulse responses of the system are
calculated both using the procedure and the inbuilt command.

VNRVJIET Page 16
DIGITAL SIGNAL PROCESSING LABORATORY 21071A0486

6. Interpolation and Decimation


Aim: To perform interpolation and decimation on a given sampled signal.

Software used: MATLAB R2022A

Program:

a) Interpolation:

clc;
clear all;

fs=input('enter sampling frequency');


f=input('enter frequency of signal');
L=input('enter interpolation factor');

t=0:1/fs:1;
x=sin(2*pi*f*t);
N=length(x); n=0:N-1;
m=0:(N*L)-1;
x1=zeros(1,L*N);
j=1:L:N*L; x1(j)=x;
f1=fir1(34,0.48,'low');
output=2*filtfilt(f1,1,x1);
y=interp(x,L);

subplot(3,1,1); stem(n,x);
xlabel('samples');
ylabel('amplitude');
title('Input signal');

subplot(3,1,2);
stem(m,output); axis
([0 200 -1 1]);
xlabel('samples');
ylabel('amplitude');
title('Interpolated signal');

subplot(3,1,3);
stem(m,y); axis ([0
200 -1 1]);
xlabel('samples');
ylabel('amplitude');
title('Interpolated signal using inbuilt command');

VNRVJIET Page 17
DIGITAL SIGNAL PROCESSING LABORATORY 21071A0486

b) Decimation:

clc;
clear all;

fs=input('enter sampling frequency');


fm=input('enter frequency of signal');
D=input('enter decimation factor');

t=0:1/fs:1;
x=sin(2*pi*fm*t);
N=length(x); n=0:N-1;
m=0:(N/D);
x2=zeros(1,length(m));
j=1:D:N; x2=x(j);
v=decimate(x,D,'fir');

subplot(3,1,1); stem(n,x);
xlabel('samples');
ylabel('amplitude');
title('Input signal');

subplot(3,1,2); stem(m,x2);
xlabel('samples');
ylabel('amplitude');
title('Decimated signal');

subplot(3,1,3); stem(m,v); axis([0 50 -1.2 1.2]);


xlabel('samples'); ylabel('amplitude');
title('Decimated signal (Using inbuilt
command)');

Output:

Input Signal Frequency: 10


Sampling Frequency: 100
Interpolation Factor: 2
Decimation Factor: 2
Graphs:

VNRVJIET Page 18
DIGITAL SIGNAL PROCESSING LABORATORY 21071A0486

Interpolation

Decimation

Result: For a given signal with a specific sampling frequency Interpolation and Decimation
are performed to increase and decrease the sampling rates respectively.

7. Generation of Sinusoidal signal through Filtering


(LCCDE approach)

VNRVJIET Page 19
DIGITAL SIGNAL PROCESSING LABORATORY 21071A0486

Aim: To generate sinusoidal signal from an impulse signal by using filtering and LCCDE
algorithm approach

Software used: MATLAB R2022A

Program:

clc
clear all t=0:0.01:10;
x=zeros(1,length(t));
x(find(t==0))=1;
w=input('Enter the value of w');

%a: Coefficients of Y[z]


%b: Coefficients of X[z]
a=[1 -2*cos(w) 1]; b=[0
sin(w) 0];
y=zeros(1,length(t));
x1=0; x2=0;
y1=0; y2=0;

%Generation of Sinusoidal Signal using LCCDE approach for


n=1:length(x)
y(n)=b(1)*x(n)+b(2)*x1+b(3)*x2-a(2)*y1-a(3)*y2;
x2=x1; x1=x(n); y2=y1; y1=y(n);
end

%Plot the input signal, generated sinusoidal signal and the response.
subplot(3,1,1); plot(t,x,'lineWidth',2); xlabel('Time');
ylabel('Amplitude');
title('Input Signal (impulse)');

subplot(3,1,2);
plot(t,y); xlabel('Time');
ylabel('Amplitude');
title('Sinusoidal signal (Sine) generated');
yi=filter(b,a,x);
subplot(3,1,3);
plot(t,yi); xlabel('Time');
ylabel('Amplitude');
title('Using inbuilt function');

Output: w = 0.1

Graphs:

VNRVJIET Page 20
DIGITAL SIGNAL PROCESSING LABORATORY 21071A0486

Result: Thus, sinusoidal signal is generated based on the input frequency using LCCDE
coefficients and is also verified with inbuilt function.

8. Implementation of Filters using IIR


(Butterworth and Chebyshev)
Aim: To plot the frequency response of Butterworth and Chebyshev filters as Low pass and
High pass filters and verify the same with a given input signal

Software used: MATLAB R2022A

Program:

1) High Pass and Low Pass Filter design:

clc; clear
all; close
all;
fs=8000;
N=1024;
n=0:N-1;
f1=500;
f2=2000;

x=3*sin(2*pi*f1*n/fs)+cos(2*pi*f2*n/fs); X=abs(fft(x,N))/N;
f=(0:1:N/2-1)*fs/N;

VNRVJIET Page 21
DIGITAL SIGNAL PROCESSING LABORATORY 21071A0486

subplot(3,1,1);
plot(f,X(1:N/2));
xlabel('frequency');
ylabel('amplitude'); title('input
signal spectrum');

%filter parameters
wp=1000;
ws=1500; rp=3;
rs=20; fF=fs/2;
wpa=wp/fF;
wsa=ws/fF;

%filter design
[n,wc]=buttord(wpa,wsa,rp,rs);
[b,a]=butter(n,wc,'high');
[h,f_hz]=freqz(b,a,512,fs);

subplot(3,1,2);
plot(f_hz,20*log10(abs(h)));
xlabel('frequency'); ylabel('gain
in db');
title('High pass filter response');
y=filter(b,a,x);
y1=abs(fft(y,N))/N;

subplot(3,1,3);
plot(f,y1(1:N/2));
xlabel('frequency'); ylabel('gain
in db');
title('filtered signal spectrum');

Output: Low pass and high pass filters designed for given parameters

Graphs:

1) Low pass Filter response

VNRVJIET Page 22
DIGITAL SIGNAL PROCESSING LABORATORY 21071A0486

2) High Pass filter response:

2) Butterworth filter design

clc; clear
all;
close all;

wp=input('enter passband frequency');


ws=input('enter stopband frequency');
rp=input('enter passband ripple');
rs=input('enter stopband ripple');
fs=input('enter sampling frequency');
wpn=2*wp/fs; wsn=2*ws/fs;

VNRVJIET Page 23
DIGITAL SIGNAL PROCESSING LABORATORY 21071A0486

[n,wc]=buttord(wpn,wsn,rp,rs);
[b,a]=butter(n,wc); [h,w]=freqz(b,a);
h1=20*log10(abs(h));
w1=angle(h);

subplot(2,1,1); plot(w/pi,h1);
title('magnitude plot');
xlabel('freq');
ylabel('magnitude H(W)');

subplot(2,1,2);
plot(w/pi,w1); title('phase
plot'); xlabel('freq');
ylabel('phase');

Output and Graphs:

1) enter passband frequency :


400 enter stopband frequency :
700 enter passband ripple : 0.3
enter stopband ripple : 20 enter
sampling frequency : 2000

2) enter passband frequency :


500 enter stopband frequency :
800 enter passband ripple : 0.1
enter stopband ripple : 20 enter
sampling frequency : 2000

VNRVJIET Page 24
DIGITAL SIGNAL PROCESSING LABORATORY 21071A0486

3) Cheybyshev Type 1 Filter


Design:

clc; clear
all;
close all;

wp=input('enter passband frequency');


ws=input('enter stopband frequency');
rp=input('enter passband ripple'); rs=input('enter
stopband ripple');
fs=input('enter sampling frequency');

wpn=2*wp/fs; wsn=2*ws/fs;
[n,wc]=cheb1ord(wpn,wsn,rp,rs);
[b,a]=cheby1(n,rp,wc);
[h,w]=freqz(b,a); h1=20*log10(abs(h));
w1=angle(h);

subplot(2,1,1); plot(w/pi,h1);
title('Chebyschev Filter I magnitude plot');
xlabel('freq');
ylabel('magnitude H(W)');

subplot(2,1,2);
plot(w/pi,w1); title('phase
plot'); xlabel('freq');
ylabel('phase');

Output and Graphs:

VNRVJIET Page 25
DIGITAL SIGNAL PROCESSING LABORATORY 21071A0486

1) enter passband frequency : 400


enter stopband frequency : 700
enter passband ripple : 0.3
enter stopband ripple : 20 enter
sampling frequency : 2000

2) enter passband frequency : 500


enter stopband frequency : 800
enter passband ripple : 0.1
enter stopband ripple : 20 enter
sampling frequency : 2000

VNRVJIET Page 26
DIGITAL SIGNAL PROCESSING LABORATORY 21071A0486

Result: Butterworth and Chebyshev Filters are designed and verified for specific input
signals. Their frequency responses are plotted.

8. Implementation of Filters using FIR


(Windowing Techniques)
Aim: To verify the functionality and filtering characteristics of the following windowing
functions in FIR filter design
1) Rectangular Window
2) Blackman Window
3) Hamming Window
4) Triangular Window Software used: MATLAB

R2022A Program:

1) Rectangular Window function:

N=input('enter order of filter');


wc=input('enter the cutoff frequency');
ws=input('enter sampling frequency');
wcd=2*wc/ws;
n=0:N;

wr=rectwin(N+1); [hr,
w]=freqz(wr,1,512);
hlp=fir1(N,wcd,'low',wr);
[hlpz,w1]=freqz(hlp,1,512);

VNRVJIET Page 27
DIGITAL SIGNAL PROCESSING LABORATORY 21071A0486

subplot(2,2,1);
stem(n,wr); xlabel('time');
ylabel('frequency');
title('rectangular window function');

subplot(2,2,3);
plot(w/pi,20*log10(abs(hr))); xlabel('frequency');
ylabel('amplitude'); title('frequency response of
rectangular window function');

subplot(2,2,2);
plot(w1/pi,20*log10(abs(hlpz)));
xlabel('frequency'); ylabel('amplitude');
title('frequency response of designed fir filter');

subplot(2,2,4);
plot(w1/pi,angle(hlpz));
xlabel('phase'); ylabel('amplitude');
title('phase response of designed fir filter');

Output and Graphs:

order N=5

order N=50

VNRVJIET Page 28
DIGITAL SIGNAL PROCESSING LABORATORY 21071A0486

2) Blackman Window function

N=input('enter order of filter'); wc=input('enter


the cutoff frequency'); ws=input('enter
sampling frequency');
wcd=2*wc/ws; n=0:N;
wr=blackman(N+1); [hr,
w]=freqz(wr,1,512);
hlp=fir1(N,wcd,'low',wr);
[hlpz,w1]=freqz(hlp,1,512);

subplot(2,2,1); stem(n,wr);
xlabel('time'); ylabel('frequency');
title('blackman window function');

subplot(2,2,3); plot(w/pi,20*log10(abs(hr)));
xlabel('frequency'); ylabel('amplitude'); title('frequency
response of blackman window function');

subplot(2,2,2);
plot(w1/pi,20*log10(abs(hlpz)));
xlabel('frequency'); ylabel('amplitude');
title('frequency response of designed fir filter');

subplot(2,2,4); plot(w1/pi,angle(hlpz));
xlabel('phase'); ylabel('amplitude');

VNRVJIET Page 29
DIGITAL SIGNAL PROCESSING LABORATORY 21071A0486

title('phase response of designed fir


filter');

Output and Graphs:

order of the filter N=5

order of the filter is N=50

3) Hamming Window function

VNRVJIET Page 30
DIGITAL SIGNAL PROCESSING LABORATORY 21071A0486

N=input('enter order of filter');


wc=input('enter the cutoff frequency');
ws=input('enter sampling frequency');
wcd=2*wc/ws; n=0:N;
wr=hamming(N+1); [hr,
w]=freqz(wr,1,512);
hlp=fir1(N,wcd,'low',wr);
[hlpz,w1]=freqz(hlp,1,512);
subplot(2,2,1); stem(n,wr);
xlabel('time'); ylabel('frequency');
title('hamming window function');

subplot(2,2,3); plot(w/pi,20*log10(abs(hr)));
xlabel('frequency'); ylabel('amplitude'); title('frequency
response of hamming window function');

subplot(2,2,2);
plot(w1/pi,20*log10(abs(hlpz)));
xlabel('frequency'); ylabel('amplitude');
title('frequency response of designed fir filter');

subplot(2,2,4); plot(w1/pi,angle(hlpz));
xlabel('phase'); ylabel('amplitude');
title('phase response of designed fir
filter');

Output:

order of the filter N=5

order of the filter N=50

VNRVJIET Page 31
DIGITAL SIGNAL PROCESSING LABORATORY 21071A0486

4) Triangular Window Function

clc; clear
all; close
all;
N=input('enter order of the filter');
wc=input('enter the cutoff frequency');
ws=input('enter sampling frequency');
wcd=2*wc/ws; n=0:N;
wr=triang(N+1); [hr
w]=freqz(wr,1,512);
hlp=fir1(N,wcd,'low',wr);
[hlpz,w1]=freqz(hlp,1,512);
subplot(2,2,1); stem(n,wr);
title('rectangular window function');
xlabel('time'); ylabel('amplitude');
subplot(2,2,3);
plot(w/pi,20*log10(abs(hr)));
title('frequency response of rectangular window function');
xlabel('frequency'); ylabel('amplitude'); subplot(2,2,2);
plot(w/pi,20*log10(abs(hlpz))); title('frequency response
of designed FIR LPF');
xlabel('frequency');
ylabel('amplitude'); subplot(2,2,4);
plot(w/pi,angle(hlpz)); title('
response of designed FIR LPF');
xlabel('frequency');
ylabel('amplitude');

Outputs and Graphs:


VNRVJIET Page 32
DIGITAL SIGNAL PROCESSING LABORATORY 21071A0486

1) enter order of the filter10


enter the cutoff frequency100
enter sampling frequency2000

2) enter order of the filter5


enter the cutoff frequency600
enter sampling frequency3000

Result: Therefore, frequency responses of various window functions are observed.

VNRVJIET Page 33
DIGITAL SIGNAL PROCESSING LABORATORY 21071A0486

CODE COMPOSER STUDIO STEPS


• Start CCS setup by double clicking on the CCS desktop icon.

New project creation:


• To create a new project, choose new CSS project from the project menu.
• Then Select the target as C671X Floating point DSP and click on
TMS320C6713 Enter the project name.
Then Click on Finish.
New Target configuration:
• In View Option, select Target configuration.
• Click on the project folder and select New Target configuration.
• Then change the filename as 6713.ccxml.
• Click on Finish.
• In basic window, select Connection as Texas Instruments Simulator.
select Device as C67xx CPU Cycle Accurate Simulator, little Endian. -Click
on Save.
• Then in Advanced window, select TMS320C67XX.
• Then in CPU Properties window click on browse button and open
DSK6713.gel file.
-Click on Save.
Launch Target configuration:
• Click on the User defined folder and select C713.ccxml.
Click on Launch target configuration. Then
click on the stop button.
• Then a CSS Editor window will be opened.
Click on your project and then click on main.c to type the programs. Execution:
• To compile a program, right click on the project name. Select build
configuration and then click on build all.
• To run a program, click on the debug option in run menu.
Click on the run option again to display the output in the console window.

1.1 LINEAR CONVOLUTION

AIM: To Perform Linear Convolution of two sequences using C-Code

SOFTWARE: PC and Code Composer Studio

PROGRAM:

VNRVJIET Page 34
DIGITAL SIGNAL PROCESSING LABORATORY 21071A0486

#include<stdio.h>
void main()
{ int
a[9]={1,2,3,4,5}; int
b[9]={1,1,1,1,1};
int m=5,n=5;
int c[10],i,j;
for(i=0;i<m+n-1;i++)
{ c[i]=0;
for(j=0;j<=i;j++)
c[i]=c[i]+(a[j]*b[i-j]);
}
for(i=0;i<m+n-1;i++) printf
("%d", c[i]);
}

OUTPUT :

1 3 6 10 15 14 12 9 5

1.2 LINEAR CONVOLUTION

AIM : To Perform Linear Convolution of two sequences using C-Code

SOFTWARE: PC and Code Composer Studio

PROGRAM:

#include<stdio.h>
#define MAX1 10
#define MAX2 10

void main()
{
int a[MAX1],b[MAX2],i,j,M,N,temp;
printf("ENTER THE RANGE OF THE ARRAY A:(MAX1=10)\n"); scanf("%d",&M);
printf("ENTER THE RANGE OF THE ARRAY B:(MAX2=10)\n"); scanf("%d",&N);
printf("ENTER THE ELEMENTS OF THE ARRAY A:\n"); for(i=0;i<M;i++)
scanf("%d",&a[i]);
printf("ENTER THE ELEMENTS OF THE ARRAY B:\n"); for(i=0;i<N;i++)
scanf("%d",&b[i]);
printf("THE VALUES OF THE ARRAY (A CONV B):\n");
for(i=0;i<(M+N-1);i++)
VNRVJIET Page 35
DIGITAL SIGNAL PROCESSING LABORATORY 21071A0486

{ temp=0;
for(j=0;j<=i;j++
)
{
if((j<M)&&((i-j)<N)) temp+=a[j]*b[i-
j];
}
printf("%d ",temp);
}
}

SIMULATION RESULTS:

ENTER THE RANGE OF THE ARRAY A:(MAX1=10)


4
ENTER THE RANGE OF THE ARRAY B:(MAX2=10)
3
ENTER THE ELEMENTS OF THE ARRAY A:
1234
ENTER THE ELEMENTS OF THE ARRAY B:
123
THE VALUES OF THE ARRAY (A CONV B):

1 4 10 16 17 12

VNRVJIET Page 36
DIGITAL SIGNAL PROCESSING LABORATORY 21071A0486

AIM:

2.1 CIRCULAR CONVOLUTION

To Perform Circular Convolution of two sequences using C-Code

SOFTWARE: PC and Code Composer Studio

PROGRAM:

#include<stdio.h>
#define MAX 10
void main( )
{
int a[MAX],b[MAX],i,j,M,N,temp,k,c[MAX],x,z;
int max(int ,int );
printf("ENTER THE RANGE OF THE ARRAY A:(MAX=10)\n");
scanf("%d",&M);
printf("ENTER THE RANGE OF THE ARRAY B:(MAX=10)\n");
scanf("%d",&N);
printf("ENTER THE ELEMENTS OF THE ARRAY A:\n");
for(i=0;i<M;i++)
scanf("%d",&a[i]);
printf("ENTER THE ELEMENTS OF THE ARRAY B:\n");
for(i=0;i<N;i++) scanf("%d",&b[i]); k=max(M,N);
if(k==M) {
for(i=N;i<M;i++
) b[i]=0;
for(i=0;i<M;i++)
c[i]=b[M-1-i];
} else {
for(i=M;i<N;i++
) a[i]=0;
for(i=0;i<N;i++)
c[i]=a[N-i-1];
}
printf("THE VALUES OF THE ARRAY (A CIRCULAR CONV B):\n");
for(i=0;i<k;i++)
{ temp=c[0];
c[0]=c[k-1];
for(z=k-1;z>=2;z--
)

VNRVJIET Page 37
DIGITAL SIGNAL PROCESSING LABORATORY 21071A0486

{ c[z]=c[z-1]; }
c[1]=temp;
x=0;
for(j=0;j<k;j++
) { if(k==M)
x=x+a[j]*c[j];
else
x=x+b[j]*c[j];
}
printf("%d ",x);
}}
int max(int l,int p)
{ if(l>p)
return(l);
else
return(p)
;
}

SIMULATED RESULTS:

ENTER THE RANGE OF THE ARRAY A:(MAX=10)


4

ENTER THE RANGE OF THE ARRAY B:(MAX=10)


3

ENTER THE ELEMENTS OF THE ARRAY A:


1
2
3
4

ENTER THE ELEMENTS OF THE ARRAY B:


1
2
3

THE VALUES OF THE ARRAY (A CIRCULAR CONV B):


18 16 10 16
3.1 AUTO & CROSS CORRELATION

To Perform correlation of two sequences using C-Code

SOFTWARE: PC and Code Composer Studio

VNRVJIET Page 38
DIGITAL SIGNAL PROCESSING LABORATORY 21071A0486

AIM:

PROGRAM:

#include<stdio.h>
#define MAX 10

void main()
{
int a[MAX],b[MAX],i,j,M,N,temp;
printf("ENTER THE RANGE OF THE ARRAY A:(MAX=10)\n");
scanf("%d",&M);
printf("ENTER THE RANGE OF THE ARRAY B:(MAX=10)\n");
scanf("%d",&N);
printf("ENTER THE ELEMENTS OF THE ARRAY A:\n");
for(i=0;i<M;i++)
scanf("%d",&a[i]);
printf("ENTER THE ELEMENTS OF THE ARRAY B:\n"); for(i=N-
1;i>=0;i--)
scanf("%d",&b[i]);
printf("THE VALUES OF THE ARRAY (A CONV B):\n");
for(i=0;i<(M+N-1);i++)
{ temp=0;
for(j=0;j<=i;j++
)
{
if((j<M)&&((i-j)<N)) temp+=a[j]*b[i-
j];
} printf("%d
",temp);
}
}

SIMULATED RESULTS:

ENTER THE RANGE OF THE ARRAY A:(MAX=10)


4
ENTER THE RANGE OF THE ARRAY B:(MAX=10)
3
ENTER THE ELEMENTS OF THE ARRAY A:
1256

VNRVJIET Page 39
DIGITAL SIGNAL PROCESSING LABORATORY 21071A0486

ENTER THE ELEMENTS OF THE ARRAY B:


891
THE VALUES OF THE ARRAY (A CONV B):
1 11 31 67 94 48

4.1 DFT

AIM: To Perform DFT using C-Code

SOFTWARE: PC and Code Composer Studio

PROGRAM:

#include<stdio.h>
#include<math.h>
int N,k,n,i;
float pi=3.1416,sumre=0, sumim=0,out_real[8]={0.0}, out_imag[8]={0.0};
int x[32]; void main(void)
{
printf(" enter the length of the sequence\n");
scanf("%d",&N); printf("
enter the sequence\n");
for(i=0;i<N;i++)
scanf("%d",&x[i]);
for(k=0;k<N;k++)
{
sumre=0;
sumim=0;

for(n=0;n<N;n++)
{
sumre=sumre+x[n]* cos(2*pi*k*n/N);
sumim=sumim-x[n]* sin(2*pi*k*n/N);
}
out_real[k]=sumre; out_imag[k]=sumim;
printf("X([%d])=\t%f\t+\t%fi\n",k,out_real[k],out_imag[k])
;
}
}

SIMULATED RESULTS:

VNRVJIET Page 40
DIGITAL SIGNAL PROCESSING LABORATORY 21071A0486

AIM:

enter the length of the sequence


4 enter the
sequence
1467
X([0])= 18.000000 + 0.000000i
X([1])= -4.999938 + 3.000043i
X([2])= -4.000000 + 0.000096i
X([3])= -5.000184 + -2.999868i
5 .GENERATION OF SINE WAVE

To Generate sine wave using C-Code

SOFTWARE: PC and Code Composer Studio

PROGRAM:

#include<stdio.h>
#include<math.h>
float a[100];
main()
{
int i;
for(i=0;i<11;i++)
{ a[i]=
sin(2*3.14*5*i/100);
printf("%f",a[i]);
}
}

SIMULATED RESULTS:

0.0000000
.3088660
.5875280
.8087360
.9508591
.0000000
.9513510

VNRVJIET Page 41
DIGITAL SIGNAL PROCESSING LABORATORY 21071A0486

.8096720
.5888160
.3103800
.001593

VNRVJIET Page 42

You might also like