Matlab filter electical spikes in accelerometric data

前端 未结 5 1772
北海茫月
北海茫月 2020-12-03 20:22

I have a dataset of accelerometric data that is affected by electical spikes.

I\'m looking for a good method to filter out or reduce these spikes as need to calcula

5条回答
  •  长情又很酷
    2020-12-03 20:45

    A moderator merged this question with this question - that's why it looks a little messy here. This answer considers additional issues in the second question!

    The following is not an entirely clean solution, the code is adopted from my previous answer, but I added an exception for your case, so you don't need to delete values at the beginning and/or end of your data manually. It discards only these invalid values, that shouldn't cause problems.

    Af = csvread(strcat('example_data_with_peak.txt'),5,0); 
    
    % Thresholds
    Tl = -0.04;
    To = 0.04;
    
    % initialisation
    peaks = find( Af < Tl | Af > To);
    counter = 0;
    
    while ~isempty(peaks)
        peaks = find( Af < Tl | Af > To);
        try
            Af(peaks) = ( Af(peaks-1) + Af(peaks+1) ) / 2;
        catch
            if peaks(1) == 1
                Af(1) = 0;
            else
                Af(end) = 0;
            end
        end   
        counter=counter+1;
    end
    
    figure(2);
    plot(Af)
    

    enter image description here

    For determining the threshold you could use somethink like this, but it's also quite brute-force:

    thresh = 15*mean(abs(findpeaks(Af)));
    

提交回复
热议问题