资源简介
matlab开发-信号平滑移动平均滤波器。matlab程序演示信号平滑或信号平均的概念
代码片段和文件信息
% Matlab Program to demonstrate the concpet of “Signal Smoothing“
% Signal Smoothing or Averaging is the Fundamental Noise Reduction Tool in
% 1-D Signal Processing Such as a Monotonic Signal Speech or Voice.
clc;
clear all;
close all;
% Initialise the Time
t = 0:0.001:1; % 0 -- Starting Time 0.001-- Sampling Time 1 -- Ending Time
% reading the size of the time
[mn] = size(t);
% Generation of sine wave
% amplitude
a = 2;
% frequency
f = 4;
% sine wave argument according to the definition
y = a*sin(2*pi*f*t);
% Generation of Random signal using “rand“ command in the matlab
% Please see the sintax of “rand“ command by typing help rand in the matlab
% command window
r = rand(mn);
% Note: Observer that we generated the random signal in the matlab using
% rand function such that size of the signal and random signal both are
% similar.
% Adding both signal and noise
y1 = (y + r);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%Implementation of Moving Average Filter or Smoothing Filter%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Algorithm:
% X(n-1) + X(n) + X(n+1)
% Y(n) = ----------------------
% 3
%
% here X(n) = noise effected signal
% Y(n) = Smoothed or averaged signal
% therefore
% Let‘s Initiliaze the for loop from 2:n-1 in order to validate the real
% meaning of (n-1) and (n+1)
% let the ouput smoothed signal is y2(n)
% Let‘s create an empty array y2(n) size equal to the size of the input
% signal
y2 = zeros(mn);
for i = 2:(n-1)
y2(i) = (y1(i-1) + y1(i) + y1(i+1))/3;
end
% therefore y2(i) will be the smoothed signal
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Lets plot the signals and see the output
subplot(411);
plot(ty); title(‘input signal‘);
subplot(412);
plot(tr); title(‘random signal‘);
subplot(413);
plot(ty1); title(‘noise added signal‘);
subplot(414);
plot(ty2); title(‘smoothed signal‘);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Please try this implementation an extension
% initiate a for loop for 2-4 times and make y2 = y1 i.e. we are making
% a feed back it becomes a recursive filter this will be the first step
% towards the implementation of Recursive filter
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% For any questions please send a mail to samudrala.naren@gmail.com
% Implemented by : Jagadeesh Samudrala Asst. Prof. Dept. of ECE Aditya
% Engineering College.
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
文件 2779 2015-09-26 04:10 signal_smoothing.m
文件 1549 2015-09-26 04:10 license.txt
评论
共有 条评论