how to remove spikes from the signal.

21 ビュー (過去 30 日間)
rohith bharadwaj
rohith bharadwaj 2017 年 8 月 29 日
回答済み: Saurabh Sinha 2018 年 10 月 24 日
I have a signal data of ultrasonic sensor. I had to remove the spikes from the plot. how do I do it? I have attached my text file and fig file. I want to remove the spikes from the plot

採用された回答

Star Strider
Star Strider 2017 年 8 月 29 日
I am not certain what you want as a result.
This will eliminate ‘spikes’ greater than 10 above than the detrended signal.
D = load('dataee.txt');
I = 1:length(D);
Ddt = detrend(D);
ia = Ddt > 10;
Dnew = D(~ia);
Inew = I(~ia);
figure(1)
plot(Inew, Dnew)
  3 件のコメント
Star Strider
Star Strider 2017 年 8 月 30 日
My pleasure.
They aren’t straight lines, so you cannot force them to be straight lines. The best you can do is apply a highpass filter to eliminate the low-frequency trends.
Also, you did not supply a time vector or sampling frequency, so I created one. My code should work with your actual time vector without need to change any other parts of my code. (No guarantees.)
I had to completely re-write my code to accommodate your new request. That required both detrending your signal and removing the mean. If the original trend and mean are significant, add them back.
This does what you want:
D = load('dataee.txt');
T = 1:length(D); % Time Vector
Ddt = detrend(D);
Dmean = mean(Ddt);
Ddt = Ddt-Dmean;
ia = Ddt > 10;
Ddt(ia) = Dmean; % Set Spikes = Mean
Dnew = Ddt;
Tnew = T;
figure(1)
plot(Tnew, Dnew) % Time Domain Plot Of Detrended & Despiked Signal
Ts = mean(diff(T)); % Sampling Interval
Fs = 1/Ts; % Sampling Frequency
L = length(Dnew);
FTD = fft(Dnew)/L; % Fourier Transform
Fv = linspace(0, 1, fix(L/2)+1)*Fs; % Frequency Vector
Iv = 1:length(Fv); % Index Vector
figure(2)
plot(Fv, abs(FTD(Iv))*2)
axis([0 0.1 ylim])
signal = Dnew; % Design & Implement Filter
Ts = mean(diff(T));
Fs = 1/Ts; % Sampling Frequency (Hz)
Fn = Fs/2; % Nyquist Frequency (Hz)
Wp = 0.030/Fn; % Passband Frequency (Normalised)
Ws = 0.032/Fn; % Stopband Frequency (Normalised)
Rp = 1; % Passband Ripple (dB)
Rs = 50; % Stopband Ripple (dB)
[n,Ws] = cheb2ord(Wp,Ws,Rp,Rs); % Filter Order
[z,p,k] = cheby2(n,Rs,Ws, 'high'); % Filter Design
[sosbp,gbp] = zp2sos(z,p,k); % Convert To Second-Order-Section For Stability
figure(3)
freqz(sosbp, 2^16, Fs) % Filter Bode Plot
filtered_signal = filtfilt(sosbp, gbp, signal); % Filter Signal
figure(4)
plot(Tnew, filtered_signal) % Plot Result
rohith bharadwaj
rohith bharadwaj 2017 年 9 月 3 日
thank you so much I have another question.
https://in.mathworks.com/matlabcentral/answers/355037-i-have-a-signal-with-many-frequencies-how-to-remove-a-particular-frequency-and-reconstruct-the-sign

サインインしてコメントする。

その他の回答 (2 件)

Jan
Jan 2017 年 8 月 29 日
Start with defining mathematically, what a spike is in your case. Does it differ by more than 3 standard deviations from the neighbors? Is it an absolute or relative threshold?
After this is defined, the implementation in Matlab is easy.
  1 件のコメント
rohith bharadwaj
rohith bharadwaj 2017 年 8 月 29 日
I think I can't use standard deviation.In my signal, if the difference between successive peaks is not zero then it is a spike. for finding peaks I've used findpeaks function.

サインインしてコメントする。


Saurabh Sinha
Saurabh Sinha 2018 年 10 月 24 日
@Star Strider This is my first time using this forum. I have a similar problem but I have a vertical curve with depth and sample values. Instead of detrending the signal, I want to extract the linear trends in the signal. See the attached image. How do i extract all linear trends from the signal? The trends are of different order i.e. some span over 100 samples, some span over 500 samples and so on.

カテゴリ

Help Center および File ExchangeSpectral Measurements についてさらに検索

タグ

製品

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by