|
那位大大帮忙解释一下以下Code的意义。
. o0 u$ r- ?( L8 R' Z- q: f9 k: y* w* z
clear all;, ^& y, v* `5 C4 J& N; M
9 F% Z# R5 f! i9 Y& Q
N=2^12; % The input sequence is made by 2^12 points
) d9 s+ C8 Q8 ^0 O% {/ G! cNbit=8; % 8-bit DAC. h2 ]* C$ f( d: d; u
Ntransient=11; %0 u1 U8 G6 f3 c
Ntot=N+Ntransient;1 n( K; O8 D. V# O7 U: |
nper=311; % prime integer number of sine waveforms- y6 O0 s- w% D: b
Fs=1;8 ~& Y$ j4 y2 i0 w7 s+ F1 }
bw=0.5;7 }4 I& H. `* Q, J' y
Fin=nper*Fs/N; % Input signal frequency (Fin=nper*Fs/N)
3 o& T2 w6 M% M* S, m, xVref=0.5; % Full scale for an input sinewave+ A: ~/ [8 y; q; L$ R6 }
Amp_dB=-0; % Amplitude in dB
$ g1 s: S9 Z( [% J, q. UAmpl=10^(Amp_dB/20)*Vref; % Input signal amplitude
7 r8 ~( \3 H& s& O
; O7 j( d! X2 j2 I+ S0 Zfinrad=Fin*2*pi;. |1 P' s# x% m8 r
alphadx=0.0001; % gradient in the resistivity
+ \" o1 G/ g! A w$ ?den=2^Nbit-1+alphadx*2^Nbit*(2^Nbit-1)/2;5 A# ^. c1 H* F h m, e7 W
U: y+ ]* P9 g; kfor i=1:Ntot,
: U: n! N. C" F. f8 l; d x=Vref*sin(finrad*(i-1))+Vref; % Unipolar range/ i; u' @& @& z6 H9 w7 g
k=round(x*2^Nbit);+ X4 k0 a. i% ]3 r9 v7 i2 Z
vout=(k+alphadx*k*(k+1)/2)/den;8 F, {' a' t% X' V* G
y(i)=vout;
" w/ a# |6 R# q9 q% E0 lend. X1 b' X" u6 X l) v8 U
+ I; \3 f& s* P* k' A3 L
y=y-mean(y) % Output with zero average
. A; x8 z8 G/ }0 {- R; ]2 L, @; `' O, v* `/ `9 v
%--------------------------------Graphics---------------------------------%" p3 d% Z/ u5 l3 k/ L
9 }: {0 {: x E5 cfigure(1);4 i W7 C9 s0 Y, y! z0 f) G, S
clf;
2 y9 `$ F1 ?! f4 Q" e% s9 _+ }plot(y,'r');) `+ T& L3 h. l3 R6 X
grid;
4 d& Y6 Z1 g1 E$ G( Z( {xlim([1600 1900]);
. }) c1 n9 V$ _7 e$ Gtitle('Sinewave with distortion');7 O5 R/ ^4 ~2 o+ |+ J( U
# n7 U# [ v# K$ U5 Zw=ones(1,N);
" a7 Z* X! J2 S) w. t+ a6 R kf=Fin/Fs; % Normalized signal frequency
1 S7 Y4 k1 A, x: g* H2 NfB=N*(bw/Fs); % Base-band frequency bins: I; g$ N0 X1 T4 S& S
[snr,ptot]=calcSNR(y(1:N),f,fB,w,N);
3 ]: F1 z0 F& {ptot=ptot-max(ptot); % Normalize total spectrum' w; J0 g3 H2 S
' F3 g9 i/ a/ F, t/ H4 T
figure(2);
% R0 z4 B( D: X! T- }clf;
$ t# D! j- E: rplot(linspace(0,Fs/2,N/2), ptot(1:N/2), 'r');
8 Z6 F: {1 k( fgrid on;1 d- c9 q8 [- j1 U; e* [0 o1 _
title('PSD of the Output')
5 C+ Z( R" s$ I; \! ]' L! Nxlabel('Frequency [Hz]')
# U7 G8 M0 ^2 I/ q1 k8 W4 M8 ?ylabel('PSD [dB]')2 C0 P& k! N# }0 Y6 z/ L7 c
axis([0 Fs/4 -120 0]);! Z* m: X) n, y9 m
text(Fs/10,-20,sprintf('\\bfSNR = %3.1fdB @ \\alpha\\DeltaX = %1.0e\n'...
8 o) v: R+ P- t- m5 F, X7 m; ] ,snr,alphadx),'Fontsize',12);
7 r [# w# W x2 y; h7 P. jtext(f*2,ptot((f*N+1)*2-1)+3,sprintf('\\bf%2.1fdB',ptot((f*N+1)*2-1)),...
) e. ^; n, M) \7 Y9 m 'Fontsize',8,'HorizontalAlignment','center'); |
|