필터 지우기
필터 지우기

Discrete convolution.

조회 수: 2 (최근 30일)
omar chavez
omar chavez 2011년 11월 26일
Hi, im trying to make certain examples of convolution codes for a function with N elements. so far I have done this. But I wish to find out a way so that it can be implemented on C too. any ideas or help?
clear all; close all; clc
x=[1 2 3]
h=[-1 0 3]
Z=[0]
[M,N]=size(x)
[L,O]=size(h)
a=1
A=N+O-1
suma=[0]
for n=1:1:N
for o=1:1:O
y(n,o)=x(n)*h(o)
end
end
s=fliplr(y);
n=-1*(N-1);
for r=1:A
Yfor(r)=sum(diag(s,n))
n=n+1;
end
Yconv=fliplr(Yfor)
%Yfor=0
%Yfor(1)=y(1,1)
%Yfor(2)=y(2,1)+y(1,2)
%Yfor(3)=y(3,1)+y(2,2)+y(1,3)
%Yfor(4)=y(3,2)+y(2,3)
%Yfor(5)=y(3,3)
Y=conv(x,h)
figure, stem(x)
grid on
figure,stem(Yconv) grid on
  댓글 수: 2
Image Analyst
Image Analyst 2011년 11월 26일
Any reason why you're not using the built-in conv() function?
Walter Roberson
Walter Roberson 2011년 11월 26일
Everything other than the conv() and the graphics should be easy to do in C.
For example, since you do not use s after taking the diag() of it, you can just design your equivalent to diag to index right to left instead of left to right.

댓글을 달려면 로그인하십시오.

답변 (0개)

카테고리

Help CenterFile Exchange에서 Logical에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by