Advertisement
kirill_76rus

Lab_2_RTC_Stat

Nov 10th, 2021
1,128
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
MatLab 10.65 KB | None | 0 0
  1. clear all;
  2. load("lab2_coeff.mat");
  3. MX = 0; %Constant value
  4. SIGMAX = 0.3; %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 = filter([1, -0.5], 1, ansambles(1, :));
  25. c1 = filter([1, 0.5], 1, ansambles(1, :));
  26. %part2 of circuits
  27. c2 = filter(1, [1, +0.9], ansambles(1, :));
  28. c3 = filter(1, [1, -0.9], ansambles(1, :));
  29. c4 = filter(Num, 1, ansambles(1, :));
  30. i = 1;
  31.    figure
  32.    plot(norm_time, ansambles(i, :));
  33.    hold on
  34.    title("Реализация случайного процесса");
  35.    xlabel("t, s");
  36.    ylabel("x(t), V");
  37.    plot(norm_time, mean(ansambles(i, :)) * ones(size(norm_time)));
  38.    plot(norm_time, std(ansambles(i, :)) * ones(size(norm_time)));
  39.    plot(norm_time, std(ansambles(i, :)) * -1 * ones(size(norm_time)));
  40.    plot(norm_time, var(ansambles(i, :)) * ones(size(norm_time)));
  41.    plot(norm_time, var(ansambles(i, :)) * -1 * ones(size(norm_time)));
  42.    grid on;
  43. %%end
  44.    %c0
  45.    figure
  46.    plot(norm_time, c0);
  47.    hold on
  48.    title("Реализация случайного процесса после прохождения цепи");
  49.    xlabel("t, s");
  50.    ylabel("x(t), V");
  51.    plot(norm_time, mean(c0) * ones(size(norm_time)));
  52.    plot(norm_time, std(c0) * ones(size(norm_time)));
  53.    plot(norm_time, std(c0) * -1 * ones(size(norm_time)));
  54.    plot(norm_time, var(c0) * ones(size(norm_time)));
  55.    plot(norm_time, var(c0) * -1 * ones(size(norm_time)));
  56.    %c1
  57.    figure
  58.    plot(norm_time, c1);
  59.    hold on
  60.    title("Реализация случайного процесса после прохождения цепи");
  61.    xlabel("t, s");
  62.    ylabel("x(t), V");
  63.    plot(norm_time, mean(c1) * ones(size(norm_time)));
  64.    plot(norm_time, std(c1) * ones(size(norm_time)));
  65.    plot(norm_time, std(c1) * -1 * ones(size(norm_time)));
  66.    plot(norm_time, var(c1) * ones(size(norm_time)));
  67.    plot(norm_time, var(c1) * -1 * ones(size(norm_time)));
  68.    %c2
  69.    figure
  70.    plot(norm_time, c2);
  71.    hold on
  72.    title("Реализация случайного процесса после прохождения цепи");
  73.    xlabel("t, s");
  74.    ylabel("x(t), V");
  75.    plot(norm_time, mean(c2) * ones(size(norm_time)));
  76.    plot(norm_time, std(c2) * ones(size(norm_time)));
  77.    plot(norm_time, std(c2) * -1 * ones(size(norm_time)));
  78.    plot(norm_time, var(c2) * ones(size(norm_time)));
  79.    plot(norm_time, var(c2) * -1 * ones(size(norm_time)));
  80.     %c3
  81.    figure
  82.    plot(norm_time, c3);
  83.    hold on
  84.    title("Реализация случайного процесса после прохождения цепи");
  85.    xlabel("t, s");
  86.    ylabel("x(t), V");
  87.    plot(norm_time, mean(c3) * ones(size(norm_time)));
  88.    plot(norm_time, std(c3) * ones(size(norm_time)));
  89.    plot(norm_time, std(c3) * -1 * ones(size(norm_time)));
  90.    plot(norm_time, var(c3) * ones(size(norm_time)));
  91.    plot(norm_time, var(c3) * -1 * ones(size(norm_time)));
  92.        %c4
  93.    figure
  94.    plot(norm_time, c4);
  95.    hold on
  96.    title("Реализация случайного процесса после прохождения цепи");
  97.    xlabel("t, s");
  98.    ylabel("x(t), V");
  99.    plot(norm_time, mean(c4) * ones(size(norm_time)));
  100.    plot(norm_time, std(c4) * ones(size(norm_time)));
  101.    plot(norm_time, std(c4) * -1 * ones(size(norm_time)));
  102.    plot(norm_time, var(c4) * ones(size(norm_time)));
  103.    plot(norm_time, var(c4) * -1 * ones(size(norm_time)));
  104. %автокорреляция
  105. figure
  106. plot(xcorr(ansambles(1, :)));
  107. title("Автокорреляция");
  108. i = 1;
  109.    figure
  110.    [counts, bins] = hist(ansambles(i, :));
  111.    hold on;
  112.    est_pdf = counts / sum(counts * mean(diff(bins)));
  113.    pd = fitdist(ansambles(1, :)','normal');
  114.    x_pdf = linspace(min(ansambles(i, :)),max(ansambles(i, :)),length(norm_time));
  115.    y_pdf = pdf(pd,x_pdf);
  116.    bar(bins,est_pdf);
  117.    plot(x_pdf, y_pdf, '-r');
  118.    title("плотность вероятности и ее оценка");
  119.    %c0
  120.    figure
  121.    plot(xcorr(c0));
  122.    title("Автокорреляция");
  123.    i = 1;
  124.    figure
  125.    [counts, bins] = hist(c0);
  126.    hold on;
  127.    est_pdf = counts / sum(counts * mean(diff(bins)));
  128.    pd = fitdist(ansambles(1, :)','normal');
  129.    x_pdf = linspace(min(ansambles(i, :)),max(ansambles(i, :)),length(norm_time));
  130.    y_pdf = pdf(pd,x_pdf);
  131.    bar(bins,est_pdf);
  132.    plot(x_pdf, y_pdf, '-r');
  133.    title("плотность вероятности и ее оценка");
  134.    
  135.    %c1
  136.    figure
  137.    plot(xcorr(c1));
  138.    title("Автокорреляция");
  139.    i = 1;
  140.    figure
  141.    [counts, bins] = hist(c1);
  142.    hold on;
  143.    est_pdf = counts / sum(counts * mean(diff(bins)));
  144.    pd = fitdist(ansambles(1, :)','normal');
  145.    x_pdf = linspace(min(ansambles(i, :)),max(ansambles(i, :)),length(norm_time));
  146.    y_pdf = pdf(pd,x_pdf);
  147.    bar(bins,est_pdf);
  148.    plot(x_pdf, y_pdf, '-r');
  149.    title("плотность вероятности и ее оценка");
  150.    
  151.    %c2
  152.    figure
  153.    plot(xcorr(c2));
  154.    title("Автокорреляция");
  155.    i = 1;
  156.    figure
  157.    [counts, bins] = hist(c2);
  158.    hold on;
  159.    est_pdf = counts / sum(counts * mean(diff(bins)));
  160.    pd = fitdist(ansambles(1, :)','normal');
  161.    x_pdf = linspace(min(ansambles(i, :)),max(ansambles(i, :)),length(norm_time));
  162.    y_pdf = pdf(pd,x_pdf);
  163.    bar(bins,est_pdf);
  164.    plot(x_pdf, y_pdf, '-r');
  165.    title("плотность вероятности и ее оценка");
  166.    
  167.    %c3
  168.    figure
  169.    plot(xcorr(c3));
  170.    title("Автокорреляция");
  171.    i = 1;
  172.    figure
  173.    [counts, bins] = hist(c3);
  174.    hold on;
  175.    est_pdf = counts / sum(counts * mean(diff(bins)));
  176.    pd = fitdist(ansambles(1, :)','normal');
  177.    x_pdf = linspace(min(ansambles(i, :)),max(ansambles(i, :)),length(norm_time));
  178.    y_pdf = pdf(pd,x_pdf);
  179.    bar(bins,est_pdf);
  180.    plot(x_pdf, y_pdf, '-r');
  181.    title("плотность вероятности и ее оценка");
  182.    
  183.    %c4
  184.    figure
  185.    plot(xcorr(c4));
  186.    title("Автокорреляция для фильтра");
  187.    i = 1;
  188.    figure
  189.    [counts, bins] = hist(c4);
  190.    hold on;
  191.    est_pdf = counts / sum(counts * mean(diff(bins)));
  192.    pd = fitdist(ansambles(1, :)','normal');
  193.    x_pdf = linspace(min(ansambles(i, :)),max(ansambles(i, :)),length(norm_time));
  194.    y_pdf = pdf(pd,x_pdf);
  195.    bar(bins,est_pdf);
  196.    plot(x_pdf, y_pdf, '-r');
  197.    title("плотность вероятности и ее оценка для фильтра");
  198.    
  199.    
  200.    %
  201.    figure
  202.    hold on
  203.    cdfplot(ansambles(i, :))
  204.    histogram(ansambles(1, :), 'Normalization', 'cdf');
  205.    title("Функция распределения и ее оценка");
  206.    figure
  207.    %PSD = periodogram(ansambles(1, :), [], length(ansambles(1, :)), fs, 'centered');
  208.    PSD = 10 * log10(abs(fft(ansambles(1, :))).^2/N/fs);
  209.    %PSD = fftshift(PSD);
  210.    plot(PSD);
  211.    title("СПМ");
  212.    ans_mean = zeros(1, length(ansambles(1, :)));
  213.    for i = 1: K
  214.        ans_mean(1, :) = ans_mean(1, :) + ansambles(i, :);
  215.    end
  216.    ans_mean = ans_mean / K;
  217.    figure
  218.    PSD_M= 10 * log10(abs(fft(ans_mean(1, :))).^2/N/fs);
  219.    plot(PSD_M);
  220.    hold on;
  221.    title("Усредненная СПМ");
  222. %end
  223.  
  224.    %с0
  225.    figure
  226.    hold on
  227.    cdfplot(c0)
  228.    histogram(c0, 'Normalization', 'cdf');
  229.    title("Функция распределения и ее оценка");
  230.    figure
  231.    %PSD = periodogram(ansambles(1, :), [], length(ansambles(1, :)), fs, 'centered');
  232.    PSD = 10 * log10(abs(fft(c0)).^2/N/fs);
  233.    %PSD = fftshift(PSD);
  234.    plot(PSD);
  235.    title("СПМ");
  236.    ans_mean = zeros(1, length(c0));
  237.    for i = 1: K
  238.        ans_mean(1, :) = ans_mean(1, :) + c0;
  239.    end
  240.    ans_mean = ans_mean / K;
  241.    figure
  242.    PSD_M= 10 * log10(abs(fft(ans_mean(1, :))).^2/N/fs);
  243.    plot(PSD_M);
  244.    hold on;
  245.    title("Усредненная СПМ");
  246.    
  247.    %c1
  248.    figure
  249.    hold on
  250.    cdfplot(c1)
  251.    histogram(c1, 'Normalization', 'cdf');
  252.    title("Функция распределения и ее оценка");
  253.    figure
  254.    %PSD = periodogram(ansambles(1, :), [], length(ansambles(1, :)), fs, 'centered');
  255.    PSD = 10 * log10(abs(fft(c1)).^2/N/fs);
  256.    %PSD = fftshift(PSD);
  257.    plot(PSD);
  258.    title("СПМ");
  259.    ans_mean = zeros(1, length(c1));
  260.    for i = 1: K
  261.        ans_mean(1, :) = ans_mean(1, :) + c1;
  262.    end
  263.    ans_mean = ans_mean / K;
  264.    figure
  265.    PSD_M= 10 * log10(abs(fft(ans_mean(1, :))).^2/N/fs);
  266.    plot(PSD_M);
  267.    hold on;
  268.    title("Усредненная СПМ");
  269.    
  270.    
  271.    %c2
  272.    figure
  273.    hold on
  274.    cdfplot(c2)
  275.    histogram(c2, 'Normalization', 'cdf');
  276.    title("Функция распределения и ее оценка");
  277.    figure
  278.    %PSD = periodogram(ansambles(1, :), [], length(ansambles(1, :)), fs, 'centered');
  279.    PSD = 10 * log10(abs(fft(c2)).^2/N/fs);
  280.    %PSD = fftshift(PSD);
  281.    plot(PSD);
  282.    title("СПМ");
  283.    ans_mean = zeros(1, length(c2));
  284.    for i = 1: K
  285.        ans_mean(1, :) = ans_mean(1, :) + c2;
  286.    end
  287.    ans_mean = ans_mean / K;
  288.    figure
  289.    PSD_M= 10 * log10(abs(fft(ans_mean(1, :))).^2/N/fs);
  290.    plot(PSD_M);
  291.    hold on;
  292.    title("Усредненная СПМ");
  293.    
  294.    %c3
  295.    figure
  296.    hold on
  297.    cdfplot(c3)
  298.    histogram(c3, 'Normalization', 'cdf');
  299.    title("Функция распределения и ее оценка");
  300.    figure
  301.    %PSD = periodogram(ansambles(1, :), [], length(ansambles(1, :)), fs, 'centered');
  302.    PSD = 10 * log10(abs(fft(c3)).^2/N/fs);
  303.    %PSD = fftshift(PSD);
  304.    plot(PSD);
  305.    title("СПМ");
  306.    ans_mean = zeros(1, length(c3));
  307.    for i = 1: K
  308.        ans_mean(1, :) = ans_mean(1, :) + c3;
  309.    end
  310.    ans_mean = ans_mean / K;
  311.    figure
  312.    PSD_M= 10 * log10(abs(fft(ans_mean(1, :))).^2/N/fs);
  313.    plot(PSD_M);
  314.    hold on;
  315.    title("Усредненная СПМ");
  316.    
  317.    
  318.    %c4
  319.    figure
  320.    hold on
  321.    cdfplot(c4)
  322.    histogram(c4, 'Normalization', 'cdf');
  323.    title("Функция распределения и ее оценка");
  324.    figure
  325.    %PSD = periodogram(ansambles(1, :), [], length(ansambles(1, :)), fs, 'centered');
  326.    PSD = 10 * log10(abs(fft(c4)).^2/N/fs);
  327.    %PSD = fftshift(PSD);
  328.    plot(PSD);
  329.    title("СПМ");
  330.    ans_mean = zeros(1, length(c4));
  331.    for i = 1: K
  332.        ans_mean(1, :) = ans_mean(1, :) + c4;
  333.    end
  334.    ans_mean = ans_mean / K;
  335.    figure
  336.    PSD_M= 10 * log10(abs(fft(ans_mean(1, :))).^2/N/fs);
  337.    plot(PSD_M);
  338.    hold on;
  339.    title("Усредненная СПМ");
  340. %end
  341.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement