clear all
close all
clc

t = linspace(0,1,1000);
f1 = 10;
f2 = 20;

s1 = [sin(2*pi*f1*t(1:500)) zeros(1,500) ];
s2 = [zeros(1,500) 2*sin(2*pi*f2*t(501:1000)) ];
s=s1+s2;

subplot(2,2,1)
plot(t,s)
xlabel('time')
ylabel('amplitude')

nfft = 2^(nextpow2(length(s)));
S = fft(s,nfft);
freqs = [0:1:nfft-1]/nfft*1000;

subplot(2,2,2)
plot(freqs(1:512),abs(S(1:512)));
xlim([0 100])
xlabel('frequency')
ylabel('magnitude')

subplot(2,2,3)
plot(freqs(1:512),angle(S(1:512)));
xlim([0 100])
xlabel('frequency')
ylabel('phase')


s1 = [2*sin(2*pi*f2*t(1:500)) zeros(1,500) ];
s2 = [zeros(1,500) sin(2*pi*f1*t(501:1000)) ];
s=s1+s2;

figure

subplot(2,2,1)
plot(t,s)
xlabel('time')
ylabel('amplitude')

nfft = 2^(nextpow2(length(s)));
S = fft(s,nfft);
freqs = [0:1:nfft-1]/nfft*1000;

subplot(2,2,2)
plot(freqs(1:512),abs(S(1:512)));
xlim([0 100])
xlabel('frequency')
ylabel('magnitude')

subplot(2,2,3)
plot(freqs(1:512),angle(S(1:512)));
xlim([0 100])
xlabel('frequency')
ylabel('phase')