Matlab filter electical spikes in accelerometric data

前端 未结 5 1777
北海茫月
北海茫月 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:56

    For others that may need this here's what I ended up using. Here's the data file data file link

    Thanks goes to @thewaywewalk

    Matlab filter electical spikes in accelerometric data

    clear all, clc,clf,tic
    aa=csvread(strcat('/tmp/example_data_with_peak.txt'),5,0); %will skip the first 5 rows that are text and zeros
    figure(1);
    plot(aa)
    Af=aa;
    % Thresholds
    Tl = -mean(abs(aa))*10
    To =mean(abs(aa))*10
    
    % initialisation
    [peaks_r,peaks_c] = find( Af < Tl | Af > To);
    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
    counter
    figure(2);
    plot(Af)
    

    Here are the images of before and after.

    Before and After

提交回复
热议问题