Escolar Documentos
Profissional Documentos
Cultura Documentos
8284
clc; Phase spectrum:
clear all; X_ang =
close all; 0
2.3562
x1=input('Enter the sequence x(n): '); -3.1416
N=input('Enter the length of DFT: '); -2.3562
x=[x1,zeros(1,N-length(x1))]
k=0:N-1
n=k
powers=n.'*k;
disp('DFT matrix for given is');
WNkn=(exp(-j*2*pi/N)).^powers
disp('The N point DFT of the given sequence is')
X=WNkn*x.' % x is sequence
after zero padding
disp('The N point DFT of the given sequence using
inbuilt function is')
X1=fft(x1,N) % for inbuilt use
original sequence
disp('Magnitude spectrum:')
X_mag=abs(X)
disp('Phase spectrum:')
X_ang=angle(X)
figure
subplot(3,1,1);
stem(0:length(x1)-1,x1); grid on;
xlabel('---->n');
ylabel('---->amplitude');
title('Input sequence x(n)')
subplot(3,1,2);
stem(0:length(X_mag)-1,X_mag); grid on;
xlabel('---->k');
ylabel('---->|X(k)|');
title('Magnitude spectrum')
subplot(3,1,3);
stem(0:length(X_ang)-1,X_ang); grid on;
xlabel('---->k');
ylabel('----> <X(k)');
title('Phase spectrum')
OUTPUT:
Magnitude spectrum:
X_mag =
10.0000
2.8284
2.0000
%Computation of N Point IDFT a sequence The N point IDFT of the given sequence using inbuilt
clc; function is
clear all;
close all;
X1 =
x1=input('Enter the sequence X(n): ');
N=input('Enter the length of IDFT: '); -1.0000 + 0.0000i 1.0000 - 0.5000i 0.5000 + 0.5000i
x=[x1,zeros(1,N-length(x1))] 0.5000 + 0.0000i
k=0:N-1
n=k
powers=n.'*k;
disp('IDFT matrix for given is');
WNkn=(exp(j*2*pi/N)).^powers
disp('The N point IDFT of the given sequence
is')
X=1/N*WNkn*x.' % x is
sequence after zero padding
disp('The N point IDFT of the given sequence
using inbuilt function is')
X1=ifft(x1,N) % for
inbuilt use original sequence
figure
subplot(2,1,1);
stem(0:length(x1)-1,x1);
grid on;
xlabel('---->n');
ylabel('---->amplitude');
title('Input sequence x(n)')
subplot(2,1,2);
stem(0:length(X1)-1,X1);
grid on;
xlabel('---->n');
ylabel('---->amplitude');
title('IDFT sequence X(n)')
OUTPUT:
WNkn =
X=
-1.0000 + 0.0000i
1.0000 - 0.5000i
0.5000 + 0.5000i
0.5000 - 0.0000i
//C Program To find N point DFT of a given
sequence XMag[k]=sqrt(pow(XReal[k],2)+pow(XImag[k]
#define CHIP_6713 1 ,2)); //magnitude
#include "dsk6713.h" XPhase[k]=atan2(XImag[k],XReal[k]);
#include "dsk6713_aic23.h" //phase
#include "stdio.h" }
#include "stdlib.h"
#include "math.h" //Printing phase and Magnitude values
#define pi 3.141592653589793 printf("The magnitude and phase response
float *x, *XReal, *XImag, *XMag, *XPhase; of DFT are\n");
void main() for(k=0;k<N;k++)
{
int i, n , k, N, lx; printf("XMag[%d]=%f\tXPhase[%d]=%f\n",k,X
Mag[k],k,XPhase[k]);
//Reading length of input sequence } //end of main
printf("\nEnter the length of input
sequence\n");
scanf("%d",&lx);
//Computing DFT
for(k=0;k<N;k++)
{
XReal[k]=0;
XImag[k]=0;
for(n=0;n<N;n++)
{
XReal[k]+=x[n]*cos(2*pi/N*k*n);
//real part
XImag[k]-
=x[n]*sin(2*pi/N*k*n); //imaginary
part
}
}
//Printing output
printf("\nThe DFT computed is\n");
for(k=0;k<n;k++)
printf("(%f)+1j*(%f)\n",XReal[k],XImag[k]
);
for(k=0;k<n;k++)
{
convolution
PROPERTIES OF LINEAR CONVOLUTION:
MATLAB CODE: a1 = 5 16 34 60 95 100 94 76
45
clc
clear all a2 =5 16 34 60 95 100 94 76
close all 45
x=input('enter the frist sequence x(n)=')
h=input('enter the second sequence h(n)=') a3 = Columns 1 through 8
d=input('enter the third sequence d(n)=') 5 26 86 232
lx=length(x) 494 850 1256 1604
lh=length(h)
ld=length(d)
Columns 9 through 13
1658 1446 1070 588
if ((ld==lx) & (lh==lx))
135
disp('testing all the proprieties of linear
convolution')
a4 =Columns 1 through 8
a1=conv(x,h) 5 26 86 232
a2=conv(h,x) 494 850 1256 1604
a3=conv(conv(x,h),d) Columns 9 through 13
a4=conv(x,conv(h,d)) 1658 1446 1070 588
a5=conv(x,(h+d)) 135
a6=conv(x,h)+conv(x,d)
a5 =6 20 45 86 139 156 155 128
if (a1==a2) 60
disp('commutative property is
satisfied!!'); a6 =6 20 45 86 139 156 155 128
else 60
disp('commutative property is not
satisfied!!'); commutative property is satisfied!!
end associative property is satisfied!!
if (a3==a4) distributive property is satisfied!!
disp('associative property is
satisfied!!');
else
disp('associative property is not
satisfied!!');
end
if (a5==a6)
disp('distributive property is
satisfied!!');
else
disp('distributive property is not
satisfied!!');
end
else disp('dimensional error of input
sequence');
end
OUTPUT
x =1 2 3 4 5
h =5 6 7 8 9
d =1 2 4 8 3
lx =5
lh =5
ld =5
y1=a*x11+b*x22
lhs=fft(y1,N)
rhs=((a.*X1)+(b.*X2))
disp(lhs)
disp(rhs)
OUTPUT:
x1 = 1 2 3 4 5
x2 =5 2 6 4 8
a =6
b = 4
N =4
y1 =26 20 42 40 62
lhs =1.0e+02 *
rhs =1.0e+02 *
clc
close all clc
clear all close all
clear all
x=input('enter the sequence of x(n):') x=input('enter tHe sequence of x(n):')
L=input('enter the value of L:')
L=input('enter tHe value of L:')
N=input('enter the value of N:')
x1=[x,zeros(1,N-length(x))]; N=input('enter tHe value of N:')
X=fft(x1,N) n=0:N-1;
k=0:N-1; X=fft(x,N);
w=exp(-i*2*pi*k*L/N);
LHS1=circshift(x1,L,2) lx=length(x);
y1=w.*X; w=exp(2*pi*n*L/N);
RHS1=ifft(y1,N)
x1=[x,zeros(1,(N-lx))];
y2=fft(circshift(x1,L,2),N);
lhs=fft(w.*x1,N)
LHS2=y2 rhs=circshift(X,L,2)
RHS2=y1
OUTPUT: OUTPUT:
enter tHe sequence of x(n):[1 2 3 4]
enter the sequence of x(n):[1 2 3 4 5]
x =1 2 3 4
x=1 2 3 4 5
enter tHe value of L:4
enter the value of L:5
enter tHe value of N:4
enter the value of N:4
lhs =1.0e+08 *
X =10.0000 + 0.0000i -2.0000 + 2.0000i -2.0000 + 0.0000i
6.1507 + 0.0000i -0.0086 + 6.1421i -
-2.0000 - 2.0000i 6.1335 + 0.0000i -0.0086 - 6.1421i
LHS1 = 1 2 3 4 5
rhs =10.0000 + 0.0000i -2.0000 + 2.0000i -
RHS1 =4.0000 + 0.0000i 1.0000 - 0.0000i 2.0000 - 0.0000i 2.0000 + 0.0000i -2.0000 - 2.0000i
3.0000 + 0.0000i
1.0e+02 *