Writing mathematical equations in MATLAB

In summary, if you are getting unexpected results from your MATLAB code for equations 4, 5, and the equation after 5, there could be a few issues to troubleshoot. Check your input values, make sure you are implementing the equations correctly, consider using built-in functions, debug your code, and compare your results to the paper.
  • #1
EngWiPy
1,368
61
Hello,

I have the attached paper, and I want to write equations 4, 5 and the equation in the first line after equation 5 in MATLAB. I did it as following:

Code:
Np=24;
L=19;
TapsL=[1 19 20];
S=length(TapsL);

Index=zeros(S,1);%Tap Locations   
    c=zeros(L+1,1);
    cHatMP=zeros(L+1,1);
    hHatMP=zeros(S,1);%Taps CS Estimates
    
    h=(1/sqrt(2.*(S))).*(randn(S,1)+1i.*randn(S,1));
    c(TapsL)=h;
   
    
    %Channel Estimation
    np=(1/sqrt(2*SNR(ii))).*(randn(Np+L,1)+1i.*randn(Np+L,1));
    n=(1/sqrt(2*SNR(ii))).*(randn(Nd+L,1)+1i.*randn(Nd+L,1));
    
    xpCP=[xp(end-L+1:end);xp];
    
    yp=filter(c,1,xpCP)+np;
    
    yp(1:L)=[]; At this point we have y=Ac+n
    
    cHatLS=inv(transpose(conj(A))*A)*transpose(conj(A))*yp;%Least square channel estimation
    
    
    for ss=1:S
        max=0;
        for pp=1:L+1
            if ss>1
                set=0;
                for mm=1:ss-1
                    if Index(mm)==pp
                        set=1;
                    end
                end
                if set==0
                    Proj=(abs(transpose(conj(A(:,pp)))*yp)^2)/norm(A(:,pp))^2;
                    if Proj>max
                       max=Proj;
                       maxIndex=pp;
                    end 
                end
            else
                Proj=(abs(transpose(conj(A(:,pp)))*yp)^2)/norm(A(:,pp))^2;
                if Proj>max
                   max=Proj;
                   maxIndex=pp;
                end
            end                   
        end
        hHatMP(ss)=transpose(conj(A(:,maxIndex)))*yp/norm(A(:,maxIndex))^2;
        Index(ss)=maxIndex;
        yp=yp-((transpose(conj(A(:,maxIndex)))*yp*A(:,maxIndex))/norm(A(:,maxIndex))^2);
    end 
    
     
    cHatMP(Index)=hHatMP;

but I get unexpected results when using these values. So, I do not know if I am doing it wrongly in MATLAB. Any suggestion, please?

Note: Assume A is given.

Thanks
 

Attachments

  • Sparse channel estimation via matching pursuit with application to equalization.pdf
    235.6 KB · Views: 350
Physics news on Phys.org
  • #2
for your post and for sharing your code. It looks like you are on the right track with your code, but there could be a few issues that are causing unexpected results. Here are some suggestions to help troubleshoot and improve your code:

1. Check your input values: Make sure that all of your input values, such as Np, L, TapsL, SNR, and Nd, are correct and consistent with the values used in the paper. Double check that you are using the correct units and that your arrays are the correct dimensions.

2. Check your equations: Make sure that you are implementing equations 4, 5, and the equation after 5 correctly in your code. Double check the order of operations and make sure you are using the correct operators for complex numbers.

3. Use built-in functions: Instead of writing your own code for the least squares channel estimation and maximum projection algorithm, consider using built-in functions in MATLAB such as "inv" and "norm". This can help ensure that the calculations are done correctly and can save you time and effort in writing and debugging your own code.

4. Debug your code: Use the built-in debugging tools in MATLAB to step through your code and check the values of your variables at each step. This can help you identify where the unexpected results are coming from and make adjustments to your code.

5. Compare your results to the paper: Finally, double check your results against the results presented in the paper. It is possible that there may be small differences due to rounding or other factors, but your results should be close to the results in the paper.

I hope these suggestions help you improve your code and get the expected results. Good luck!
 

1. How do I write a basic mathematical equation in MATLAB?

To write a basic mathematical equation in MATLAB, you can use the basic arithmetic operators such as + (addition), - (subtraction), * (multiplication), and / (division). For example, to write the equation 2 + 3 in MATLAB, you would type "2+3" into the command window and press enter.

2. How do I write more complex equations in MATLAB?

To write more complex equations in MATLAB, you can use parentheses to group terms and specify the order of operations. You can also use built-in functions and constants, such as sin, cos, exp, and pi, to perform more advanced mathematical operations. It is also helpful to break down the equation into smaller steps and use variables to represent different parts of the equation.

3. How do I display the result of a mathematical equation in MATLAB?

To display the result of a mathematical equation in MATLAB, you can use the disp() function. This function allows you to display the result of a variable or expression in the command window. For example, if you want to display the result of the equation 2+3, you would type "disp(2+3)" into the command window and press enter.

4. Can I plot mathematical equations in MATLAB?

Yes, you can plot mathematical equations in MATLAB by using the plot() function. This function allows you to graph a mathematical equation or a set of data points. You can also customize the appearance of the graph by adding labels, titles, and changing the color and style of the plot.

5. How do I solve equations with multiple variables in MATLAB?

To solve equations with multiple variables in MATLAB, you can use the solve() function. This function allows you to solve a system of equations by specifying the variables and their corresponding equations. You can also use the solve() function to find the roots of an equation or to solve for a specific variable in terms of the other variables.

Similar threads

  • MATLAB, Maple, Mathematica, LaTeX
Replies
4
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
126
  • MATLAB, Maple, Mathematica, LaTeX
Replies
8
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
1K
  • Advanced Physics Homework Help
Replies
7
Views
1K
  • Engineering and Comp Sci Homework Help
Replies
1
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
3
Views
6K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
11
Views
6K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
4K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
7
Views
10K
Back
Top