
Приложение
clc;
clear;
close all;
X=zeros(1,1000);
Y=zeros(1,1000);
X(1:100)=5;
Y(301:400)=1;
conv_R=conv(X,Y);
plot(conv_R);
title('Корреляция одного импульса');
xlabel('Время t');
ylabel('Значение');
X(300:400)=5;
Y(601:700)=1;
xcorr_R = xcorr(X,Y);
figure;
plot(xcorr_R);
title('Корреляция двух импульсов');
xlabel('Время t');
ylabel('Значение');
%2й пункт
t = 0 : 0.1 : 100;
shift=3;
pulse=0;
for i=1:10
pulse=pulse+rectpuls(t-shift,3);
shift=shift+3+10*rand;
end
figure;
plot(t,pulse),grid, set(gca,'FontSize',12);
title('Сигнал без периодичных повторов импульсов');
xlabel('Время t');
ylabel('U');
delayed_pulse=zeros (1,300);
delayed_pulse=[delayed_pulse,pulse];
xcorr_R2 = xcorr(pulse,delayed_pulse);
figure;
plot(xcorr_R2);
title('Корреляция');
xlabel('Время t');
ylabel('Значение');
Covariance=xcov(pulse,delayed_pulse);
figure;
plot(Covariance);
title('Ковариация');
xlabel('Время t');
ylabel('Значение');
% 3й пункт
figure;
out = awgn(delayed_pulse,0.3);
plot(delayed_pulse);
hold on;
plot(delayed_pulse+out);
legend('Sine Wave','Sine Wave with Noise');
title('Сигнал без периодичных повторов импульсов c шумом');
xlabel('Время t');
ylabel('U');
hold off;
%4 пункт
f = 2;
t = 1:0.01:5;
sin_x = sin(2*pi*f*t);
figure
hold on
plot(t,sin_x);
sin_x_noise = awgn(sin_x,10);
plot(t,(sin_x+sin_x_noise));
legend('Sine Wave','Sine Wave with Noise');
title('Синусоида с шумом');
xlabel('Время t');
ylabel('U');
hold off;
t=1:0.01:9;
xcorr_R3=xcorr(sin_x,(sin_x+sin_x_noise));
figure
plot(t,xcorr_R3),grid;
title('Корреляция');
xlabel('Время t');
ylabel('Значение');
% 5 пункт
barker = comm.BarkerCode('Length',11,'SamplesPerFrame',11);
Bar = barker();
Bar = Bar';
%Сформировали вектор временных отсчетов, значения которых нормированы
%относительно длительности всей последовательности
t = 0:(length(Bar)*11) - 1;
%Сформировали несущую
s0 = square(t);
%Промодулировали несущую кодом Баркера
s(1:121)=0;
for j=1:11
for i=1:11
s(:,i*j) = s0(:,i*j)*Bar(j);
end
end
%Построили результат
figure
hold on
plot(t, s,'r');
w_noise = awgn(s,10);
plot(t,w_noise,'y');
legend('Sine Wave','Sine Wave with Noise');
title('Промодулировали несущую кодом Баркера');
xlabel('Время t');
ylabel('U');
hold off
figure
xcorr_R4=xcorr(Bar);
plot(xcorr_R4), grid;
title('Автокорреляция');
xlabel('Время t');
ylabel('Значение');
% % % % %
K=0:1:10;
X=randi([0,1],1,11);
for i=1:length(X)
if X(i)==0
X(i)=-1;
end
end
w_noise2 = awgn(X,10);
figure
hold on
plot(K,X,'g'), grid;
plot(K,w_noise2,'r'), grid;
legend('Sine Wave','Sine Wave with Noise');
title('Рандомный сигнал с шумом');
xlabel('Время t');
ylabel('U');
hold off;
figure
R5=xcorr(X);
plot(R5), grid;
title('Автокорреляция');
xlabel('Время t');
ylabel('Значение');
% 6 задание
fn = 1;
fc=0.01;
m=0.5;
t =0:0.01:100;
mono = sin(2*pi*fc*t);
mat1 = mean(mono);
dispers1 = var(mono);
dispers12 = dispers1^(1/2);
lin = sin(2*pi*fc*t.^2);
mat2 = mean(lin);
dispers2 = var(lin);
dispers22 = dispers2^(1/2);
apl = sin(2*pi*fn*t).*(1+m*sin(2*pi*fc*t));
mat3 = mean(apl);
dispers3 = var(apl);
dispers32 = dispers3^(1/2);
s_cm=sin(2*pi*fc*(cos(0.5*t)).*t);
mat4 = mean(s_cm);
dispers4 = var(s_cm);
dispers44 = dispers4^(1/2);
s_pm=sin(2*pi*fn*t+5*cos(2*pi*t));
mat5 = mean(s_pm);
dispers5 = var(s_pm);
dispers55 = dispers5^(1/2);
figure;
subplot(5,1,1),histogram(mono);xlabel('mono');grid on;
subplot(5,1,2),histogram(lin);xlabel('lin');grid on;
subplot(5,1,3),histogram(apl);xlabel('apl');grid on;
subplot(5,1,4),histogram(s_cm);xlabel('s_cm');grid on;
subplot(5,1,5),histogram(s_pm);xlabel('s_pm');grid on;