t = [0:0.1:2]
以1Hz
的频率创建一个正弦数据集。Gaussian random
和mean is 0
的{{1}}数据添加到正弦数据中。standard deviation is 0.5
使用data.csv
和for loop
函数。我写了这个,但是我想使用fprintf
。
randn
答案 0 :(得分:1)
您不需要循环。
尝试一下:
t = 0:0.01:4;
f = 1; %Hz
w = 2*pi*f;
s = sin(w*t); % original signal with frequency 1Hz
noise = randn(size(s)); % white noise with mu=0, sigma = 1
noise = noise*0.5; % sigma correction
s_noisy = s + noise;
%plot
figure
plot(t, s);
hold on;
plot(t, s_noisy);
hold off;
grid minor;
% save to file
fileID = fopen('sine.csv','w');
fprintf(fileID, '%6.4f\n', s_noisy);
fclose(fileID);