DSP MATLAB Code

MATLAB Code for Digital Signal Processing

MATLAB Script for Circular time shift property of DFT

clc;
x = input('x[n] = 'wink;
l = input('l = 'wink;
N = length(x);
X = fft(x,N);
for k = 0:N-1
X1(k+1) = X(k+1).*exp(-1j*2*pi*k*l/N);
end
disp('DFT of x[n] is:'wink;
disp(X)
disp('DFT of x(n-l) is:'wink;
disp(X1);
Posted by makeale 01/05/2015 08:53 PM 0 Comments

MATLAB Script for Linearity property of DFT

clc;
x1 = input('x1[n]= 'wink;
x2 = input('x2[n]= 'wink;
a1 = input('a1 = 'wink;
a2 = input('a2 = 'wink;
n1 = length(x1);
n2 = length(x2);
N = max(n1,n2);
x1 = [x1 zeros(1,N-n1)];
x2 = [x2 zeros(1,N-n2)];
y1 = a1.*x1 + a2.*x2;
Y1 = fft(y1,N);
X1 = fft(x1,N);
X2 = fft(x2,N);
Y2 = a1*X1 + a2*X2;
disp('Output of left side DFT(a1*x1 + a2*x2) is:'wink;
disp(Y1);
disp('Output of right side a1*X1 + a2*X2 is:'wink;
disp(Y2);
Posted by makeale 01/05/2015 08:52 PM 0 Comments

MATLAB Script for Circular convolution property of DFT

Objective: To that the circular convolution property of discrete Fourier transform using MATLAB

clc;
x1 = input('x1[n]= 'wink;
x2 = input('x2[n]= 'wink;
N = max(length(x1),length(x2));
ym = cconv(x1,x2,N);
X1 = fft(x1,N);
X2 = fft(x2,N);
Y = X1.*X2;
yn = ifft(Y,N);
disp('Circular convolution output is:'wink;
disp(ym);
disp('Circular convolution using DFT is:'wink;
disp(yn);
Posted by makeale 01/05/2015 08:51 PM 0 Comments

MATLAB Script for DFT

MATLAB Code

clc;
x=input('x= 'wink;
N=input('N= 'wink;
l=length(x);
x=[x zeros(1,N-l)];
X=zeros(1,N);
for k=0:N-1
   X(k+1)=0;
   for n=0:N-1
       X(k+1)=X(k+1)+x(n+1)*exp(-2*j*pi*k*n/N);
   end
end
disp(['The ',num2str(N), ' point DFT of x[n] is:']);
disp(X);
Posted by makeale 01/05/2015 08:48 PM 0 Comments

MATLAB function for circular convolution

function y=cc(x,h)
% cc(x,h) computes circular convolution of x(n) and h(n)
n1= length(x);
n2= length(h);
N=max(n1,n2);%length of sequence
x=[x zeros(1,N-n1)];  %modified first sequence
h=[h zeros(1,N-n2)];  %modified second sequence

for m=0:N-1;
   y(m+1)=0;
   for n=0:N-1
      j=mod(m-n,N);
      y(m+1)=y(m+1)+x(n+1)*h(j+1);  %shifting and adding
   end
end
disp(['The ',num2str(N), ' point circular convolution is: ',num2str(y)]);
Posted by makeale 01/05/2015 08:45 PM 0 Comments
 

Archives