MATLAB digital signal processing operations, write their own program to send up. Welcome to Exchange ~
QQ Wu 979064 First is any point moving average: Main program: MOV_AVERAGE_MAIN.M (Run) function: MOV_AVERAGE.M (multi-point moving average) /////////mov_average_ main.m///////////% Multi-point moving average close all;clear all;numsample=500; % sampling accuracy is 100l=input (' Please enter the window size for smoothing ' n '); if l>1 && l<50; % control of the input variable else error (' Your input is wrong! '); end;t = Linspace (0,pi/10,numsample); % Create vector a=10;% signal amplitude p=0;% signal phase s = A*sin (t+p),% generates sinusoidal signal N=randn (1,numsample),% with Gaussian random structure white noise y=s+n;% overlay white noise subplot (4,1,1); Plot (t,s, ' R '), title (' Original Signal '), subplot (4,1,2);p lot (t,n, ' B '), title (' White Noise signal '), subplot (4,1,3);p lot (t,y, ' K '), title (' Add white noise after signal '),% call Move smoothing function Y=mov_average (numsample,l,y),%numsample for sampling precision, window size nsubplot (4,1,4);p lot (t,y, ' K '); N-point movement smoothed after '); &NBSP;///////MOV_AVERAGE.M/////////function y=mov_average (numsample,n,f)%mov_average is a multi-point move smoothing function% The numsample is to use the precision%n for the window size that is used for smoothing, whose value should be greater than 0 and less than numsample%f for the function that needs to be moved smooth m=0;%m represents the point while the m<numsample-n+1;% sample point is being processed m=m +1;temp=0;%temp is used to calculate the sum of the value of the N-point function, where it is cleared 0 for p=0:1:n-1; %p is the sum of the values of the increment temp=temp+f (m+p)%n points of the variables in the window end;f (m) =temp/n;% mean value end;y=f;% back generation
MATLAB Programming Example (1) Moving average