0% found this document useful (0 votes)
27 views6 pages

Dsplab

digital presentation
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
27 views6 pages

Dsplab

digital presentation
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 6

DATE:23/02/2024

Work Sheet-4
Circular Folding, Circular Shifting, and Circular Convolution

AIM:-
To realise the following operations in MATLAB
1. Circular Folding
2. Circular Shifting
3. Circular Convolution

QUESTIONS :-
1. Consider the signal 𝑥[𝑛] = 10(0.8) ^𝑛 defined in the
interval 0 ≤ n ≤ 10.
(a) Write a MATLAB function called cfold_ROLLNO to
implement the circular folding operation (Hint: Take x[n], n
and N as inputs).
(b) Using the function defined in part (a), determine and
plot x [((−n))11]

CODE:
clc;
clear;
close;
n=0:10;
x=10*(0.8).^(n);
CIRCULAR FOLDING FUNCTION N=length(n);
a=cfold_ECE22173(x,n,N);
function y=cfold_ECE22173(x,n,N)
for i =1:N stem(n,a);
y(i)=x(mod(-n(i),N)+1); xlabel('n_ ECE22173');
end ylabel('a_ ECE22173');
title('Circular Folding of x[n]_ ECE22173');
%% 1 b)
clc;
clear;
close;
n=0:10;
x=10*(0.8).^(-n);
N=length(n);
a=cfold_ECE22173(x,n,N);

stem(n,a);
xlabel('n_ ECE22173');
ylabel('a_ ECE22173');
title('Circular Folding of x[-n]_ ECE22173');

2. For the signal 𝑥[𝑛] = 10(0.8) 𝑛 defined in the interval 0 ≤ n


≤ 10,
(a) Write a MATLAB function called cshift_ROLLNO to
implement circular shifting operation 𝑥[(𝑛 − 𝑛0)𝑁] (Hint:
Take x[n], n, 𝑛0 and N as inputs)
(b) Using the function defined in part (a), Sketch x[((n +
4))11], that is, a circular shift by 4 samples toward the left.
(c) Sketch x[((n − 3))15], that is, a circular shift by 3 samples
toward the right, where x[n] is assumed to be a 15-point
sequence given by 𝑥[𝑛] = { 10(0.8) 𝑛 0 ≤ 𝑛 ≤ 10
{ {0 11 ≤ 𝑛 ≤ 14.
(d) Sketch x[((n − 6))15], that is, a circular shift by 3 samples
toward the right, where x[n] is assumed to be a 15-point
sequence defined in part (c).

CODE:-

%% 2a),b)
clc;
clear;
close;
n=0:10;
CIRCULAR SHIFT FUNCTION:- n0=-4;
x=10*(0.8).^(n);
function y=cshift_ECE22173(x,n,n0) a=cshift_ECE22173(x,n,n0);
N=length(n); stem(n,a);
for i =1:N xlabel('n_ ECE22173');
y(i)=x(mod(n(i)-n0,N)+1); ylabel('a_ ECE22173');
end title('Circular Shifting of x[-n]_ ECE22173');
%% 2c)
clc;
clear;
close;
n=0:15;
n0=+3;
x=(10*(0.8).^(n)).*(n>=0 & n<=10)+ 0.*(n>=11 &n<=15);
a=cshift_ECE22173(x,n,n0);
stem(n,a);
xlabel('n_ ECE22173');
ylabel('a_ ECE22173');
title('Circular Shifting of x[n-3]_ ECE22173');

%% 2d)
clc;
clear;
close;
n=0:15;
n0=+6;
x=(10*(0.8).^(n)).*(n>=0 & n<=10)+ 0.*(n>=11 &n<=15);
a=cshift_ECE22173(x,n,n0);
stem(n,a);
xlabel('n_ ECE22173');
ylabel('a_ ECE22173');
title('Circular Shifting of x[n-6]_ ECE22173');

3. There are two ways to write a function for circular


CIRCULAR CONVOLUTION FUNCTION convolution:
(a). In the transform domain (The frequency-domain
function y= implementation uses the fact that the circular convolution
cconv_time_freq_ECE22173(x,h,N,ind)
X=fft(x,N);
of x[n] and h[n] is equivalent to the multiplication of their
H=fft(h,N); DFTs, i.e., Y [k] = X[k].H[k] and take the inverse DFT of Y [k]).
if ind ==1 (b). In the time domain (Using the inbuilt function cconv in
z=X.*H; MATLAB).
y=ifft(z,N);
else
Develop a MATLAB function, called
z=cconv(x,h,N); cconv_time_freq_ROLLNO that implements both methods.
y=ifft(z,N); The MATLAB function will require four inputs: the signal
end vectors x[n] and h[n], the length of the circular convolution
N, and a variable ind that indicates which method to use.
The function returns a single output y[n]. Consider x[n] = {1,
2, 2,0} and h[n] = {1, 2, 3, 4}. Using the function
cconv_time_freq_ROLLNO compute the circular convolution
of x[n] and h[n] by both approaches and verify your results.
CODE:-

%% 3
clc;
clear;
close;
n=0:3;
x=[1,2,2,0];
h=[1,2,3,4];
ind=1;
a=cconv_time_freq_ECE22173(x,h,4,ind);
b=cconv(x,h,length(x));
stem(n,a);
xlabel('n_ ECE22173');
ylabel('a_ ECE22173');
title('Circular Convolution using function
ECE22173');
figure;
stem(n,b);
xlabel('n_ ECE22173');
ylabel('b_ ECE22173');
title('Circular Convolution using cconv ECE22173');
INPUT:-
>>Enter length of block: 4 DATE:30/03/2024

Work Sheet-5
Linear Filtering using Overlap add and Overlap save methods

OUTPUT:- AIM: To perform block convolution on the given sequence


by using overlap add/ save method in MATLAB.
ECE22173 x[n] is:
1 2 -1 2 3 -2
-3 -1 1 1 2 -1 QUESTION:-

ECE22173 h[n] is: 1. Compute the block convolution using overlap add
1 2 3 -1
method for the input sequence x[n] = [1 2 -1 2 3 -2 -3 -1 1 1
output y[n] is: 2 -1] and the impulse response h[n] = [ 1 2 3 -1]. Assume
1.0000 4.0000 6.0000 input signal block size to be 4. Compare the obtained result
5.0000 2.0000 11.0000 0.0000 with that obtained from the inbuilt function conv.
-16.0000 -8.0000 3.0000 8.0000
5.0000 3.0000 -5.0000 1.0000
CODE:-

x_n = [1,2,-1,2,3,-2,-3,-1,1,1,2,-1];
h_n = [1,2,3,-1];
L = input("Enter length of block: ");
M = length(h_n);
B = round(length(x_n)/L);
h1 = [h_n, zeros(1, L-1)];
x_i = zeros(B, L+M-1);
y_i = zeros(B,L+M-1);
for i=1:B
x_i(i,:) = [x_n((i-1)*L+1:i*L), zeros(1,M-1)];
y_i(i,:) = cconv(x_i(i,:), h1,L+M-1);
end
y_n = [];
for i=1:B
if(i==1)
y_n = [y_n,y_i(i,1:L), y_i(i,L+1:L+M-
1)+y_i(i+1,1:M-1)];
elseif(i==B)
y_n = [y_n,y_i(i,M:L+M-1)];
else
y_n = [y_n,y_i(i,M:L), y_i(i,L+1:L+M-
1)+y_i(i+1,1:M-1)];
end
end
disp('ECE22173 x[n] is:');
disp(x_n);
disp('ECE22173 h[n] is:');
disp(h_n);
disp('output y[n] is:')
disp(y_n);
2. Perform block convolution for the sequences given in
INPUT:- Qn.1 using overlap save method with same input signal
>>Enter lenght of block: 4
block size and verify the result

CODE:-
OUTPUT:-
x_n = [1,2,-1,2,3,-2,-3,-1,1,1,2,-1];
ECE22173 x[n] is: h_n = [1,2,3,-1];
1 2 -1 2 3 -2 L = input("Enter length of block");
-3 -1 1 1 2 -1 M = length(h_n);
B = round(length(x_n)/L)+1;
ECE22173 h[n] is: h1 = [h_n, zeros(1,L-1)];
1 2 3 -1 x_1 = zeros(B,L+M-1);
y_1 = zeros(B, L+M-1);
output y[n] is: for i=1:B
Columns 1 through 15 if(i==1)
x_i(i,:) = [zeros(1, M-1), x_n(1:L)];
1.0000 4.0000 6.0000 elseif(i==B)
5.0000 2.0000 11.0000 -0.0000 x_i(i,:) = [x_i(i-1,L+1:L+M-1), zeros(1,L)];
-16.0000 -8.0000 3.0000 8.0000 else
5.0000 3.0000 -5.0000 1.0000 x_i(i,:) = [x_i(i-1,L+1:L+M-1),x_n((i-
1)*L+1:i*L)];
end
y_i(i,:) = cconv(x_i(i,:), h1, L+M-1);
end
y_n = [];
for i=1:B
y_n = [y_n,y_i(i,M:L+M-1)];
end
disp('ECE22173 x[n] is:');
disp(x_n);
disp('ECE22173 h[n] is:');
disp(h_n);
disp('output y[n] is:');
disp(y_n);

You might also like