T Using Mathematical Expression
T Using Mathematical Expression
T Using Mathematical Expression
2. PROGRAMS:
FREQUENCY RESPONSE
clear all;
close all;
clc;
b=input('enter the numerator coefficients');
DFT COMPUTATION
clc;
close all;
clear all;
x1=input('enter the seq');
N1=length(x1);
for i=0:1:N1-1
for j=0:1:N1-1
Wn(i+1,j+1)=exp(((-1)*sqrt(-1)*2*pi*i*j)/N1);
end
end
xx=x1*Wn;
disp('x(k)');
disp(xx);
y=abs(xx);
o=angle(xx);
n=0:1:N1-1;
subplot(2,2,1);
plot(n,y);
xlabel('k---->');
ylabel('x(k)---->');
title('magnitude plot for dft');
subplot(2,2,2);
plot(n,o);
xlabel('k---->');
ylabel('x(k)---->');
title('phase plot for dft');
n=0:1:N1-1;
for i=0:1:N1-1
for j=0:1:N1-1
Wn(i+1,j+1)=exp(((1)*sqrt(-1)*2*pi*i*j)/N1);
end
end
yx=xx*Wn./N1;
disp('y(n)');
disp(abs(yx));
ya=abs(yx);
subplot(2,2,3);
plot(n,ya);
xlabel('n---->');
ylabel('x(n)---->');
title('magnitude plot for idft');
FFT COMPUTATION
clc;
clear all;
close all;
N=input('enter the length of FFT');
x=input('enter the input signal');
for i=0:1
v11(i+1)=x(4*i+1);
v12(i+1)=x(4*i+3);
v21(i+1)=x(4*i+2);
v22(i+1)=x(4*i+4);
end
v11k=dft(v11,N/4);
v12k=dft(v12,N/4);
v21k=dft(v21,N/4);
v22k=dft(v22,N/4);
N1=N/2;
for n=0:1:N/4-1
Wn1(n+1)=exp(((-1)*sqrt(-1)*2*pi*n)/N1);
end
v12kk =v12k.*Wn1;
F1k=v11k+v12kk;
F1nk=v11k-v12kk;
F1=[F1k F1nk];
v22kk =v22k.*Wn1;
F2k=v21k+v22kk;
F2nk=v21k-v22kk;
F2=[F2k F2nk];
for n=0:1:N/2-1
Wn1(n+1)=exp(((-1)*sqrt(-1)*2*pi*n)/N);
end
F2w =F2.*Wn1;
Xk=F1+F2w;
Xkn=F1-F2w;
XK=[Xk Xkn];
n=0:N-1;
stem(n,abs(XK));
figure(2);
an=angle(XK);
stem(n,an);
FREQUENCY SPECTRUM
N=256; % Total Number of Samples
fs=8000; % Sampling frequency
f=1000;
n=0:N-1;
% Now generate the sinusoidal signal
x=sin(2*pi*(f/fs)*n);
% Estimate its spectrum using fft command
X=fft(x);
magX=abs(X);
% Build up an appropriate frequency axis
fx=0:(N/2)-1; % first make a vector for f=0,1,2,...(N/2)-1
fx=(fx*fs)/N; % Now scale it so that it represents
frequencies in Hz
figure(1);
subplot(1,1,1);
plot(fx,20*log10(magX(1:N/2)));
grid;
title('Spectrum of a sinusoidal signal with f=1KHz');
xlabel('Frequency (Hz)');
ylabel('Magnitude (dB)');