|
那位大大帮忙解释一下以下Code的意义。
2 d- R- C7 W" M# q6 g: W4 ]. C2 H: _" i/ Q, [
clear all;
+ N% z6 b& o$ k' g, a5 I h* {5 j' e- s x' k
N=2^12; % The input sequence is made by 2^12 points; R* z K: Q$ o l( @
Nbit=8; % 8-bit DAC
) G0 y# i, [+ S; `1 zNtransient=11; %2 K) [" Q6 @2 C" G D/ d
Ntot=N+Ntransient;
' Z: Y: E5 n& Hnper=311; % prime integer number of sine waveforms
{- Y) R4 A F' w; \' lFs=1;
! G0 W: P# P7 |bw=0.5;( y8 g6 W* L6 p8 U6 ~9 d
Fin=nper*Fs/N; % Input signal frequency (Fin=nper*Fs/N)5 C4 K& n9 {; H$ n
Vref=0.5; % Full scale for an input sinewave8 P+ Y' r# C* u l
Amp_dB=-0; % Amplitude in dB! |* v9 b% |; \1 G
Ampl=10^(Amp_dB/20)*Vref; % Input signal amplitude$ V( ]! ] O7 V* l1 S" _* h6 A7 C
4 e% r% t! y7 b8 V% I# ]8 S( Zfinrad=Fin*2*pi;
" K4 r2 `9 u# A1 }9 {& f2 n6 valphadx=0.0001; % gradient in the resistivity
; I6 U5 V! B4 j" V; _8 oden=2^Nbit-1+alphadx*2^Nbit*(2^Nbit-1)/2;
& q8 c) u8 B0 y: F9 S
7 U* r- V( w" {4 A0 |% ?for i=1:Ntot,
, V9 i8 l: o$ D! E x=Vref*sin(finrad*(i-1))+Vref; % Unipolar range
4 Q5 O% i$ U3 o5 y9 L0 Q$ u k=round(x*2^Nbit);% Z i' D, z2 t2 T+ z6 v" c* c
vout=(k+alphadx*k*(k+1)/2)/den;
! \9 E, W/ n/ r+ F' e% F y(i)=vout;/ s) c. F/ E* ?( R
end, W6 v* W J3 g
7 D, T: L( ]" Ny=y-mean(y) % Output with zero average
- b- v7 r3 @" m' D+ n4 H5 `4 a# {' s! n& P( b
%--------------------------------Graphics---------------------------------%3 `; N* ]- k i( J
2 l4 h* ^4 ]) L0 _5 T
figure(1);
0 Q6 o( Y( i$ x/ a% B5 D( p( Gclf;
+ g1 c9 u% e$ q1 s# D6 F8 |' uplot(y,'r');: ?- r; c; B- C, @# `
grid;
1 Y. W0 s6 X! s- Uxlim([1600 1900]);+ o( A8 J5 b4 {' T# p3 g
title('Sinewave with distortion');
" N1 C( l& ]# W: V% u' Z. V4 j: v( C
w=ones(1,N);
* `1 Q, [1 ~( U+ l& H5 h( P [6 Of=Fin/Fs; % Normalized signal frequency7 D+ L% i; ] S) T
fB=N*(bw/Fs); % Base-band frequency bins
- y0 P) R( w4 d[snr,ptot]=calcSNR(y(1:N),f,fB,w,N);
! Z' n7 W* l( M) K8 eptot=ptot-max(ptot); % Normalize total spectrum
. L; A3 g$ e8 W0 V8 y: N! t$ Z3 M" Z' A4 M/ @
figure(2);( Y1 A6 k. {# X1 d2 b, U
clf;0 s$ P1 h: C, m8 a4 y) j& O
plot(linspace(0,Fs/2,N/2), ptot(1:N/2), 'r');$ N, D: O Z) ^* [, u
grid on;5 i9 W o+ A3 s E& Z/ `. L
title('PSD of the Output'): x5 ^( ^$ B; f r I
xlabel('Frequency [Hz]'): P- u$ W# @# U% y
ylabel('PSD [dB]')
/ d& v( D! J, L8 M a4 b* m3 Z' o3 ^5 m9 Gaxis([0 Fs/4 -120 0]);/ a6 G N, O' \" T
text(Fs/10,-20,sprintf('\\bfSNR = %3.1fdB @ \\alpha\\DeltaX = %1.0e\n'...
% `- x. \( ?7 f: {) h2 C1 r" R& I ,snr,alphadx),'Fontsize',12);
. w, K& t. \! f( ?* Dtext(f*2,ptot((f*N+1)*2-1)+3,sprintf('\\bf%2.1fdB',ptot((f*N+1)*2-1)),...
# X" M( {: J! b9 U5 n! p+ } 'Fontsize',8,'HorizontalAlignment','center'); |
|