Compare commits

..

2 Commits

Author SHA1 Message Date
Lymeng LY 6a1fafb4bb Modified file by copied from teacher 2025-04-09 14:29:19 +02:00
Lymeng LY 4cff4f1d49 Added new file of MovingAverage 2025-04-07 09:50:01 +02:00
3 changed files with 74 additions and 1 deletions

View File

@ -1,2 +1,2 @@
# SignalProcessing_filtering
Experiment basic digital filtering e.g. moving average
I am doing on filtering the siganl by using the MATLAB

33
applyMovingAverage.m Normal file
View File

@ -0,0 +1,33 @@
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);

40
movingAverage.m Normal file
View File

@ -0,0 +1,40 @@
function signal_filtered = movingAverage(t, signal, nbSamples, plt)
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% function signal_filtered = movingAverage(t, signal, nbSamples, plt)
% ex.: signal_filtered = movingAverage(t, signal, 10, 1);
%
% Task: To apply a moving average filter
%
% Inputs:
% -t: temporal vector(in s)
% -signal: signal amplitude (length is the same as t), in a.u
% -nbSamples=nb of samples taken into account to complete the moving
% amplitude
% -plot: flag if equal to 1, figures are displayed
%
% Outputs: -signal_filtered:filtered signal amplitude is a.u. after
% windowing
%
%
% Author: Lymeng LY, lymeng.ly@ecam.fr
% Date: 07/04/2025
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
signal_filtered = zeros(1,length(signal));
for l_samples = nbSamples:length(signal)
sum = 0;
for l_avg=0:nbSamples-1
sum = sum+signal(l_sample-l_avg);
end
signal_filtered(l_samples)= sum / nbSamples;
end
if(plt)
figure;
plot(t, signal, 'b'); hold on;
plot(t, signal_filtered, 'r');
ylim([99 101]);
xlabel('Time(s)');
ylabel('Amplitude(a.u.)');
legend('raw','filtered');
end