Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

matlab problem in two signal addition of any dimension

Status
Not open for further replies.

sayurabh

Member level 4
Joined
Apr 11, 2007
Messages
69
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,286
Activity points
1,783
function [y,n]=sigadd(x1,n1,x2,n2)

n=min(min(n1),min(n2)):max(max(n1),max(n2));
if(min(n1)>min(n))
while(min(n1)>min(n))
x1=[zeros(1,1),x1];
min(n1)=min(n1)-1;
end;
end;
if(min(n2)>min(n))
while(min(n2)>min(n))
x2=[zeros(1,1),x2];
min(n2)=min(n2)-1;
end;
end;
if(max(n2)<max(n))
while(max(n2)<max(n))
x2=[x2,zeros(1,1)];
max(n2)=max(n2)+1;
end;
end;
if(max(n1)<max(n))
while(max(n1)<max(n))
x1=[x1,zeros(1,1)];
max(n1)=max(n1)+1;
end;
end;
y=x1+x2;
i had made the code for working of this code for any dimensions of two array i tried to make both araays avoiding the negastive indexing problem some where is prob matlab is not accepting predefine min function plz check it out code iz easy if u want to understand reply it i will tell u the whole story it i know the code ihad myself it is better then proakis code for addition of wo sgnal moe powerful but some logical error iz coming x1 and x2 are two signal eneterred and the n1 and n2 are th respected lengths of ther signal i mean indexex u understand
 

I can't read your question. Please add punctuation!

min(n1)=min(n1)-1;
That statement doesn't make sense. "min" is a function. You can't store a value into a function.

"zeros(1,1)" seems like a complicated way of writing "0".

What is your code suppose to do? Can you provide example input values, and the expected output values?
 

    sayurabh

    Points: 2
    Helpful Answer Positive Rating
thanks buddy u was saying right i modified the code according to u gotcha it is working i hae added zeros in te en becoz i tell u the whole story first i have done max range for the resultant array that would be n i think that u have understand it
ok then i have compar the min value of both indexes of array that is the first element of both array if any array have minmum value greater than the min(n) than zeros are added at the starting to corresponding array till min(n)=min(n1orn2) i made case for both so it code can work for any input than i comapre max(n) with max value of n1 and n2 add zeros at the end of the arrays till max(n)=max(n1orn2) in this way i made the two arrays of equal dimensions and added thasm code is working i m showing the modified code and its ouput
function [y,n]=sigadd(x1,n1,x2,n2)

n=min(min(n1),min(n2)):max(max(n1),max(n2));
if(n1(1)>n1)
while(n1(1)>n(1))
x1=[zeros(1,1),x1];
n1(1)=n1(1)-1;
end;
end;
if(n2(1)>n(1))
while(n2(1)>n(1))
x2=[zeros(1,1),x2];
n2(1)=n2(1)-1;
end;
end; a=max(n2);
if(max(n2)<max(n))
while(a<max(n))
x2=[x2,zeros(1,1)];
a=a+1;
end;
end;
b=max(n1);
if(b<max(n))
while(b<max(n))
x1=[x1,zeros(1,1)];
b=b+1;
end;end;
y=x1+x2;
>> x1=[1 2 3 4 5];
>> n1=-1:3;
>> x2=[1 2 3];
>> n2=0:2;
>> sigaddom(x1,n1,x2,n2)

ans =

1 3 5 7 5

that is the ans it is correct it also works for negative indexing u can check for any input thanks alot for help

Added after 1 minutes:

if u donot understand i will try to demonstrate u more good way
 

what the &# means tell me it is bit confusing tell me in detail i can understand own made code it is tuff to understand to others code for the same workm but ur code is short and precise smaller than my code plz tell meaning of &#
 

Your first sentence is a jumble! Please add a period "." to the end of each sentence.

I think your code aligns arrays x1 and x2 (using index arrays n1 and n2), and then adds them.

Loops execute slowly in MATLAB. You should use MATLAB's array arithmetic. For example:
Code:
x1 = [1 2 3 4 5];
n1 = -1:3;
x2 = [1 2 3];
n2 = 0:2;
%
n  = min([n1 n2]) : max([n1 n2]);
L1 = length(n1);
L2 = length(n2);
Ln = length(n);
y  = [zeros(1,n1(1)-n(1)) x1 zeros(1,n(Ln)-n1(L1))] ...
   + [zeros(1,n2(1)-n(1)) x2 zeros(1,n(Ln)-n2(L2))];
%
display(y);
display(n);
y =
1 3 5 7 5
n =
-1 0 1 2 3

UPDATE:

I don't see &# anywhere, unless I examine EDAboard's HTML source code.
Maybe you are using a broken web browser or language translator that doesn't support HTML character codes.

Here is a ZIP file containing my example code:
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top