Signal addition , signal multiplication are two major operation which we need in the manipulation of signals in DSAP
During addition and signal multiplication ,we first need to arranged the both the signals in proper order
with respect to the range of the signal.
SIGNAL ADDITION:
It is implemented in Matlab by the arithematic operation ".+".HOwever the length of the two
signals must be same. i.e x1(n) and x2(n) should have same length. Moreover
a slight modification in the code should be done if the length of two signals are not the same
function [y,n] = sigadd(x1,n1,x2,n2)
% implements y(n) = x1(n)+x2(n)
% -----------------------------
% [y,n] = sigadd(x1,n1,x2,n2)
% y = sum sequence over n, which includes n1 and n2
% x1 = first sequence over n1
% x2 = second sequence over n2 (n2 can be different from n1)
%
n = min(min(n1),min(n2)):max(max(n1),max(n2)); % duration of y(n)
y1 = zeros(1,length(n)); y2 = y1; % initialization
y1(find((n>=min(n1))&(n<=max(n1))==1))=x1; % x1 with duration of y
y2(find((n>=min(n2))&(n<=max(n2))==1))=x2; % x2 with duration of y
y = y1+y2; % sequence addition
SIGNAL MULTIPLICATION
It is implemented in Matlab by the arithematic operation ".*".
function[y,n]=sigmulti(x1,n1,x2,n2);
n=min(min(n1),min(n2)):
max(max(n1),max(n2));
y1=zeros(1,length(n));
y2=y1;
y1(find((n>=min(n1))&(n<=max(n1))==1))=x1;
y2(find((n>=min(n2))&(n<=max(n2))==1))=x2;
y=y1.*y2;
Finally in the matlab command window give the input of two signals and their length and call the respective function to get the output.
logical operation of intersection “&”, relational operations like “<=” and “==”, and the find function are required to make x1(n) and x2(n) of equal length.So the above function is a genaralize function which results a appropriate answer for both equal aswell as non equall length signals.
Really nice post. Your post is expressing what I actually wanted to know, thanks for sharing…
ReplyDeleteoffice shifting in gurgaon .