MATLAB: How to smooth this plot

filtergraphnoise

So i have a large data set. I just copied here one set, as an example. I tried to use filters to get rid of those small spikes, but i ended up with just a completely straight line.
I split this data in thre sectoins (720 length each) , because I want to kee that stepping characteristic of it.
I am using R2017b edition of matlab, so there are many functions i cannot use to do this.
Could anyone help me with this?

Best Answer

Try this:
[D,S] = xlsread('Book1.xlsx');
signal = D(:,1);
L = size(signal,1);
Fs = 1; % Sampling Frequency (Default, Time Vector Or Sampling Frequency Not Provided)
Fn = Fs/2; % Nyquist Frequency
msig = signal - mean(signal);
FTsig = fft(msig)/L; % Subtract Mean (Makes FFT Easier To Interpret)
Fv = linspace(0, 1, fix(L/2)+1)*Fn; % Frequency Vector
Iv = 1:numel(Fv); % Index Vector
figure
plot(Fv, abs(FTsig(Iv))*2)
grid
xlim([0 0.05])
% Fs = 2250; % Sampling Frequency
% Fn = Fs/2; % Nyquist Frequency
Wp = 0.019*Fs/Fn; % Stopband Frequency (Normalised)
Ws = 1.2*Wp; % Passband 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,'low'); % Elliptic Filter Design: Zero-Pole-Gain
[sos,g] = zp2sos(z,p,k); % Second-Order Section For Stability
figure
freqz(sos, 2^18, Fs) % Filter Bode Plot
set(subplot(2,1,1), 'XLim',[0 Fs/5]) % Optional

set(subplot(2,1,2), 'XLim',[0 Fs/5]) % Optional
signal_filt = filtfilt(sos, g, signal); % Filter Signal
t = linspace(0, 1, L)/Fs; % Time Vector
figure
plot(t, signal, '-b')
hold on
plot(t, signal_filt, '-r', 'LineWidth',1.5)
hold off
grid
xlabel('Frequency')
ylabel('Amplitude')
legend('Original Signal', 'Filtered Signal', 'Location','SW')
It designs a lowpass filter that filters out most of the noise:
How can I smooth this plot - 2019 11 13.png
The stopband ‘Ws’ is set to be a specific multiplier of the passband frequency, so you only need to change ‘Wp’ to get different passband and stopband frequencies.
Experiment to get the result you want.