Signal Addition function (Alternate Method) in MATLAB

You can make a signal addition function in Matlab and can use it as a calling function in any operations, codes and files in Matlab. So, basically this is the 2nd method of how to make a signal addition function in Matlab. I have already explained the first method here Signal addition 1st Method. So, lets start with the alternate method now, to do this simply open and create a new Script (.m file) in Matlab.


  1. Open MATLAB << Then on the top left corner click on the File option << Click New << Then click Script
  2. Now write the following Matlab code given below of signal addition function into the new script (.m file) and save the file in the Matlab directory with any name you want.


MATLAB CODE:

function [y n] = sigadd_another_method(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;



Now, here I’m gonna give you an example of how we can use our sigadd_another_method function which we created in any operations or files in Matlab. For this create a new file and write the following input code given below and run.



INPUT CODE:

n1 = 1:5
x1 = [1 2 3 4 5]
n2 = 1:5
x2 = [2 4 6 8 10]
[y,n] = sigadd_another_method(x1,n1,x2,n2)



OUTPUT:


n1 =


     1     2     3     4     5



x1 =


     1     2     3     4     5



n2 =


     1     2     3     4     5



x2 =


     2     4     6     8    10



y =


     3     6     9    12    15



n =


     1     2     3     4     5




This is how you can make a Signal Addition function in MATLAB. Hope you like this article. This is the 2nd (alternate) method of how to make a signal addition function in Matlab. I have already explained the 1st method in my pervious blog. If you want to learn that click here Signal addition 1st Method. If you want to learn more about MATLAB you can read and view all the blog posts related to MALTAB here. MATLAB Learning

If you need any help and assistance, please comment down below so that we can help you. Good Luck!!