Sie sind auf Seite 1von 5

Search:

File Exchange

Create Account

File Exchange

Answers

Newsgroup

Link Exchange

Blogs

Trendy

Cody

Contest

MathWorks.com

Log In

CONVOLUTION IN MATLAB
WITHOUT USING conv(x,h)

3.3125

3.3 | 16 ratings

Rate this file

by imran shezad
23 Mar 2009

47 Downloads (last 30 days)


File Size: 1.35 KB

enter x=[ ]; % enter in brackets enter h=[ ]

File ID: #23402


Version: 1.0

Watch this File

File Information

Description A GENERALAZED CONVOLUTION COMPUTING CODE IN MATLAB WITHOUT USING MATLAB


BUILTIN FUNCTION conv(x,h)

MATLAB release MATLAB 7.0.4 (R14SP2)


Please login to tag files.

Tags for This File

communications

Save Cancel

Please login to add a comment or rating.


Comments and Ratings (25)
08 Aug 2015

s priyanka

I am not understand this concept can anybody xplain me i am using X


as 3*3 matrix and h as 3*3 matrix...I runned the aghil vinayak program
got output but t is 1*6 matrix but ishould be 3*3

Comment only

18 May 2015

Dhrubajyoti Das

Good

24 Sep 2014

Muhammad Azeem

function y=my_conv(x,h)
x2=h;
lx=length(x);
lh=length(h);
if lx>lh
x2=[x2 zeros(1,lx-lh)];
else
x=[x zeros(1,lh-lx)];
end
y=zeros(1,lx+lh-1);
x=fliplr(x);
for i=1:length(y)
if i<=length(x)
y(i)=sum(x(1,length(x)-i+1:length(x)).*x2(1,1:i));
else
j=i-length(x);
y(i)=sum(x(1,1:length(x)-j).*x2(1,j+1:length(x2)));
end
end
figure
stem(y);

Comment only

15 Mar 2014

Sharifa Yasheen

I excuted Priya's written program but got error saying X must be same
length as Y and even in subplot(2,2,1);stem(x1,x);
Please help me out where am going wrong

Comment only

15 Mar 2014

Zulqadar Hassan

good

23 Feb 2014

Priya

clc
clear all
close all
x=input('Enter the first sequence: ');
l1=input('Enter the lower limit: ');
u1=input('Enter the upper limit: ');
x1=l1:1:u1;
h=input('Enter the second sequence: ');
l2=input('Enter the lower limit: ');
u2=input('Enter the upper limit: ');
h1=l2:1:u2;
l=l1+l2;
u=u1+u2;
n=l:1:u;
s=numel(n);

Comment only

Code covered by the BSD License

Highlights from

CONVOLUTION IN MATLAB
WITHOUT USING conv(x,h)
convolution.m

A GENERALAZED CONVOLUTION
COMPUTING CODE IN MATLAB
WITHOUT USING MATLAB BUILTIN
FUNCTION conv(x,h)
View all files

Comments and Ratings (25)

28 Jan 2014

assad

i=1;
for i=1:s
y(i)=0;
for k=1:numel(x)
if (i+1-k)<=0
y(i)=y(i)+(x(k)*0);
else if (i+1-k)>numel(h)
y(i)=y(i)+(x(k)*0);
else
y(i)=y(i)+(x(k)*h(i+1-k));
k=k+1;
end
end
end
i=i+1;
end
disp(y);
subplot(2,2,1);stem(x1,x);
title('First sequence');xlabel('n');ylabel('x(n)');
subplot(2,2,2);stem(h1,h);
title('Second Sequence');xlabel('n');ylabel('h(n)');
subplot(2,2,[3 4]);stem(n,y);
title('Convoluted sequence');xlabel('n');ylabel('y(n)');
X = input('Enter x: '); %input vector X and H
H = input('Enter h: ') ;
LenX = length(X); %defining their lenghts
LenH = length(H);
y = zeros(1,LenX+LenH); %defing vector y of zeroes and of size
% lenth of X + length of H
t = zeros(1,LenH); % definign a vector t of same length as H
for i = 1:LenH+LenX-1 % Running a for loop from 1 to length of Y -1
if i<=LenX % till I IS Lesser then length of X i.e overlap about to begin
t(1)= X(i); % put x(i) on t(1) later it is shifted forwards in the vector t i.e.
later t(2)=t(1)

Comment only

for j = 1:LenH % in the if condition a for loop from 1 to length of H


y(i) = y(i) + H(j)*t(j); % summing for all H(j)*t(j) and putting it at y(1) or y
(2) or Y(i) in first iteration
% i.e. for i=1 only firt multiplication would
% be non zero rest all zeroes.
end

for k = LenH:-1:2 % shifting old value of t(i) to t(i+1) now there would me
1+ non zeroes values in t
% this cycle would continue until i is lesser then
% length X i.e. overlap increasing every iteration less
% and less non zero vales in t every iteration
t(k) = t(k-1);
end

else % now when all of the T is non zero which means 100% overlap in
else overlap would start to decrease between T and H
% T is basically X
t(1)= 0;
for j = 1:LenH % Now we start filling up Zeroes in T i.e. overlap began to
decrease now and each iteration it would decrease
% i.e T moving to left until there is no more
% over lap
y(i) = y(i) + (H(j)*t(j)); % in this for loop we multiply all respective vales
of h and t and add the
% putting it at y(1) or y(2) or Y(i) in first iteration
end
for k = LenH:-1:2 %% here just like similar loop above t where we were
filling up t with vales of x
%now we are filling up zeroos in t i.e. over lap decreasing
t(k) = t(k-1);
end
end
end

ly=length(y)
indices=[ly]
for i=1:ly
indices(i)=i;
end
disp (y); %displays vector y.

disp (indices); % displays vector indices.


stem(y);
ylabel('Y[n]');
xlabel('[n]');
title('Convolution without conv function');
23 Sep 2013

Aghil Vinayak

x = input('Enter x: ');
h = input('Enter h: ') ;

Comment only

Comments and Ratings (25)

Ni = length(x);
Nh = length(h);
y = zeros(1,Ni+Nh);
t = zeros(1,Nh);
for i = 1:Ni+Nh-1
if i<=Ni
t(1)= x(i);
for j = 1:Nh
y(i) = y(i) + h(j)*t(j);
end
for k = Nh:-1:2
t(k) = t(k-1);
end
else
t(1)= 0;
for j = 1:Nh
y(i) = y(i) + (h(j)*t(j));
end
for k = Nh:-1:2
t(k) = t(k-1);
end
end
end
stem(y);

30 Mar 2013

sonali

17 Feb 2013

Abdul-Rauf Mujahid

function [y] = myconv( x,h )

26 Dec 2012

Aiman Sultan

thanx :)

22 Nov 2012

Nirjhar Roy

nice

15 Nov 2012

Mohammad reza
nilchiyan

good Job man, how can we put this code in the box with the rectangular
shape input in simulink?

Comment only

28 May 2012

muskan kanwal
tehseen sattar

can you make it using function so that we should give two input
argument to the function and we return the output ...

Comment only

12 Apr 2012

chiangmai4121

Thank-you Duane, exactly what I was looking for. Jos(10584) this


program is very useful to me, so your comment is wrong. Thanks again
Duane, keep ignoring haters like Jos

20 Jan 2012

Mohit Gaur
Tim

Why are there two inputs, x and h?

23 Sep 2011

hamsa dhia

good gob well done

30 Jun 2011

jyotibasu yaranal

fine..

14 Jul 2010

ROHIT ALHAT

good job man.....

27 Mar 2009

imran shezad
Jos (10584)

A typical example of a file that has no use for others, written in poor
C-style code. Do not bother to download!

23 Mar 2009

Duane Hanselman

The content of the M-file is:


% A GENERALAZED CONVOLUTION COMPUTING CODE IN
MATLAB WITHOUT USING MATLAB BUILTIN FUNCTION conv(x,h)
close all
clear all
x=input('Enter x: ')
h=input('Enter h: ')
m=length(x);
n=length(h);
X=[x,zeros(1,n)];
H=[h,zeros(1,m)];
for i=1:n+m-1
Y(i)=0;
for j=1:m

21 Feb 2013

24 Apr 2012

12 Oct 2011

24 Mar 2009

Rama Krishna Tata

m=length(x);
n=length(h);
x=[x,zeros(1,n)];
h=[h,zeros(1,m)];
for i=1:n+m-1
y(i)=0;
for j=1:m
if(i-j+1>0)
y(i)=y(i)+x(j)*h(i-j+1);
end
end
end

Comment only

Comments and Ratings (25)

if(i-j+1>0)
Y(i)=Y(i)+X(j)*H(i-j+1);
else
end
end
end
Y
stem(Y);
ylabel('Y[n]');
xlabel('----->n');
title('Convolution of Two Signals without conv function');

Contact us

Patents

1994-2016 The MathWorks, Inc.


Featured MathWorks.com Topics:

New Products

Trademarks
Support

Privacy Policy
Documentation

Preventing Piracy
Training

Terms of Use

Webinars

Newsletters

MATLAB Trials

Careers

Das könnte Ihnen auch gefallen