function [y]=noisySinewave(dur,freq,simufreq,amplitude,noiseamplitude)
%
%Generates a sine wave with added noise
% dur: the duration of the signal to be generated
% freq: the frequency of the sine
% amplitude: the amplitude of the sine
% simufreq: the sampling frequency of the generated time series
% noiseamplitude: maybe a bad name. It's actually the relative power of the
% noise realtive to the sine over the entire spectrum.

x=freq*2*pi/simufreq*(1:ceil(dur*simufreq));
y=awgn(sin(x),10*log10(amplitude^2/noiseamplitude^2));
y = sin(x)*amplitude;
y = y + randn(1,length(x))*noiseamplitude;
plot(x/2/pi/freq,y,'-*b');