How to smoothen curve in Matlab?

3 views (last 30 days)
nancy
nancy on 22 May 2016
Answered: nancy on 24 May 2016
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 Comment
Image Analyst
Image Analyst on 22 May 2016
Edited: Image Analyst on 22 May 2016
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?

Sign in to comment.

Accepted Answer

nancy
nancy on 24 May 2016
Yes, that is ok.. Thank you very much.

More Answers (2)

Image Analyst
Image Analyst on 22 May 2016
Edited: Image Analyst on 22 May 2016
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 Comments
nancy
nancy on 23 May 2016
Hi, I have updated the graphic with a thicker line.
Image Analyst
Image Analyst on 23 May 2016
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".

Sign in to comment.


nancy
nancy on 24 May 2016
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!