Removing jumps from data when plotting a graph

조회 수: 44(최근 30일)
I am trying to plot sensor readings. See attached the data and the graph. Please I need a help on how to remove those jumps in the graph (space between the 2 red markings). I would like to apply same to the remaing jumps in the graph. Any help is well appreciated.
  댓글 수: 4
Austin Ukpebor
Austin Ukpebor 2021년 1월 19일
Thanks Star Strider. I couldn't figure out on how to apply gradient function to my case using the link you shared. Please help me out, I have my data attached.
@Matt Gaidica, please share the code you used to generate your graph. When I used the diff() function, I had a different graph.

댓글을 달려면 로그인하십시오.

채택된 답변

Star Strider
Star Strider 2021년 1월 20일
I am not certain what result you want.
Try this:
D1 = readmatrix('SensorValues.xlsx');
s = D1; % Signal Vector
L = size(s,1); % Data Length
Fs = 1; % <— Need Actual Sampling Frequency Here!
Ts = 1/Fs; % Sampling Interval
Fn = Fs/2; % Nyquist Frequency
t = linspace(0, L, L)*Ts; % Time Vector
sc = s - mean(s); % Subtract Mean (Makes Other Peaks More Prominent)
FTs = fft(sc)/L; % Normalised Fourier Transform
Fv = linspace(0, 1, fix(L/2)+1)*Fn; % Frequency Vector
Iv = 1:numel(Fv); % Index Vector (One-Sided Fourier Transform)
plot(Fv, abs(FTs(Iv))*2)
xlim([0 0.001])
title('Fourier Transform')
xlabel('Frequency (Hz)')
Wp = [0.001 0.075]/Fn; % Passband Frequency (Normalised)
Ws = [0.9 1.1].*Wp; % Stopband Frequency (Normalised)
Rp = 1; % Passband Ripple
Rs = 60; % Passband Ripple (Attenuation)
[n,Wp] = ellipord(Wp,Ws,Rp,Rs); % Elliptic Order Calculation
[z,p,k] = ellip(n,Rp,Rs,Wp); % Elliptic Filter Design: Zero-Pole-Gain
[sos,g] = zp2sos(z,p,k); % Second-Order Section For Stability
freqz(sos, 2^20, Fs) % Filter Bode Plot
set(subplot(2,1,1), 'XLim',Wp*Fn.*[0.8 1.2]) % Optional
set(subplot(2,1,2), 'XLim',Wp*Fn.*[0.8 1.2]) % Optional
s_filtered = filtfilt(sos, g, s); % Filter With IIR Filter
plot(t, s)
hold on
plot(t, s_filtered)
hold off
xlabel('Time (Units Estimated)')
ylabel('AMplitude (Units Not Specified)')
legend('Original Signal', 'Bandpass-Filtered Signal', 'Location','W')
The filter eliminates the d-c (constant) offset, and a bit of the high-frequency noise. Adjust the upper limit of the ‘Wp’ vector to get the result you want.
Note — With the actual sampling frequency, it will be necessary to adjust the limits of ‘Wp’ and the xlim values of the Fourier Transform plot.
  댓글 수: 4
Star Strider
Star Strider 2021년 1월 21일
As always, my pleasure!

댓글을 달려면 로그인하십시오.

추가 답변(2개)

Fangjun Jiang
Fangjun Jiang 2021년 1월 19일
In your case, since you have enough data, I think you can use symbol in plot() to remove the "jump".
If your old way is plot(x,y), then you can use plot(x,y,'.')

Matt Gaidica
Matt Gaidica 2021년 1월 19일
What do you want to do with the data that around the jumps (still referring to my previous figure)? Interpolate it? Maybe you want some type of dynamic detrending, but it still doesn't totally remove the artifact of the jumps. I just loaded your data in A.
y = smoothdata(A,'movmean',100);
close all
hold on;
  댓글 수: 9
Matt Gaidica
Matt Gaidica 2021년 1월 21일
Sure thing, sounds like a cool project. Feel free to reach out directly if you need anything!

댓글을 달려면 로그인하십시오.


Community Treasure Hunt

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

Start Hunting!

Translated by