EEE 309
clc;
clear all;
F=10;
Fs=20;
n=0:0.0005:2/F;
x1=sin(2*pi*F*n+pi/6);
plot(n,x1)
hold on
Ts=0:(1/Fs):2/F;
x_s=sin(2*pi*F*Ts+(pi/6));
stem(Ts,x_s);
hold on
axis tight
n_new=0:0.0045:.2
x_new= interp1(n,x1,n_new)
plot(n_new,x_new,'r')
axis tight
clc;
clear all;
F=10;
Fs=20;
n=0:0.0005:2/F;
x1=sin(2*pi*F*n+pi/6);
plot(n,x1)
hold on
Ts=0:(1/Fs):2/F;
x_s=sin(2*pi*F*Ts+(pi/6));
stem(Ts,x_s);
hold on
axis tight
n_new=0:0.0045:.2
x_new= interp1(n,x1,n_new)
plot(n_new,x_new,'r')
axis tight
309_lab_1_part_a_interp.docx |
clc;
fs=100;
t=0:(1/fs):0.3;
x=10*sin(20*pi*t+(pi/6));
plot(t,x,'g')
stem(t,x,'r')
hold on
b=3;
L=2^b;
xmax= max(x)
xmin= min(x)
a=round(xmin);
c=round(xmax);
d=(c-a)/L-1;
for l=1:length(x)
for i=-c:1:c
if x(l)>=(i-d/2)x(l)<(i+d/2);
qu(l)=i*d;
end
end
end
n=0:.01:.3
j=interp1(t,qu,n)
plot(t,qu,'o',n,j);
axis tight
hold on;
grid on;
stem(t,qu)
fs=100;
t=0:(1/fs):0.3;
x=10*sin(20*pi*t+(pi/6));
plot(t,x,'g')
stem(t,x,'r')
hold on
b=3;
L=2^b;
xmax= max(x)
xmin= min(x)
a=round(xmin);
c=round(xmax);
d=(c-a)/L-1;
for l=1:length(x)
for i=-c:1:c
if x(l)>=(i-d/2)x(l)<(i+d/2);
qu(l)=i*d;
end
end
end
n=0:.01:.3
j=interp1(t,qu,n)
plot(t,qu,'o',n,j);
axis tight
hold on;
grid on;
stem(t,qu)
lab_01_part_b.docx |
clc;
clear all;
close all;
f=10;
A=1;
t=0:.01/f:1/f;
xt=A*sin(2*pi*f*t+(pi/6));
plot(t,xt);
hold on;
% sampling-----------------------------------------------------------------
fs=100;
n=0:1/fs:1/f;
xn=A*sin(2*pi*f*n+(pi/6));
stem(n,xn,'r');
grid on;
hold on;
% defining the array and level for quantization-------------------------
xq=zeros(1,length(xn));
b=3;
L=2^b;
del=(A+A)/(L-1);
Lq=zeros(1,L);
% setting quantized level-------------------------------------------------
for i=0:1:L-1
Lq(i+1)=-A+(i*del);
end
% quantization-------------------------------------------------------------
for j=1:1:length(xn)
for k=1:1:length(Lq)
if ((Lq(k)-(del/2)) < xn(j) && xn(j) < (Lq(k)+(del/2)));
xq(j)=Lq(k);
end
end
end
%stem(n,xq,'g');
%hold on
%Pe=(del^2)/12
%Px=(1^2)/2
%SNR=Px/Pe
%SNRdb=1.76+6*b
% reconstruction of signal-------------------------------------------------
ni=0:.1/fs:1/f;
yi=interp1(n,xq,ni);
plot(n,xq,'o',ni,yi,':.');
axis tight
%encoding of the quantized signal
U=0.23;
n=3;
q=U/(2^n-1)
t=0:1/fs:0.23;
y1=abs(A*sin(2*pi*f*t+(pi/6)));
a=fix(y1/q);
yd=dec2bin(a,n)
yq=a*q
stem(t,yq)
plot(t,yq,'r')
clear all;
close all;
f=10;
A=1;
t=0:.01/f:1/f;
xt=A*sin(2*pi*f*t+(pi/6));
plot(t,xt);
hold on;
% sampling-----------------------------------------------------------------
fs=100;
n=0:1/fs:1/f;
xn=A*sin(2*pi*f*n+(pi/6));
stem(n,xn,'r');
grid on;
hold on;
% defining the array and level for quantization-------------------------
xq=zeros(1,length(xn));
b=3;
L=2^b;
del=(A+A)/(L-1);
Lq=zeros(1,L);
% setting quantized level-------------------------------------------------
for i=0:1:L-1
Lq(i+1)=-A+(i*del);
end
% quantization-------------------------------------------------------------
for j=1:1:length(xn)
for k=1:1:length(Lq)
if ((Lq(k)-(del/2)) < xn(j) && xn(j) < (Lq(k)+(del/2)));
xq(j)=Lq(k);
end
end
end
%stem(n,xq,'g');
%hold on
%Pe=(del^2)/12
%Px=(1^2)/2
%SNR=Px/Pe
%SNRdb=1.76+6*b
% reconstruction of signal-------------------------------------------------
ni=0:.1/fs:1/f;
yi=interp1(n,xq,ni);
plot(n,xq,'o',ni,yi,':.');
axis tight
%encoding of the quantized signal
U=0.23;
n=3;
q=U/(2^n-1)
t=0:1/fs:0.23;
y1=abs(A*sin(2*pi*f*t+(pi/6)));
a=fix(y1/q);
yd=dec2bin(a,n)
yq=a*q
stem(t,yq)
plot(t,yq,'r')
eee309_partc_lab_1.docx |
a)
i)
clc;
close all;
clear all;
n=0:63;
x=2*sin(2*pi*(5/16)*n)+5*sin(2*pi*(3/16)*n);
L=length(x)
N=64;
X=zeros(1,N)
for k=0:1:N-1
for m=0:1:L-1
X(k+1)= X(k+1)+x(m+1)*exp(-i*2*pi*k*m/N)
end
end
K=0:1:N-1;
Y=(K/N);
figure
subplot(311)
stem(Y,abs(X));
legend('Y,abs(X)')
axis tight
subplot(312)
stem(K,X)
legend('x(k) vs k')
axis tight
ii)
clc
close all;
clear all;
n=0:63;
x=2*sin(2*pi*(5/16)*n)+5*sin(2*pi*(3/16)*n);
L=length(x)
N=128;
x=[x zeros(1,N-L)]
A=dftmtx(N)
X=x*A
K=0:1:N-1;
Y=(K/N);
subplot(311)
stem(Y,abs(X));
legend('Y,abs(X)')
axis tight
subplot(312)
stem(K,X)
legend('x(k) vs k')
axis tight
(iii)
clc
close all;
clear all;
n=0:63;
x=2*sin(2*pi*(5/16)*n)+5*sin(2*pi*(3/16)*n);
L=length(x)
N=64;
Y=fft(x,N)
stem(n,abs(Y));
axis tight
i)
clc;
close all;
clear all;
n=0:63;
x=2*sin(2*pi*(5/16)*n)+5*sin(2*pi*(3/16)*n);
L=length(x)
N=64;
X=zeros(1,N)
for k=0:1:N-1
for m=0:1:L-1
X(k+1)= X(k+1)+x(m+1)*exp(-i*2*pi*k*m/N)
end
end
K=0:1:N-1;
Y=(K/N);
figure
subplot(311)
stem(Y,abs(X));
legend('Y,abs(X)')
axis tight
subplot(312)
stem(K,X)
legend('x(k) vs k')
axis tight
ii)
clc
close all;
clear all;
n=0:63;
x=2*sin(2*pi*(5/16)*n)+5*sin(2*pi*(3/16)*n);
L=length(x)
N=128;
x=[x zeros(1,N-L)]
A=dftmtx(N)
X=x*A
K=0:1:N-1;
Y=(K/N);
subplot(311)
stem(Y,abs(X));
legend('Y,abs(X)')
axis tight
subplot(312)
stem(K,X)
legend('x(k) vs k')
axis tight
(iii)
clc
close all;
clear all;
n=0:63;
x=2*sin(2*pi*(5/16)*n)+5*sin(2*pi*(3/16)*n);
L=length(x)
N=64;
Y=fft(x,N)
stem(n,abs(Y));
axis tight
eee309_lab4_dft_fft.docx |