Sei sulla pagina 1di 4

Name: K.

Ashok Kumar
Reg. Number: 9908005035
Date:21.07.2010
Exp. No. 4 Name of the Experiment: Continuous and Discrete signal generation
clc;
clear all;
close all;

% Circular Convolution using DFT


x_n = input ('Enter the x(n) input vector = ');
h_n = input ('Enter the h(n) input vector = ');
figure(1);
subplot(3,2,1);
stem(x_n);
title ('x(n) vector');
xlabel ('samples "n"');
ylabel ('Amplitude');
subplot(3,2,2);
stem(h_n);
title ('h(n) vector');
xlabel ('samples "n"');
ylabel ('Amplitude');

N = length(x_n)+length(h_n)-1;
x_k = dft(x_n,N); % Call of user defined function dft
h_k = dft(h_n,N);
mag_xk = abs(x_k);
ang_xk = angle(x_k);
mag_hk = abs(h_k);
ang_hk = angle(h_k);
n = 0:1:N-1;
subplot(3,2,3);
stem(n,mag_xk)
title ('DFT of x(n) vector x(k)');
xlabel ('samples "n"');
ylabel ('Amplitude');
subplot(3,2,4);

DIGITAL SIGNAL PROCESSING LABORATORY CODE: ECE381


Name: K.Ashok Kumar
Reg. Number: 9908005035
Date:21.07.2010
Exp. No. 4 Name of the Experiment: Continuous and Discrete signal generation
stem(n,mag_hk)
title ('DFT of h(n) vector h(k)');
xlabel ('samples "n"');
ylabel ('Amplitude');

% Inverse DFT

y_k = x_k.*h_k;
N2 = length(y_k);
y_n = idft(y_k,N);
subplot(3,2,5);
stem(n,abs(y_n));
title ('IDFT of x(k)&h(k)or circular convolution by DFT');
xlabel ('samples "n"');
ylabel ('Amplitude');
disp('circular convolution output signal');
disp(abs(y_n));
subplot(3,2,6);
stem(n,conv(x_n,h_n));

title ('Linear convolution of x(n) & h(n)');


xlabel ('samples "n"');
ylabel ('Amplitude');
disp('linear convolution output signal');
disp(conv(x_n,h_n));

% Functions:
% file name : D_I
function [w,y] = DI(ak,bk,xn,LT,Ld)

% Direct for I

% To find w(n)

DIGITAL SIGNAL PROCESSING LABORATORY CODE: ECE381


Name: K.Ashok Kumar
Reg. Number: 9908005035
Date:21.07.2010
Exp. No. 4 Name of the Experiment: Continuous and Discrete signal generation
for n = 1:LT
for k = 1:LT

if ((n-k+1) > 0 && (n-k+1) <= LT)


wd(k) = ak(k)*xn(n-k+1);
end
w(n) = sum(wd);
end
end

%%
% To find y(n)
y = zeros(1,LT);
WD = zeros(1,Ld);
for N = 1:LT
for K = 2:Ld
if ((N-K) >= 0)
WD(K) = bk(K)*y(N-K+1);
end
end
y(N) = sum(WD) + w(N);
WD = zeros(1,Ld);
end

% file name : D_II


function [u,Y] = DII(bk,xn,ak,LT,Ld)
%%
% Direct form II Realization

u = zeros(1,LT);
Wd = zeros(1,Ld);
for N = 1:LT
for K = 2:Ld
if ((N-K) >= 0)
Wd(K) = bk(K)*u(N-K+1);
end
end
u(N) = sum(Wd) + xn(N);
Wd = zeros(1,Ld);
end

for n = 1:LT
for k = 1:LT

if ((n-k+1) > 0 && (n-k+1) <= LT)


wD(k) = ak(k)*u(n-k+1);
end
Y(n) = sum(wD);
end
end

DIGITAL SIGNAL PROCESSING LABORATORY CODE: ECE381


Name: K.Ashok Kumar
Reg. Number: 9908005035
Date:21.07.2010
Exp. No. 4 Name of the Experiment: Continuous and Discrete signal generation

Enter your input and output details here :


CIRCULAR CONVOLUTION USING DFT
Enter the 1st sequence: 2.3*ones(1,20)
Enter the 2nd sequence: 5.3*ones(1,40)

DIGITAL SIGNAL PROCESSING LABORATORY CODE: ECE381

Potrebbero piacerti anche