%% how to create a noisy data
x = 0:0.1:20; %creating a dummy data
y = sin(x); %finding a sine of the variable x
n = randn(1, length(x)); % generating a random (Gaussian) noise of size 1x length(x)
y_noisy = y+n; % creating the sine function noisy by adding the Gaussian noise
%% how to smooth the noisy data wout using any filter but using moving average
for rollingwindow=2:20 % specify the rolling averaging window
N = length(y_noisy);
m = N - rollingwindow + 1;
newy_noisy =zeros(m,1); % initializing the matrix
for i = 1:m
newy_noisy(i) = mean(y_noisy(i:i+(rollingwindow-1)));
end
%% here newy_noisy has to be defined in such a way it is not overwritten. But how?
figure();
plot(y, 'b');
hold on
plot(y_noisy, 'r')
hold on
plot(newy_noisy, 'k', 'linewidth', 1)
legend('theoretical','noisy','smooth')
title(['noisy vs smooth', sprintf('rollwindow = %d', rollingwindow)]);
outputFileName = sprintf('rollwin%d', rollingwindow);
outputFullFileName = fullfile('C:\Users\anusu\Desktop',outputFileName);
%saveas(gcf, outputFullFileName, 'png');
hold off
end
Can you look for this? If not, specify with more details