matlab如何添加自定义信噪比的噪声信号?
clear all;
close all;
x=0:0.2:10;
data1=sin(x);
plot(x,data1);
hold on;
data2=awgn(data1,10*log10(0.05));
plot(x,data2,'r-');
hold off;
扩展资料
matlab添加白噪声叠加到信号:
function [Y,NOISE] = noisegen(X,SNR)
% noisegen add white Gaussian noise to a signal.
% [Y, NOISE] = NOISEGEN(X,SNR) adds white Gaussian NOISE to X. The SNR is in dB.
NOISE=randn(size(X));
NOISE=NOISE-mean(NOISE);
signal_power = 1/length(X)*sum(X.*X);
noise_variance = signal_power / ( 10^(SNR/10) );
NOISE=sqrt(noise_variance)/std(NOISE)*NOISE;
Y=X+NOISE;
其中X是纯信号,SNR是要求的信噪比,Y是带噪信号,NOISE是叠加在信号上的噪声。
2024-02-18 广告