moving filter average with convolutional function

12 Ansichten (letzte 30 Tage)
Tu Nguyen
Tu Nguyen am 15 Feb. 2022
Kommentiert: Tu Nguyen am 16 Feb. 2022
For question 2i, I am confused that question, I have understanded in 2 ways:
firstly, we take N as a vector and find y[n] by con(1./N,ecg)
secondly, we take each number of N and multiplies to conv(ecg, h) with h is delta function.
Which way is correct?
Thank you so much for your answer

Akzeptierte Antwort

Image Analyst
Image Analyst am 15 Feb. 2022
No, N is not a vector it's a number, though you can make a vector from all the Ns:
allN = [2, 4, 8, 16, 32];
plot(ecg, 'b-', 'LineWidth', 3);
grid on;
for k = 1 : length(allN)
% Get this one N
N = allN(k);
% Construct kernel
h = ones(1, N) / N;
% Do the convolution, cropping to the same size as the input vector.
output = conv(ecg, h, 'same');
% Plot it.
hold on;
plot(output, '-');
% Create the string for the legend since all plots show up in different colors.
legendStrings{k} = sprintf('N = %2.2d', N);
end
legend(legendStrings);

Weitere Antworten (1)

Benjamin Thompson
Benjamin Thompson am 15 Feb. 2022
Are you asking how to define h in MATLAB?
>> h = ones(8,1)/8
h =
0.1250
0.1250
0.1250
0.1250
0.1250
0.1250
0.1250
0.1250
Then if you have an input signal ecf you can call conv(h, ecg)

Community Treasure Hunt

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

Start Hunting!

Translated by