pds3
🧩 Syntax:
%ex. 1
clear variables;
Fc = 10^5;
Fs = 10^6;
Fm = 10^4;
m = 0.2;
m2 = 1.2;
n = 0:199;
xm = sin(2*pi*Fm/Fs*n);
xc = sin(2*pi*Fc/Fs*n);
x_MA = (1+m*xm).*xc;
x_MA_PS = (m*xm).*xc;
x_MA2 = (1+m2*xm).*xc;
x_MA_PS2 = (m2*xm).*xc;
figure,
subplot(411), stem(n, x_MA),
subplot(412), stem(n, x_MA_PS),
subplot(413), stem(n, x_MA2),
subplot(414), stem(n, x_MA_PS2),
%ex. 2
clear variables;
n = 0:99;
Fs = 50*10^3;
Fa1 = 20*10^3;
Fa2 = 25*10^3;
Fa3 = 30*10^3;
x1 = cos(2*pi*Fa1/Fs*n);
x2 = cos(2*pi*Fa2/Fs*n);
x3 = cos(2*pi*Fa3/Fs*n);
figure,
subplot(3,1,1); stem(n,x1);
subplot(3,1,2); stem(n,x2);
subplot(3,1,3); stem(n,x3);
%Ex. 3
clear variables;
n = 0:100;
Fs = 10^3;
Fa = 100;
x = 2*cos(2*pi*Fa/Fs*n+pi/4);
x_bialternanta = abs(x);
x_ma = (x+x_bialternanta)/2;
figure,
subplot(311), plot(n, x);
subplot(312), plot(n,x_bialternanta);
subplot(313), plot(n, x_ma);
%ex. 4
clear variables;
Fa = 200; %frecv semnal analogic
Fs = 800; %freecv esantionare
L = 10; %raportul dintre frecv de simulare si esantionare
P = 10; %nr perioade pentru semnalul analogic
%x_a(t)
t = 0:1/(L*Fs):P/Fa-1/(L*Fs); %interval timp analogic
xa = cos(2*pi*Fa*t);
figure, plot(t, xa), grid,
xlabel('Timp [s]'), ylabel('Amplitudine'), title('Semnalul analogic (simulat) x_a(t)')
%semnalul discret in timp x(n)
xn = xa(1:L:length(xa));
n = 0:length(xn)-1; %timpul discret
N = seqperiod(xn, 1e-10) %perioada
figure, stem(n, xn), grid, axis([0 max(n) -1 1]),
xlabel('n'), ylabel('Amplitudine'),
title('Secventa discreta obtinuta dupa esantionare x(n)'),
%semnal analogic care poate fi reconstruit din esantionare
%xa_rect = sum[x(n)*sinc(Fs(t-n/Fs))]; sinc(x) = sin(pi*x)/(pi*x)
%matricele de timp pentru reconstruire length(n) x length(t) (40 x 400)
%t = n/Fs
tr = repmat(t, length(xn), 1); %matricea de timp(analogic)
nr = repmat(n', 1, length(t)); %matricea de timp (discret)
xa_rec = xn*sinc(Fs*(tr-nr/Fs));
figure, plot(t, xa_rec), grid, xlim([0 max(t)]),
title('Semnalul reconstituit x_{a,rec}(t)'), xlabel('Timp [s]'), ylabel('Amplitudine'),
%semnalul analogic initial, secventa discreta obtinuta, semnalul analogic
%reconstituit
te = 3*(length(t)/P):(P-3)*(length(t)/P);
ne = 3*N+1:(P-3)*N+1;
figure, subplot(311),
plot(t(te), xa(te)), grid, xlim([t(te(1)) t(te(end))]),
xlabel('t[s]'), ylabel('x_a(t)')
subplot(312), stem(n(ne), xn(ne)), grid, xlabel('n'), ylabel('x(n)')
subplot(313), plot(t(te), xa(te)), hold all
plot(t(te), xa_rec(te), '--'), hold off; grid, xlim([t(te(1)) t(te(end))]),
xlabel('t[s]'), ylabel('x_{a, rec}(t)')
%ex. 5
clear variables;
Fa1 = 100;
Fa2 = 300;
Fa3 = 400;
Fa4 = 500;
Fa5 = 600;
%frecv semnal analogic
Fs = 900; %freecv esantionare
L = 10; %raportul dintre frecv de simulare si esantionare
P = 10; %nr perioade pentru semnalul analogic
%x_a(t)
t1 = 0:1/(L*Fs):P/Fa1-1/(L*Fs);
t2 = 0:1/(L*Fs):P/Fa2-1/(L*Fs);
t3 = 0:1/(L*Fs):P/Fa3-1/(L*Fs);
t4 = 0:1/(L*Fs):P/Fa4-1/(L*Fs);
t5 = 0:1/(L*Fs):P/Fa5-1/(L*Fs);%interval timp analogic
xa1 = cos(2*pi*Fa1*t1);
xa2 = cos(2*pi*Fa2*t2);
xa3 = cos(2*pi*Fa3*t3);
xa4 = cos(2*pi*Fa4*t4);
xa5 = cos(2*pi*Fa5*t5);
figure,
subplot(511), plot(t1, xa1), grid,
xlabel('Timp [s]'), ylabel('Amplitudine'), title('Semnalul analogic (simulat) x_a(t)')
subplot(512), plot(t2, xa2), grid,
xlabel('Timp [s]'), ylabel('Amplitudine'), title('Semnalul analogic (simulat) x_a(t)')
subplot(513), plot(t3, xa3), grid,
xlabel('Timp [s]'), ylabel('Amplitudine'), title('Semnalul analogic (simulat) x_a(t)')
subplot(514), plot(t4, xa4), grid,
xlabel('Timp [s]'), ylabel('Amplitudine'), title('Semnalul analogic (simulat) x_a(t)')
subplot(515), plot(t5, xa5), grid,
xlabel('Timp [s]'), ylabel('Amplitudine'), title('Semnalul analogic (simulat) x_a(t)')
%semnalul discret in timp x(n)
xn1 = xa1(1:L:length(xa1));
n1 = 0:length(xn1)-1; %timpul discret
N1 = seqperiod(xn1, 1e-10) %perioada
figure, stem(n1, xn1), grid, axis([0 max(n1) -1 1]),
xlabel('n'), ylabel('Amplitudine'),
title('Secventa discreta obtinuta dupa esantionare x(n)'),
xn2 = xa2(1:L:length(xa2));
n2 = 0:length(xn2)-1; %timpul discret
N2 = seqperiod(xn2, 1e-10) %perioada
figure, stem(n2, xn2), grid, axis([0 max(n2) -1 1]),
xlabel('n'), ylabel('Amplitudine'),
title('Secventa discreta obtinuta dupa esantionare x(n)'),
%t = n/Fs
tr = repmat(t1, length(xn1), 1); %matricea de timp(analogic)
nr = repmat(n1', 1, length(t1)); %matricea de timp (discret)
xa_rec = xn1*sinc(Fs*(tr-nr/Fs));
figure, plot(t1, xa_rec), grid, xlim([0 max(t1)]),
title('Semnalul reconstituit x_{a,rec}(t)'), xlabel('Timp [s]'), ylabel('Amplitudine'),
%Ex. 6
clear variables;
n = 0:200;
x = 3*cos(2*pi*0.15*n) + 2*cos(2*pi*0.1*n);
w = randn(1, length(n));
y = x + w;
%evaluare corelatii
[r_xx, x_lags] = xcorr(x, 'biased'); %autocorelatie x(n)
[r_ww, w_lags] = xcorr(w, 'biased'); %autocorelatie w(n)
[r_xw,xw_lags] = xcorr(x, w, 'biased'); %autocorelatie x(n), w(n)
[r_wx, wx_lags] = xcorr(w, x, 'biased'); %autocorelatie w(n), x(n)
[r_yy, y_lags] = xcorr(y, 'biased'); %autocorelatie y(n)
figure,
subplot(421), stem(n, x), grid, xlabel('n'), ylabel('x(n)'),
subplot(422), stem(x_lags, r_xx), grid,
subplot(423), stem(n, w), grid, xlabel('n'), ylabel('w(n)'),
subplot(424), stem(w_lags, r_ww), grid,
subplot(425), stem(xw_lags, r_xw), grid,
subplot(426), stem(wx_lags, r_wx), grid,
subplot(427), stem(n, y), grid, xlabel('n'), ylabel('y(n)')
subplot(428), stem(y_lags, r_yy), grid,