34 lines
1.1 KiB
Matlab
34 lines
1.1 KiB
Matlab
function applyMovingAverage(freq_sampling, duration_signal, signal_constant, nbSamples, randomRange, plt)
|
|
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
|
% function applyMovingAverage(freq_sampling, duration_signal, signal_constant, nbSamples, randomRange, plt)
|
|
% ex.:applyMovingAverage(500, 10, 100, 10, 1);
|
|
%
|
|
% Task: To generate a digital constant signal with noise and apply moving
|
|
% average filter
|
|
%
|
|
% Inputs:
|
|
% -freq_signal: frequency of the signal (in Hz)
|
|
% -signal_contant:constant value of our signal(a.u.)
|
|
% -duration_signal: duration of the signal (in s)
|
|
% -signal_noise_range: range of noise in our signal(a.u.)
|
|
% -nbSamples:
|
|
% -plt: if greater than 0, signal will be plotted
|
|
%
|
|
% Outputs:None
|
|
%
|
|
% Author: Lymeng LY, lymeng.ly@ecam.fr
|
|
% Date: 07/04/2025
|
|
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
|
|
|
%generates time vector
|
|
t=0:1/freq_sampling:duration_signal;
|
|
|
|
%generate the signal samples
|
|
for l_sample=1:length(t)
|
|
signal(l_sample) = signal_constant + (rand()*(randomRange(2)-randomRange(1))+randomRange(1));
|
|
end
|
|
|
|
%apply the moving average filter
|
|
signal_filtered = movingAverage(t, signal,nbSamples, plt);
|
|
|