Azzera filtri
Azzera filtri

Discrete convolution.

2 visualizzazioni (ultimi 30 giorni)
omar chavez
omar chavez il 26 Nov 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 Commenti
Image Analyst
Image Analyst il 26 Nov 2011
Any reason why you're not using the built-in conv() function?
Walter Roberson
Walter Roberson il 26 Nov 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.

Accedi per commentare.

Risposte (0)

Community Treasure Hunt

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

Start Hunting!

Translated by