smoothing a graph using matlab
이전 댓글 표시
how can I smooth data imported from one column (Excel sheet) using Matlab
how to smooth the corners?

채택된 답변
추가 답변 (1개)
Image Analyst
2022년 2월 20일
0 개 추천
You could use sgolayfilt() to fit a sliding window to the data. Window width would be about the width of one of those humps. It looks kind of like a sine or cosine wave thus you can fit it to a 4th or 5th order polynomial. Attach your data if you need more help.
댓글 수: 6
Abeer Aboul Azm
2022년 2월 20일
Image Analyst
2022년 2월 20일
Attached is a generic demo I wrote. Experiment around with different parameters. If you need more help, could you attach your actual data. Otherwise could you click the "Accept this answer" link?
Abeer Aboul Azm
2022년 2월 20일
Image Analyst
2022년 2월 20일
I really think you could have done it if you would have tried, but anyway, here is the simple moification I made. I read in your data (instead of creating some) with readmatrix, and I set the window width to 113 and the polynomial order to 5.
% Filter a noisy, 1-D sine wave signal using Savitzky-Golay filtering to reduce the noise.
clc; % Clear the command window.
close all; % Close all figures (except those of imtool.)
clear; % Erase all existing variables. Or clearvars if you want.
workspace; % Make sure the workspace panel is showing.
format long g;
format compact;
fontSize = 25;
% Read in data.
y = readmatrix('data.xlsx')
x = 1 : length(y);
% Plot the noisy signal
subplot(2,1,1);
plot(x, y, 'b-', 'LineWidth', 2);
grid on;
title('Noisy Signal', 'FontSize', fontSize);
xlabel('Index', 'FontSize', fontSize);
ylabel('Value', 'FontSize', fontSize);% Enlarge figure to full screen.
set(gcf, 'Units', 'Normalized', 'OuterPosition', [0, 0.04, 1, 0.96]);
% Give a name to the title bar.
set(gcf, 'Name', 'Demo by ImageAnalyst', 'NumberTitle', 'Off')
% Now smooth with a Savitzky-Golay sliding polynomial filter
windowWidth = 203-90; % Distance between a couple of peaks.
polynomialOrder = 5;
smoothY = sgolayfilt(y, polynomialOrder, windowWidth);
% Now it's done - it's smoothed. Now plot it.
subplot(2,1,2);
plot(x, smoothY, 'b-', 'LineWidth', 2);
grid on;
caption = sprintf('Smoothed Signal with window width = %d and polynomial order = %d', windowWidth, polynomialOrder);
title(caption, 'FontSize', fontSize);
xlabel('Index', 'FontSize', fontSize);
ylabel('Value', 'FontSize', fontSize);
% Put axis in the middle
ax = gca;
ax.XAxisLocation = 'origin';

Abeer Aboul Azm
2022년 2월 20일
Image Analyst
2022년 2월 20일
편집: Image Analyst
2022년 2월 20일
If it worked, can you click "Accept this answer" for the best answer? Thanks in advance.
카테고리
도움말 센터 및 File Exchange에서 Smoothing and Denoising에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!

