N=512; Nf=2*N;
fs=1; dt=1/fs; t=0:dt:(N-1)*dt; f=0:fs/Nf:(Nf-1)/Nf*fs; t=t(:); f=f(:);
SNR=40;   % SNR in dB

num=[0 0 1];
den=[200 10 1];

%   1/(200 s^2 + 10 s + 1)

sys2nd_cont=tf(num,den);
h=impulse(sys2nd_cont,t); h=h/sum(h);
H=fft(h,Nf);

% generate the input ramp signal

r_start=10; r_peak=210; r_stop=240;
x=zeros(N,1);
x(r_start:r_peak)=(0:1/(r_peak-r_start):1);
x(r_peak:r_stop)=(1:-1/(r_stop-r_peak):0);
X=fft(x,Nf);

% generate the noiseless output signal:
Y=X.*H; y=real(ifft(Y)); y=y(1:N);

% generate the output nois and the noisy output
n=randn(size(y)); n=n./std(n); n=n*sqrt(mean(y.*y)*10^(-SNR/10));
yn=y+n; Yn=fft(yn,Nf);

figure(1), plot(t,x,t,yn), legend('input','noisy output'), xlabel('sec'), title('signals of the system')
figure(2), loglog(f(2:end),abs(H(2:end))), grid, title('Abs. value of the transfer fundtion')
