exmp2_11.m
来自「用dsp解压mp3程序的算法」· M 代码 · 共 22 行
M
22 行
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% exmp2_11.m - Waveform and spectrum of sinewave corrupted by
% white noise with Signal-to-noise ratio = 10 dB
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
N=256; A=sqrt(20); w0=0.2*pi; % define parameters
n = [0:N-1]; % time index
sn = A*sin(w0*n); % sine sequence
vn = (rand(1,N)-0.5)*sqrt(12); % zero-mean, unit-variance white noise
xn = sn+vn; % sinewave embedded in white noise
subplot(2,1,1); % top figure
plot(n,xn) % plot the waveform
title('Waveform of noisy sinewave');
xlabel('Time index n'); ylabel('Amplitude');
axis([0 255 -inf inf])
Xk = fft(xn); % compute DFT
absXk = 20*log10(abs(Xk)); % magnitude spectrum in dB
subplot(2,1,2); % bottom figure
plot(n,absXk) % plot the spectrum
title('Spectrum of noisy sinewave');
xlabel('Frequency index k'); ylabel('Magnitude in dB');
axis([0 127 -inf inf])
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?