Calculation of superposition noise and signal-to-noise ratio on MATLAB signals
Posted 11 months ago (2014-01-24 18:38) Read (26) | Comments (0)
0 People bookmark this article,
I want to collect
likes
0
Open source China team collaboration platform officially opened--http://team.oschina.net
Snr in signal processing often need to add noise to the signal, in the superposition of noise often need to meet a certain Snr, this produces two problems, one noise is the specified signal-to-noise ratio overlay, and the other how to test the noise ratio of the noisy signal to meet the specified Snr. In MATLAB, you can use RANDN to produce a normal distribution white noise with a mean of 0 variance of 1, but at any length x=randn (1,n), X is not necessarily the mean 0 variance of 1 (some small deviations), which will have an impact on subsequent computations. Here are 3 functions for adding noise to signals at a certain signal-to-noise ratio, as well as verifying the signal-to-noise ratio of noisy signals. 1, the white noise superimposed on the signal up:?
123456789 |
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; |
where x is a pure signal, SNR is the required signal-to-noise ratio, y is a noisy signal, and noise is the noise superimposed on the signal. 2, add the specified noise to the signal there are standard noise library NOISEX-92, including white noise, office noise, factory noise, car noise, tank noise, etc., in the signal processing often need to stack the noise in the library into the signal, and the noise sampling frequency and pure signal sampling frequency is often inconsistent, Calibration is required for sampling frequency. ?
123456789101112131415 |
function [Y,NOISE] = add_noisem(X,filepath_name,SNR,fs)
% add_noisem add determinated noise to a signal.
% X is signal,
and its sample frequency is fs;
% filepath_name is NOISE‘s path
and name,
and the SNR is signal to noise ratio in dB.
[wavin,fs1,nbits]=wavread(filepath_name);
if fs1~=fs
wavin1=resample(wavin,fs,fs1);
end
nx=size(X,1);
NOISE=wavin1(1:nx);
NOISE=NOISE-mean(NOISE);
signal_power = 1/nx*sum(X.*X);
noise_variance = signal_power / ( 10^(SNR/10) );
NOISE=sqrt(noise_variance)/std(NOISE)*NOISE;
Y=X+NOISE;
|
where x is a pure signal, Filepath_name is the path and file name of the specified noise file (. wav), SNR is the required signal-to-noise ratio, FS is the sampling frequency of the X, Y is the noisy signal, and the noise is the noise superimposed on the signal. 3, the SNR signal-to-noise ratio is defined as signal energy (pure signal) ^2 snr=-----------------=--------------------------Noise energy (with noise signal-pure signal) ^2 /c0>?
12345678 |
function snr=SNR_singlech(I,In) % 计算信噪比函数 % I :\original signal % In :noisy signal(ie. original signal + noise signal) snr=0; Ps=sum(sum((I-mean(mean(I))).^2));%signal power Pn=sum(sum((I-In).^2)); %noise power snr=10*log10(Ps/Pn); |
where I is a pure signal, in is a noisy signal, SNR is the signal-to-noise ratio below gives an example of the function of the call can be used as a reference: example one?
123456789 |
clear all; clc; close all; [filename,pathname]=uigetfile( ‘*.wav‘ , ‘请选择语音文件:‘ ); [X,fs]=wavread([pathname filename]); [Y,NOISE] = noisegen(X,10); subplot 311; plot(X); subplot 312; plot(NOISE); subplot 313; plot(Y); mn=mean(NOISE) snr=SNR_singlech(X,Y) |
Example Two?
1234567891011 |
clear all; CLC, close all; [filename,pathname]=uigetfile ( ' *.wav ' [filename1,pathname1]=uigetfile ( ' *.wav ' filepath_name=[pathname1 filename1]; [x,fs]=wavread ([pathname filename]); [y,noise] = Add_noisem (X,FILEPATH_NAME,10,FS); subplot 311; plot (X); subplot 312; plot (NOISE); subplot 313; plot (Y); mn=mean (NOISE) snr=snr_singlech (x, y) |
reference: [1]. Http://www.ilovematlab.cn/thread-54155-1-1.html
Calculation of superposition noise and Snr of "reprint" MATLAB signal