Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write a program in a script file HW6P5.m to apply an averaging filter to the sig

ID: 3735689 • Letter: W

Question

Write a program in a script file HW6P5.m to apply an averaging filter to the signal stored in the file signal.mat (to be downloaded from UBlearns). Your program must load the signal from your current folder. Your program should ask the user for the number of data points to be averaged as an odd number bigger than 1. Your program should confirm that the user entered in an odd number bigger than 1. If the number is invalid, then the program should re-prompt the user to enter an odd number >1 The program must apply an averaging filter such that the total number pfaveraged points is equal to the number specified by the user centered on a given point. You may use the floor () function to determine the number of data points on either side of the central data point to use. All elements in the averaged signal that do not have enough data points surround them to average should be set to zero. For example: If the original signal has values of [9 10 2 6 7 14 15 4 14 15] and the user ente 3 as the odd number of averaging points the 1st element in the averaged signal will be zero since there are not enough points to average (element 11 for a total of 3 data points) the 2od element in the averaged signal will be the average of the first three elements of the original signal: 9:1042-7. the 3rd element in the averaged signal will be the average of the next three elements of the original signal: 1042+6 The same should be done for the end points that do not have enough points for the average. EAS 230-Spring 2018 Hw6 NAME: PERSON #: LAB SECTION The signal after being averaged should be [0 7 6 59 12 11 11 11 0] where the zeros at the ends are corresponding to signal values that do not have enough surrounding points to calculate their averages. Visualize your results using the following commands subplot (2,1,1): plot (originalsignal): subplot (2, 1,2): plot (averagedsignal) : Test your script by entering the following numbers in the command window a) 1, 4 and 10 b) 3, 5, and 7

Explanation / Answer

load signal.mat;%you havent provided the structure of data in signal.mat,
%so i am assuming it is stored as a vector signal. If it isnt, please tell in comments how
%it is stored so i can modify the code
k=1;
while k==1
k=0;
n=input('Enter data points to average: ');
if (mod(n,2)~=1)||(n<2)
fprintf('Number should be an odd integer >1! ')
k=1;
end
end
newSig=zeros(size(signal));
for i=(n+1)/2:length(signal)-(n-1)/2
newSig(i)=sum(signal(i-(n-1)/2:i+(n-1)/2))/n;
end
subplot(2,1,1);plot(signal);
subplot(2,1,2);plot(newSig);

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote