How to smoothen curve in Matlab?
5 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
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 Commento
Image Analyst
il 22 Mag 2016
Modificato: Image Analyst
il 22 Mag 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?
Risposta accettata
Più risposte (2)
Image Analyst
il 22 Mag 2016
Modificato: Image Analyst
il 22 Mag 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 Commenti
Image Analyst
il 23 Mag 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".
Vedere anche
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!