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

3 ビュー (過去 30 日間)
Lipi Vikram Thakker
Lipi Vikram Thakker 2020 年 8 月 31 日
回答済み: Pratyush Roy 2020 年 9 月 3 日
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 Center および File ExchangeSignal Generation and Preprocessing についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by