【轉帖】Matlab訊號上疊加雜訊和信噪比的計算

來源:互聯網
上載者:User

標籤:style   blog   http   ar   io   color   os   sp   for   

Matlab訊號上疊加雜訊和信噪比的計算

        發表於11個月前(2014-01-24 18:38)      閱讀(26) | 評論(0)            
0人收藏此文章,
我要收藏
    0

開源中國 Team 團隊協作平台正式開放 —— http://team.oschina.net

            

信噪比                    在訊號處理中經常需要把雜訊疊加到訊號上去,在疊加雜訊時往往需要滿足一定的信噪比,這樣產生二個問題,其一雜訊是否按指定的信噪比疊加,其二怎麼樣檢驗帶噪訊號中信噪比滿足指定的信噪比。 在MATLAB中可以用randn產生均值為0方差為1的常態分佈白色雜訊,但在任意長度下x=randn(1,N),x不一定是均值為0方差為1(有些小小的偏差),這樣對後續的計算會產生影響。在這裡提供3個函數用於按一定的信噪比把雜訊疊加到訊號上去,同時可檢驗帶噪訊號中信噪比。 1,把白色雜訊疊加到訊號上去: ?
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;
其中X是純訊號,SNR是要求的信噪比,Y是帶噪訊號,NOISE是疊加在訊號上的雜訊。 2,把指定的雜訊疊加到訊號上去 有標準雜訊庫NOISEX-92,其中帶有白色雜訊、辦公室雜訊、工廠雜訊、汽車雜訊、坦克雜訊等等,在訊號處理中往往需要把庫中的雜訊疊加到訊號中去,而雜訊的採樣頻率與純訊號的採樣頻率往往不一致,需要採樣頻率的校準。 ?
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~=fswavin1=resample(wavin,fs,fs1);endnx=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;
其中X是純訊號,filepath_name是指定雜訊檔案(.wav)的路徑和檔案名稱,SNR是要求的信噪比,fs是訊號X的採樣頻率,Y是帶噪訊號,NOISE是疊加在訊號上的雜訊。 3,檢驗帶噪訊號的信噪比 信噪比的定義為 訊號能量              (純訊號)^2 SNR=-----------------=-------------------------- 雜訊能量        (帶噪訊號-純訊號)^2 ?
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 powerPn=sum(sum((I-In).^2)); %noise powersnr=10*log10(Ps/Pn);
其中I是純訊號,In是帶噪訊號,snr是信噪比 以下給出調用上函數的例子可作參考: 例一 ?
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)
例二 ?
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)
參考: [1] .  http://www.ilovematlab.cn/thread-54155-1-1.html

【轉帖】Matlab訊號上疊加雜訊和信噪比的計算

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.