How can I filter/remove peaks in my curve? (not a signal)
10 次查看(过去 30 天)
显示 更早的评论
Hi all.
I am trying to remove the peaks from my data using the Signal Processing Toolbox, without success.
In my data, which values are attached, there are peaks which values are significantly lower than the "correct data" at the beginning, and afterwards I have peaks with both higher and lower values. Also, there are infinite values which are not plotted and I want to ignore.
I have tried different commands but as I am quite new to MatLab and my curve is not a signal, I am not sure if I am using the ToolBox correctly.
Every help will be very much appreciated. Thank you very much.
P.S. I know the image is from Excel but of course I am managing the data in MatLab.

0 个评论
采纳的回答
Star Strider
2019-12-30
It is not obvious what result you want. If you just want a regression line through your data, first use the fillmissing (R2016b and later) function to eliminate the non-finite gaps (first replace the Inf values with NaN), then use polyfit and polyval to do a simple regression and evaluation.
I have not looked at your data because I do not know what you want to do. However the best approach to filter design is first to do a Fourier transform (fft) on your data to understand its spectral characteristics, then design your filter to elimiinate the unwanted frequencies. Your data have to be regularly-sampled (constant sampling interval) of none of these will work correctly. If they do not have a constant sampling interval, use the resample function (after fillmissing) first to correct that.
8 个评论
Star Strider
2020-1-4
One problem I noticed with the data set you posted was that the data doubles back on itself. If you plot it as a line instead of points, that is easily apparent.
I am not certain how you want to deal with that problem.
One way might be to sort the data by the x-values, although with some of your data that might not be the most optimal solution.
Another way would be to only use the initial data to the maximum value of the x-vector (not the last value).
Using your posted ‘data.mat’, that would be:
D = load('data.mat');
x = D.data(:,1);
y = D.data(:,2);
y(isinf(y)) = NaN; % Replace ‘Inf’ with ‘NaN’
y2 = fillmissing(y, 'linear'); % Interpolate ‘NaN’ Values
[max_x,idx] = max(x); % Value & Index Of Maximum X-Value
xe = x(1:idx); % Trim Vector
y2e = y2(1:idx); % Trim Vector
P1 = polyfit(xe, y2e, 5); % Fit For Detrending
Yp1 = polyval(P1, xe); % Evaluated Fit For Detrending
y3e = y2e - Yp1; % Detrend
[y4e,TF] = rmoutliers(y3e, 'median'); % Remove Outliers From Detrended Data
yclean = y4e + Yp1(~TF); % Reconstitute Original Data
P2 = polyfit(xe(~TF), yclean, 7); % Fit ‘Cleaned’ Data To Arbitrary Polynomial
Yp2 = polyval(P2, xe); % Evaluate Fit Of ‘Cleaned’ Data To Arbitrary Polynomial With Original Data
figure
plot(xe, y2e, '.')
hold on
plot(xe, Yp2, '-r')
% plot(x(~TF), yclean)
hold off
grid
ylim([-1E+3 1E+4])
That seems to work well with this data set.
更多回答(0 个)
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!


