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
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')
댓글 수: 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".
참고 항목
카테고리
Help Center 및 File Exchange에서 Electrophysiology에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!