kirill_76rus

Lab_3

Nov 24th, 2021
1,253
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
MatLab 4.32 KB | None | 0 0
  1. clear all;
  2. load("lab2_coeff.mat");
  3. MX = 3; %Constant value
  4. SIGMAX = 0.5; %Mean square deviations
  5. N = 10000; %Count samples
  6. K = 100;%Count realizations of process
  7. fs = 1000; %Freuency of sampling
  8. amp = 10;
  9. ansambles = zeros(K, N);
  10. %TODO norming Fsampling with time value
  11. x = normrnd(MX, SIGMAX, 1, N);
  12. %Generate random process
  13. for i = 1:K
  14.     ansambles(i, :) =amp * normrnd(MX, SIGMAX, 1, N);
  15. end
  16. norm_time = zeros(1, N);
  17. %Math time norming
  18. for i = 1:N
  19.    norm_time(i) = i/fs;
  20. end
  21. %Plot graph
  22. %for i = 1: K
  23. %Create array after circuits
  24. %c0 = ansambles(1, :).^2;
  25. c0 = ansambles(1, :).^2;
  26. i = 1;
  27.    figure
  28.    plot(norm_time, ansambles(i, :));
  29.    hold on
  30.    title("Реализация случайного процесса");
  31.    xlabel("t, s");
  32.    ylabel("x(t), V");
  33.    plot(norm_time, mean(ansambles(i, :)) * ones(size(norm_time)));
  34.    plot(norm_time, std(ansambles(i, :)) * ones(size(norm_time)));
  35.    %plot(norm_time, std(ansambles(i, :)) * -1 * ones(size(norm_time)));
  36.    %plot(norm_time, var(ansambles(i, :)) * ones(size(norm_time)));
  37.    %plot(norm_time, var(ansambles(i, :)) * -1 * ones(size(norm_time)));
  38.    grid on;
  39. %%end
  40.    %c0
  41.    figure
  42.    plot(norm_time, c0);
  43.    hold on
  44.    title("Реализация случайного процесса после квадратичного преобразователя");
  45.    xlabel("t, s");
  46.    ylabel("x(t), V");
  47.    plot(norm_time, mean(c0) * ones(size(norm_time)));
  48.    plot(norm_time, std(c0) * ones(size(norm_time)));
  49.    %plot(norm_time, std(c0) * -1 * ones(size(norm_time)));
  50.    %plot(norm_time, var(c0) * ones(size(norm_time)));
  51.    %plot(norm_time, var(c0) * -1 * ones(size(norm_time)));
  52.    
  53. %автокорреляция
  54. figure
  55. plot(xcorr(ansambles(1, :)));
  56. title("Автокорреляция");
  57. i = 1;
  58.    figure
  59.    [counts, bins] = hist(ansambles(i, :));
  60.    hold on;
  61.    est_pdf = counts / sum(counts * mean(diff(bins)));
  62.    pd = fitdist(ansambles(1, :)','normal');
  63.    x_pdf = linspace(min(ansambles(i, :)),max(ansambles(i, :)),length(norm_time));
  64.    y_pdf = pdf(pd,x_pdf);
  65.    bar(bins,est_pdf);
  66.    plot(x_pdf, y_pdf, '-r');
  67.    title("плотность вероятности и ее оценка");
  68.    %c0
  69.    figure
  70.    plot(xcorr(c0));
  71.    title("Автокорреляция после квадратичного преобразователя");
  72.    i = 1;
  73.    figure
  74.    [counts, bins] = hist(c0);
  75.    %hist(c0);
  76.    hold on;
  77.    est_pdf = counts / sum(counts * mean(diff(bins)));
  78.    pd = fitdist(c0','normal');
  79.    x_pdf = linspace(min(c0),max(c0),length(norm_time));
  80.    y_pdf = pdf(pd,x_pdf);
  81.    bar(bins,est_pdf);
  82.    plot(x_pdf, y_pdf, '-r');
  83.    title("плотность вероятности и ее оценка после квадратичного преобразователя");
  84.    
  85.    %
  86.    figure
  87.    hold on
  88.    cdfplot(ansambles(i, :))
  89.    histogram(ansambles(1, :), 'Normalization', 'cdf');
  90.    title("Функция распределения и ее оценка");
  91.    figure
  92.    %PSD = periodogram(ansambles(1, :), [], length(ansambles(1, :)), fs, 'centered');
  93.    PSD = 10 * log10(abs(fft(ansambles(1, :))).^2/N/fs);
  94.    %PSD = fftshift(PSD);
  95.    plot(PSD);
  96.    title("СПМ");
  97.    ans_mean = zeros(1, length(ansambles(1, :)));
  98.    for i = 1: K
  99.        ans_mean(1, :) = ans_mean(1, :) + ansambles(i, :);
  100.    end
  101.    ans_mean = ans_mean / K;
  102.    figure
  103.    PSD_M= 10 * log10(abs(fft(ans_mean(1, :))).^2/N/fs);
  104.    plot(PSD_M);
  105.    hold on;
  106.    title("Усредненная СПМ");
  107. %end
  108.  
  109.    %с0
  110.    figure
  111.    hold on
  112.    cdfplot(c0)
  113.    histogram(c0, 'Normalization', 'cdf');
  114.    title("Функция распределения и ее оценка после квадратичного преобразователя");
  115.    figure
  116.    %PSD = periodogram(ansambles(1, :), [], length(ansambles(1, :)), fs, 'centered');
  117.    PSD = 10 * log10(abs(fft(c0)).^2/N/fs);
  118.    %PSD = fftshift(PSD);
  119.    plot(PSD);
  120.    title("СПМ после квадратичного преобразователя");
  121.    ans_mean = zeros(1, length(c0));
  122.    for i = 1: K
  123.        ans_mean(1, :) = ans_mean(1, :) + c0;
  124.    end
  125.    ans_mean = ans_mean / K;
  126.    figure
  127.    PSD_M= 10 * log10(abs(fft(ans_mean(1, :))).^2/N/fs);
  128.    plot(PSD_M);
  129.    hold on;
  130.    title("Усредненная СПМ после квадратичного преобразователя");
  131. %end
  132.  
Advertisement
Add Comment
Please, Sign In to add comment