Discrete convolution.
1 回表示 (過去 30 日間)
古いコメントを表示
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 件のコメント
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 Center および File Exchange で Matrix Indexing についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!