Fs = 1000; % frequency of sampling
T = 1/Fs; % sample time
L = 1000; % length of sampling
t = (-L/2:L/2)*T;
noise_amplitude = 0.5;
envelope_factor = 100;

% mix up the signal
frequencies = [1, 120; 0.7, 100; 0.9, 60; 0.2, 250; 0.5, 450; 0.6, 453]; 
data = frequencies(:,1)'*sin(2*pi*frequencies(:,2)*t);

% Add a gaussian envelope
data = data.*exp(-envelope_factor*t.^2);

% repeat the signal
% data = data + circshift(data, [1;550]);

% add noise
data = data + noise_amplitude*rand(1,length(data));



subplot(2,1,1);
plot(Fs*t,data);
xlabel('t/ms');
ylabel('intensity');

NFFT = 2^nextpow2(L);
Y = fft(data, NFFT)/L;
f = Fs/2*linspace(0,1,NFFT/2+1);

subplot(2,1,2);
plot(f,2*abs(Y(1:NFFT/2+1)),'b');
xlabel('frequency/Hz');
ylabel('|F(\omega)|');

% subplot(3,1,3);
% recovered = L*ifft(Y);
% plot(Fs*t,recovered(1:L),'b', Fs*t,data-recovered(1:L), 'r');
% xlabel('t/ms');
% ylabel('intensity');