Скачиваний:
7
Добавлен:
25.12.2019
Размер:
1.53 Кб
Скачать
clear
close all
clc
% Белый шум
N=32768;
for i=1:1:N
A(i)=32768*rand(1,1);
end

f=hist(A,256);
s=zeros(1,1000);
ft=[0:256-1]*128;
t=[0:0.01:10-0.01];
for i=1:1:256
s=s+f(i)*sin(2*pi*128*(i-1)*t);
end
figure(1)
subplot(2,1,1)
stem(ft,10*log10(f))
axis([0 max(ft) min(10*log10(f)) max(10*log10(f))])
title('Спектр мощности белого шума')
xlabel('f, Гц')
ylabel('p(f), dB')
subplot(2,1,2)
plot(t,s)
axis([0 max(t) min(s) max(s)])
title('Сигнал белого шума')
xlabel('t, с')

% Розовый шум

N=32768;
for i=1:1:N
A(i)=rand(1,1);
A(i)=32768*exp(A(i));
end

f=hist(A,256);
s=zeros(1,1000);
ft=[0:256-1]*128;
t=[0:0.01:10-0.01];
for i=1:1:256
s=s+f(i)*sin(2*pi*128*(i-1)*t);
end
figure(2)
subplot(2,1,1)
stem(ft,10*log10(f))
axis([0 max(ft) min(10*log10(f)) max(10*log10(f))])
title('Спектр мощности розового шума')
xlabel('f, Гц')
ylabel('p(f), dB')
subplot(2,1,2)
plot(t,s)
axis([0 max(t) min(s) max(s)])
title('Сигнал розового шума')
xlabel('t, с')

% Синий шум

N=32768;
for i=1:1:N
A(i)=rand(1,1);
A(i)=32768*sqrt(2*A(i));
end

f=hist(A,256);
s=zeros(1,1000);
ft=[0:256-1]*128;
t=[0:0.01:10-0.01];
for i=1:1:256
s=s+f(i)*sin(2*pi*128*(i-1)*t);
end
figure(3)
subplot(2,1,1)
stem(ft,10*log10(f))
axis([0 max(ft) min(10*log10(f)) max(10*log10(f))])
title('Спектр мощности синего шума')
xlabel('f, Гц')
ylabel('p(f), dB')
subplot(2,1,2)
plot(t,s)
axis([0 max(t) min(s) max(s)])
title('Сигнал синего шума')
xlabel('t, с')