www.gusucode.com > signal 案例源码程序 matlab代码 > signal/NoisePowerExample.m
%% Noise Power % Create a sinusoidal signal sampled at 48 kHz. The signal has a % fundamental of frequency 1 kHz and unit amplitude. It additionally % contains a 2 kHz harmonic with half the amplitude and additive noise with % variance 0.1². %% fs = 48e3; t = 0:1/fs:1-1/fs; A = 1.0; powfund = A^2/2; a = 0.4; powharm = a^2/2; s = 0.1; varnoise = s^2; x = A*cos(2*pi*1000*t) + ... a*sin(2*pi*2000*t) + s*randn(size(t)); %% % Compute the noise power in the signal. Verify that it agrees with the % definition. [SNR,npow] = snr(x,fs); compare = [10*log10(powfund)-npow SNR]