Would like help on smoothing data a noisy data would using a central moving average by also using iteration and scalar operations.
3 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Jason
am 22 Sep. 2015
Kommentiert: Image Analyst
am 23 Sep. 2015
I'm not quite able to understand what the assignment is asking for. When it comes to "except k = 1 and k = N where x(1) = y(1).
The assignment explains this .. "Write a MATLAB program that will smooth a 1D array of noisy data using an averaging filter. The noisy data is stored in the MATLAB workspace file noisydata.mat. The data is stored in a 1D row array named x. The smoothing filter should process the 1 by N array of noisy data x and produce a 1 by N array of smoothed data y using a central moving average, y(k) = x(k-1) + x(k+1)/2 , except for k = 1 and k = N, where y(1) = x(1) and y(N) = x(N).
Your program
should plot the original noisy data versus the sample number (index) and the smoothed
data versus the sample number on separate axes in separate figure windows.
The program should perform all the operations using Iteration (for loops) and scalar
operations. Do not use element by element comparisons, element by element
mathematical operations, or MATLAB’s built in sum function.
clear; clc;
% load data
load('noisydata.mat','x');
k = 1;
avg = zeros(1,length(x));
% create smoothing filter using a central moving average
for vecVal = x
if k > 1
avg(k) = (x(k-1) + x(k+1))/2;
k = k + 1;
disp(avg)
end
end
0 Kommentare
Akzeptierte Antwort
Image Analyst
am 23 Sep. 2015
I assume you can't use conv() either since it says you must use for loops. So you're going to need two for loops, one over elements of x, and one over the window. Here's a start:
for k = 1 : length(x)-N
% Some code to initialize the sum
for wk = 1 : N
% More code to compute the sum
end
% More code to assign the sum to the output
end
2 Kommentare
Image Analyst
am 23 Sep. 2015
Looks like you ignored my answer. You have no loop over the window of N elements. You're just averaging the element to the right and left of the window center - no accommodation for N elements at all.
While I don't think that style of plotting you did will illustrate the smoothing effect in the best way (as compared to in the same plot), it is what the directions say to do.
Weitere Antworten (0)
Siehe auch
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!