5 point asymmetric moving average using past values

조회 수: 4 (최근 30일)
Luke Pretzie
Luke Pretzie 2016년 10월 26일
댓글: Luke Pretzie 2016년 10월 27일
Hello everyone, and thank you in advance for taking the time to inspect my question.
I am currently working on a code that will allow me to take a signal and apply a 5-point asymmetric moving average filter (Past Values) to it. In an attempt to do that, I have written the following code:
N = length(ECG); %The number of rows in the columns of the ECG data: Both columns contain 1040 rows
A = ECG(:,2); %The second column of the ECG data specifies amplitude
time = ECG(:,1); %The first column of the ECG data specifies the time point
for i = 5 : (N) %Sets a counter
asym5p(i)= mean(A(i-4:i)); %Creates a vector from the mean of the four previous terms & the term of interest
end
plot (time (5 : (N)), asym5p, 'm') %Plots the vector with time on the x-axis and voltage on the y-axis
xlabel('Time (sec)');
ylabel('Amplitude (Volts)');
title('5 Point Asymmetric Filter (Future)');
Despite my best efforts, I cannot understand why the code will not compile, as I keep receiving the error message "Vectors must be the same length."
Any insight into this would be greatly appreciated.
Regards,
Luke Pretzie

채택된 답변

Swarooph
Swarooph 2016년 10월 26일
Looks like when you are plotting, size of asym5p is 1x1040 while size of time (5 : (N)) is 1x1036. These need to be same length for plot to work. For e.g. if I change the following line
plot (time (5 : (N)), asym5p, 'm')
to the following line
plot (time , asym5p, 'm')
The code will work.
P.S: I generated ECG data as follows to run your code. For the future, consider attaching the data or provide the sample inputs for easy replication of code behavior.
ECG = rand(1040,2);
  댓글 수: 1
Luke Pretzie
Luke Pretzie 2016년 10월 27일
Yes, that seems to work, thank you!
I apologize for not including the ECG data, it came in an Excel File and I wasn't sure of how to upload that information.
-Luke Pretzie

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Applications에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by