Create a subplot with two graphs subplot(2,1,x). The top plot will be your summed sinusoids and the bottom will show all the sinusoids used to create the final sinusoid. To do this, use the for loop to create a matrix that contains three vectors, one for each of the base sinusoids. Then use one command (outside your function) to plot all three together on the bottom subplot.
My code is below but I am unsure how or where to add a for loop to execute this. My thought was to store the "x" value and then plot it.
function [xx,tt] = syn_sin(fk,xk,fs,dur,tstart)if nargin <5, tstart=0, endif length (xk)~= length(fk) error ('error', 'fk~=xk');endt= tstart: 1/(fs):dur;x=xk(1)* exp(2*j*pi*fk(1)*t);for k=2:length(fk); x=xk(k) *exp(2*j*pi*fk(k)*t) +x;endplot(t,x),grid on
Best Answer