MATLAB: Multiple sine wave adding and ploting

Hi every body .. i need help.. i was going to answer the following code of my matlab beginner lessons, so i confused as i'm new to the coding .. Actually i would appreciate if some one could help me.. this the question..
Write a function called mix_sines that takes two positive scalar input arguments f1 and f2 (you do not have to check the input arguments) that represent the frequency of two sines waves. The function needs to generate these sines waves, add them together and plot the result. If the function is called like this: mix_sines(1,0) then it displays three full periods of a regular sine wave with amplitude 1. If it is called like this: mix_sines(20,21), then it plots Figure 2.21 below (note that if you add a phase shift of pi to one of the sines, then the result will start at 0 as shown below). Notice that the amplitude is 2. Also, notice that signal has three times 21 periods, but the envelope signal has three times 1 periods. That is because the difference of the two frequencies (21 and 20) is 1. ? Figure 2.20 Problem 8 Figure.. i posted the fig8 below here.

Best Answer

Hints: formulas for sine wave
y = sin(2*pi*f*(x-phaseShift));
y = amplitude * sin(2*pi*(x-phaseShift)/period);
and period = 1/f. Compute x using linspace():
x = linspace(0, 3*period, 500); % 500 points between 0 and 3*period
and of course use plot(), and to get even fancier, use title, xlabel, ylabel and grid.
xlabel('X', 'FontSize', 20);
ylabel('Y', 'FontSize', 20);
title('My Awesome Homework Solution', 'FontSize', 20);
grid on;