How to smoothen a plot in MATLAB?

前端 未结 5 972
南方客
南方客 2021-01-31 10:37

I have some 9000 points that are plotted on a graph:

[Full resolution]

\"alt

Actually, the plot is n

5条回答
  •  隐瞒了意图╮
    2021-01-31 11:14

    If you have the Curve Fitting Toolbox, you can use the smooth function. The default method is a moving average of size 5 (method can be changed). An example:

    % some noisy signal
    Fs = 200; f = 5;
    t = 0:1/Fs:1-1/Fs;
    y = sin(2*pi*f*t) + 0.6*randn(size(t));
    subplot(411)
    plot(y), title('Noisy signal')
    
    % smoothed signal
    subplot(412)
    plot( smooth(y, 5, 'moving') ), title('smooth')
    ylim([-2 2])
    

    If not, you can use use your own window function using the filter function from core MATLAB:

    % equivalent to a moving average window
    wndwSize = 5;
    h = ones(1,wndwSize)/wndwSize;
    subplot(413)
    plot( filter(h, 1, y) ), title('filter + square window')
    
    % Guassian
    h = pdf('Normal',-floor(wndwSize/2):floor(wndwSize/2),0,1);
    subplot(414)
    plot( filter(h, 1, y) ), title('filter + Guassian window')
    

    screenshot

提交回复
热议问题