ssa

Форк
0
/
RaznFilter.m 
114 строк · 4.3 Кб
1
function [out, lower_prct, upper_prct] = RaznFilter(signal, threshold)
2
%     Nmed = 5;
3
%     signal = signal-medfilt1(signal, Nmed);
4
%     
5
%     % Ïåðâàÿ ðàçíîñòü ñèãíàëà
6
%     len = length(signal);
7
%     FirstRaznSignal = [signal(1), signal];
8
%     FirstRaznSignal = FirstRaznSignal-[signal, signal(len)];
9
%     
10
%     disp("Àïåðòóðà ôèëüòðà äëÿ insFrc_AcfNrm äëÿ ôèëüòðà ïðîöåíòèëåé: " + Nmed);  
11
%     prct = prctile(FirstRaznSignal, threshold);
12
% 
13
%     lower_prct=prct(1);
14
%     upper_prct=prct(2);
15
%     
16
%     disp("lower_prct " + lower_prct);
17
%     disp("upper_prct " + upper_prct);
18
%     
19
% %     signal=signal-medfilt1(signal, Nmed);
20
%     out = FirstRaznSignal;
21
%     
22
%     figure();
23
%     plot(FirstRaznSignal,'blue--'); hold on; grid on;
24
%     line('XData', [0 200], 'YData', [upper_prct upper_prct], 'Color','black','LineStyle','--');
25
%     line('XData', [0 200], 'YData', [lower_prct lower_prct], 'Color','black','LineStyle','--');
26
%     
27
%     index = 1;
28
%     MemoryValue = FirstRaznSignal(1);
29
%     
30
%     % Öèêë ïî âñåìó ñèãíàëó
31
%     for value = FirstRaznSignal
32
%         if (value < lower_prct || value > upper_prct)
33
%             out(index) = MemoryValue;
34
%         end
35
%        MemoryValue=out(index);
36
%        index=index+1;
37
%     end
38
%     plot(out,'red'); grid on;
39
%     ylabel("Hz",'interp','none'); xlabel("ns",'interp','none'); title("Ïåðâàÿ ðàçíîñòü"); grid on;
40
%     legend('Ïåðâàÿ ðàçíîñòü','down','up','Èíòåðïîëÿöèÿ', 'Location', 'southoutside');
41
    
42

43
    % Âû÷èñëåíèå ïåðâîé ðàçíèöû (àïïðîêñèìàöèÿ ïðîèçâîäíîé)
44
    difference = diff(signal);
45

46
    % Îïðåäåëåíèå ïîðîãà äëÿ ñãëàæèâàíèÿ ïðîâàëîâ
47
%     threshold = 5; % Ïðèìåð ïîðîãîâîãî çíà÷åíèÿ (çàìåíèòå íà âàøå ðåàëüíîå çíà÷åíèå)
48
    prct = prctile(difference, threshold);
49
    lower_prct=prct(1);
50
    upper_prct=prct(2);
51
    
52
    
53
%     figure('Position', [0 0 900 800]);
54
%     plot(difference,'blue'); hold on; grid on;
55
    len=length(signal);
56
%     line('XData', [0 len], 'YData', [upper_prct upper_prct], 'Color','black','LineStyle','--');
57
%     line('XData', [0 len], 'YData', [lower_prct lower_prct], 'Color','black','LineStyle','--');
58

59
%     line('XData', [0 200], 'YData', [threshold threshold], 'Color','green','LineStyle','--');
60
%     line('XData', [0 200], 'YData', [-threshold -threshold], 'Color','green','LineStyle','--');
61

62
%     % Ïðèìåíåíèå âçâåøåííîãî ñãëàæèâàíèÿ íà îñíîâå ïîðîãà
63
%     smoothedSignal = signal;
64
%     for i = 1:(length(difference))
65
%         xlim([i-5 i+5]);
66
%         disp(difference(j));
67
%         if i == 166
68
%             disp(166);
69
%         end
70
%         %if abs(difference(i)) > threshold
71
%         if (difference(i) < lower_prct || difference(i) > upper_prct)
72
%             % Åñëè ðàçíèöà ïðåâûøàåò ïîðîã, âûïîëíÿåì ñãëàæèâàíèå
73
% %             smoothedSignal(i+1) = (signal(i) + signal(i+1)) / 2; % Ïðîñòîå ñãëàæèâàíèå ïî ñðåäíåìó çíà÷åíèþ
74
%             j = i + 1;
75
%             while (difference(j) < lower_prct || difference(j) > upper_prct) && j ~= length(difference)-1
76
%                  j = j + 1;
77
%             end
78
%             smoothedSignal(i+1) = (signal(i) + signal(i+1)) / 2;
79
%         end
80
%     end
81

82
    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
83
    % Âû÷èñëåíèå ïåðâîé ðàçíèöû (àïïðîêñèìàöèÿ ïðîèçâîäíîé)
84
% difference = diff(signal);
85

86
% Îïðåäåëåíèå ïîðîãà äëÿ ñãëàæèâàíèÿ ïðîâàëîâ
87
threshold = 0.1; % Ïðèìåð ïîðîãîâîãî çíà÷åíèÿ (çàìåíèòå íà âàøå ðåàëüíîå çíà÷åíèå)
88

89
% Ïðèìåíåíèå âçâåøåííîãî ñãëàæèâàíèÿ íà îñíîâå ïîðîãà
90
smoothedSignal = signal;
91
for i = 1:length(difference)
92
    if abs(difference(i)) > threshold
93
        % Åñëè ðàçíèöà ïðåâûøàåò ïîðîã, âûïîëíÿåì ñãëàæèâàíèå
94
        smoothedSignal(i+1) = (signal(i) + signal(i+1)) / 2; % Ïðîñòîå ñãëàæèâàíèå ïî ñðåäíåìó çíà÷åíèþ
95
        % Ïðîâåðÿåì ñëåäóþùèå îòìåòêè íà ïðåâûøåíèå ïîðîãà è ñãëàæèâàåì èõ
96
        j = i + 1;
97
        while j < length(difference) && abs(difference(j)) > threshold
98
            smoothedSignal(j+1) = (signal(j) + signal(j+1)) / 2; % Ñãëàæèâàåì
99
            j = j + 1;
100
        end
101
    end
102
end
103
    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
104
    
105
    out = smoothedSignal;
106
    out = difference;
107
    
108
%     plot(out,'red'); grid on;
109
%     plot(signal,'green--'); grid on;
110
%     ylabel("Hz",'interp','none'); xlabel("ns",'interp','none'); title("Ïåðâàÿ ðàçíîñòü"); grid on;
111
%     legend('Ïåðâàÿ ðàçíîñòü','down','up','Èíòåðïîëÿöèÿ', 'Location', 'southoutside');
112
    
113
    
114
end

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.