Borrar filtros
Borrar filtros

Discrete convolution.

2 visualizaciones (últimos 30 días)
omar chavez
omar chavez el 26 de Nov. de 2011
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 comentarios
Image Analyst
Image Analyst el 26 de Nov. de 2011
Any reason why you're not using the built-in conv() function?
Walter Roberson
Walter Roberson el 26 de Nov. de 2011
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.

Iniciar sesión para comentar.

Respuestas (0)

Categorías

Más información sobre Logical 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