Add the following lines of code at the bottom of your code (after y=x+randn(size(x)).*sigma;):
ffty = fft(y);
ffty = abs(ffty(1:ceil(length(y)/2)));
ffty(ffty<100)=0;
[~,locs] = findpeaks(ffty);
freqs = (locs-1)/t(end)
signal_1 = sin(2*pi*t*freqs(1))+sin(2*pi*t*freqs(2))+sin(2*pi*t*freqs(3));
signal_2 = sin(2*pi*t*freqs(6))+sin(2*pi*t*freqs(7));
subplot(211), plot(t,signal_1)
subplot(212), plot(t,signal_2)
Best Answer