Matlab function which convolves a one dimensional signal with a one dimensional filter

3 visualizaciones (últimos 30 días)
Write a Matlab function which convolves a one dimensional signal with a one dimensional filter. The resulting signal should have the same length as the original signal. Choose a boundary condition which you think is appropriate and state it in your report. Matlab has routines which can do this job, e.g. “conv”. You should not use those routines, write your own version of it. You may use those for checking your code, e.g. comparing your results and results from Matlab. Print out your Matlab code.

Respuestas (1)

Pratyush Roy
Pratyush Roy el 3 de Sept. de 2020
The following code snippet defines a function for 1D convolution:
function z = conv1D(x,y)
l = length(x);
z = zeros(2*l-1,1); % For 2 sequences of length 'l', the full convolution length is '2*l-1'
for i=0:(2*l-2)
temp = 0;
for j=0:l-1
if (i-j>=0 && i-j<=l-1)
temp = temp+x(i-j+1)*y(j+1);
end
end
z(i+1) = temp;
end
%Consider the sub-sequence in the middle of the original sequence
if mod(l,2)==0 %If l is an even number
z = z((l/2+1):(3*l/2));
else %if l is an odd number
z = z((l+1)/2:(3*l-1)/2);
end
end
The output is same as that obtained from the command:
conv(x,y,'same')
You can refer to the following documentation for further help:

Categorías

Más información sobre Signal Generation and Preprocessing en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by