How to smoothen curve in Matlab?

3 次查看(过去 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
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?

请先登录,再进行评论。

采纳的回答

nancy
nancy 2016-5-24
Yes, that is ok.. Thank you very much.

更多回答(2 个)

Image Analyst
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')
  4 个评论
nancy
nancy 2016-5-23
Hi, I have updated the graphic with a thicker line.
Image Analyst
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".

请先登录,再进行评论。


nancy
nancy 2016-5-24
And also I have a question. You see my graphic in the attached file. I want to show x-axis as; 10,20,30,40,50,60,70,80,90 and 100. I mean that; I want to divide x-axis between 10 and 100 by 10 step. I send to you the code that I write:
clear;
load -ascii test.txt;
degree1=test(:,1);
Intensity1=test(:,2);
freq=logspace(log10(10),log10(100),9001);
figure; loglog(freq,test(:,2), 'b', 'Linewidth',3);
set(gca,'Fontsize',14,'Linewidth',2);
I want the y-axis to remain as I show in the graphic.. But I want to show x-axis as I told. Could you please help me on this point?
I send also .txt document.

标签

Community Treasure Hunt

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

Start Hunting!

Translated by