how to remove spikes from the signal.

18 vues (au cours des 30 derniers jours)
rohith bharadwaj
rohith bharadwaj le 29 Août 2017
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

Réponse acceptée

Star Strider
Star Strider le 29 Août 2017
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 commentaires
Star Strider
Star Strider le 30 Août 2017
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 le 3 Sep 2017
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

Connectez-vous pour commenter.

Plus de réponses (2)

Jan
Jan le 29 Août 2017
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 commentaire
rohith bharadwaj
rohith bharadwaj le 29 Août 2017
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.

Connectez-vous pour commenter.


Saurabh Sinha
Saurabh Sinha le 24 Oct 2018
@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.

Catégories

En savoir plus sur Time-Frequency Analysis dans Help Center et File Exchange

Tags

Produits

Community Treasure Hunt

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

Start Hunting!

Translated by