81.1k views
3 votes
Write a MATLAB function named 'expansion' that calculates and plots for any arbitrary signal . The expansion function should create a longer vector by adding an additional element between neighboring elements in the original vector. Each new element be should equal to the average of its neighboring elements. Only use matrix/vector manipulations; do NOT use loops.

User Filth
by
3.4k points

1 Answer

0 votes

Answer:

Check the explanation

Step-by-step explanation:

function expansion = expansion(n)

%create a vector to store additional elements between neighboring elements

average_neighbor = 0.5 * (n(1:end-1) + n(2:end));

%creating the longer array "expansion" of zeros

%which has double the length of "average_neighbor"

%and original vector "n" combine.

lenA = length(average_neighbor)*2;

lenN = length(n)*2;

expansion = zeros(1,(lenA+lenN));

%place original vector n and average_neighbor in every second element after the starting point

expansion(1:2:lenN) = n;

expansion(2:2:lenA) = average_neighbor;

%removes 0 in the array

expansion(expansion == 0) = [];

stem(expansion)

end

%Please see the screen shot given below for more clarity

Write a MATLAB function named 'expansion' that calculates and plots for any arbitrary-example-1
User Skintkingle
by
3.9k points