필터 지우기
필터 지우기

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

조회 수: 2 (최근 30일)
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.

답변 (1개)

Pratyush Roy
Pratyush Roy 2020년 9월 3일
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:

카테고리

Help CenterFile Exchange에서 Signal Generation and Preprocessing에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by