How to smoothen curve in Matlab?
2 次查看(过去 30 天)
显示 更早的评论
Hi,
I want to smooth a graphic, I mean that; to remove the noises from the curve. I add the graphic and ".txt" datas in the attached file. I have plotted the graphic but how can I smooth the graphic and reduce noise? Could you please write code for this problem and help me?
Thanks a lot...
1 个评论
Image Analyst
2016-5-22
编辑:Image Analyst
2016-5-22
Do you have the Signal Processing Toolbox and/or the Curve Fitting Toolbox? And you haven't said that's noise. You have low data and high spikes. In some areas (like mass spectrometry) the spikes are the signal you want, and in some areas, they'd be noise. So what do you want?
采纳的回答
更多回答(2 个)
Image Analyst
2016-5-22
编辑:Image Analyst
2016-5-22
If you want to filter out spikes, then a modified median filter is one way. Play around with the threshold and median filter window width until you get what you want.
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 = 20;
data = importdata('test.txt');
x = data(:, 1);
y = data(:, 2);
subplot(2, 2, 1);
plot(x, y, 'b-');
grid on;
title('Original Data', 'FontSize', fontSize);
subplot(2, 2, 2);
histogram(y);
grid on;
title('Histogram', 'FontSize', fontSize);
spikes = y > 2000;
subplot(2, 2, 2);
plot(x, spikes, 'b-');
grid on;
title('Spike Locations', 'FontSize', fontSize);
subplot(2, 2, 3);
medianFilteredSignal = medfilt1(y, 251);
plot(x, medianFilteredSignal, 'b-');
grid on;
title('Filtered Data', 'FontSize', fontSize);
noSpikes = y; % Initialize
noSpikes(spikes) = medianFilteredSignal(spikes);
subplot(2, 2, 4);
plot(x, noSpikes, 'b-');
grid on;
title('Repaired Data', 'FontSize', fontSize);
% Set up figure properties:
% Enlarge figure to full screen.
set(gcf, 'Units', 'Normalized', 'OuterPosition', [0 0 1 1]);
% Get rid of tool bar and pulldown menus that are along top of figure.
set(gcf, 'Toolbar', 'none', 'Menu', 'none');
% Give a name to the title bar.
set(gcf, 'Name', 'Demo by ImageAnalyst', 'NumberTitle', 'Off')
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/174343/image.png)
4 个评论
Image Analyst
2016-5-23
Attach a PNG file so we can see it easier. OK, I'm assuming you're done then? If so, you can please "Accept this Answer".
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!