% Script to create a realistic model of an experimental multi-peak signal,
% based on the measured characteristics of an original signal.
clear Peaks
format compact
format short g
% Estimated from the original experimental data:  
x=.11:.101:450; % Independent variable of original data
Baseline=180+(290-180)./290.*x; % Slightly tilted but straight baseline 
noise=21;% Estimated from the noise in original data (white and contant).
%
% Define P as a table of peaks in the original data, from findpeaksG,
% iPeak, ipf, etc.
%         Position      Height       Width         Area
P=[1       119.73       70.161       2.5385       264.27
   2       206.31       306.61       1.3842       451.78
   3       214.78       126.12       1.5837       212.62
   4       252.48       16629        1.1265       19943 
   5       301.5        18945        1.0348       20871 
   6       360.2        504.17       1.0252       550.17 ];
% Create a model for each peak (Gaussian in this case, but could be any
% shape) based on the height, position, and width in the above matrix P.
for peak=1:length(P) % peak=peak number (1 through 6 in this case)
    Height=P(peak,3);
    Position=P(peak,2);
    Width=P(peak,4);
    % Create a Gaussian for each peak and add to a row of matrix "Peaks"
    Peaks(peak,:)=Height.*gaussian(x,Position,Width); 
end            
y=sum(Peaks); % Add up all the separate peak into a multi-peak vector y
y=y+Baseline+noise.*randn(size(x)); % Add noise and baseine
clf
plot(x,y)
xlabel('Independent variable: x') 
ylabel ('Dependent variable, y')
title('Simulated signal, designed to match a real experimental signal')
