使用awgn加入噪声

X = sqrt(2)*sqrt(3)*sin(0:pi/1000000:6*pi);               %产生正弦信号功率位3
Y = awgn(X,10,'measured');                          %加入信噪比为10db的噪声,加入前预估信号的功率(强度)
sigPower = sum(abs(X).^2)/length(X)           %求出信号功率
noisePower=sum(abs(Y-X).^2)/length(Y-X)  %求出`噪声功率
SNR=10*log10(sigPower/noisePower)          %由信噪比定义求出信噪比,单位为db这里写自定义目录标题)
L=128;
f1=100;
fs=400;
t=0:1/fs:(1/fs)*(L-1);
si=sin(2*pi*f1*t);
f=fft(si,L);
f=20*log(abs(f))/log(10);
ft=[0:(fs/L):fs/2];
f=f(1:length(ft));
subplot(3,2,1);plot(t,si);
xlabel('时间(s)');
ylabel('幅度(v)');title('时域信号波形');%%%%%%
subplot(3,2,2);plot(ft,f);
xlabel('频率(hz)');
ylabel('功率(dbw)');title('信号频谱图');
clf;
%fm=100;f0=2.4e10;B=2.4e8;FR=320R;FD=160v;
Fs = 130000;            % Sampling frequency                    
Ts = 1/Fs;             % Sampling period       
N = 512;             % Length of signal
n=0:N-1;
%t1 = (0:1:N-1)*Ts;        % Time vector
t1=n/Fs;
%y = wgn(m, n, p);
% Form a signal containing a 50 Hz sinusoid of amplitude 0.7 and a 120 Hz sinusoid of amplitude 1.
S = sqrt(2)*sqrt(15)*sin(2*pi*50000*t1) + sqrt(2)*sqrt(13)*sin(2*pi*14400*t1);
% Corrupt the signal with zero-mean white noise with a variance of 4.
NOISE=wgn(1, 512, 7);
X = S+NOISE;
sigPower = sum(abs(S).^2)/length(S);           %求出信号功率
noisePower=sum(abs(X-S).^2)/length(X-S); %求出噪声功率
SNR=10*log10(sigPower/noisePower) ;
% Plot the noisy signal in the time domain. It is difficult to identify the frequency components by looking at the signal X(t).
 %对信号进行快速Fourier变换
Y = fft(X); %求得Fourier变换后的振幅
mag1=abs(2*Y/N);
P1 = mag1(1:N/2);
%P1=20*log10(abs(P1));
%P1(2:end-1) = 2*P1(2:end-1);
f1=(1:N/2)*Fs/N;    %频率序列
figure(1);
plot(1000*t1,X);title('Signal Corrupted with Zero-Mean Random Noise');xlabel('t (milliseconds)');ylabel('X(t)');
figure(2);
plot(f1,P1,'r');  xlabel('频率/Hz');ylabel('dbv');title(': FFT','color','r');
  • 1
    点赞
  • 9
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值