資源簡介
matlab 代碼 信號帶寬估計的matlab代碼

代碼片段和文件信息
%
%?FUNCTION?1.2?:?“cp0101_bandwidth“
%
%?Evaluates?the?bandwidth?of?the?input?‘signal‘?with?sampling?period?‘dt‘
%
%?Bandwidth?is?evaluated?according?to?the?given?‘threshold‘(in?dB)
%?‘BW‘?is?the?bandwidth
%?‘f_high‘?is?the?higher?limit
%?‘f_low‘?is?the?lower?limit
%?調制信號的單邊帶寬是基帶信號帶寬的2倍,要調制到1000Hz正弦波上,f0=1e3
%?Programmed?by?Guerino?Giancola
%
function?[ss_Ef_highf_lowBW]=cp0101_bandwidth(signaldtthreshold)
%?---------------------------------------------------------
%?Step?One?-?Evaluation?of?the?single-sided?ESD(功率譜密度)
%?---------------------------------------------------------
threshold=-3;?????????????????????????????????????%?計算帶寬所需要的閾值為-3dB或-10dB
width=1e-1;
points=500;
f0=0;?????????????????????????????????????????????%?要調制到1000Hz正弦波上,f0=1e3
dt=width/points;
signal=zeros(15*points);?????????????????????????%?矩陣1到5*points
signal(2*points:3*points-1)=ones(1points);???????%?signal矩陣從2*points到3*points-1這1000點都為1
mod=cos(2.*pi.*f0.*linspace(15*width5*points));?
signal=signal.*mod;
fs=1/dt;
N=length(signal);
T=N*dt;
df=1/T;
X=fft(signal);
X=X/N;
ds_E=abs(X).^2/(df^2);
ss_E=2.*ds_E(1:floor(N/2));
%?------------------------------------------------
%?Step?Two?-?Evaluation?of?the?frequency?bandwidth
%?------------------------------------------------
[Epeakindex]=max(ss_E);
f_peak=index*df;
Eth=Epeak*10^(threshold/10);
%?iterative?algorithm?for?evaluating?high?and?low?frequencies
imax=index;
E0h=ss_E(index);
while?(E0h>Eth)&(imax<=(N/2))
????imax=imax+1;
????E0h=ss_E(imax);
end
f_high=(imax-1)*df;
imin=index;
E0l=ss_E(index);
while?(E0l>Eth)&(imin>1)&(index>1)
????imin=imin-1;
????E0l=ss_E(imin);
end
f_low=(min(indeximin)-1)*df;
%?end?of?iterative?algorithm
BW=f_high-f_low;
fprintf(‘\nFrequency?Bandwidth=?%f?[Hz]\nHigh?Frequency=%f?[Hz]\nLow?Frequency=?%f?[Hz]\n‘BWf_highf_low);
%?-----------------------------
%?Step?Three?-?Graphical?output
%?-----------------------------
figure(2)
frequency=linspace(0fs/2length(ss_E));
PF=plot(frequencyss_E);
set(PF‘LineWidth‘[2]);???????????????????????%?線條寬度為[2]
L1=line([f_high?f_high][min(ss_E)?max(ss_E)]);
set(L1‘Color‘[0?0?0]‘Linestyle‘‘:‘);
L1=line([f_low?f_low][min(ss_E)?max(ss_E)]);
set(L1‘Color‘[0?0?0]‘Linestyle‘‘:‘);
L1=line([f_low?f_high][Eth?Eth]);
set(L1‘LineWidth‘[2]‘Color‘‘red‘‘Linestyle‘‘:‘);
axis([0.8*f_low?1.2*f_high?-0.1*Epeak?1.2*Epeak]);
AX=gca;
set(AX‘FontSize‘12);
T=title(‘Frequency?domain‘);
set(T‘FontSize‘14);
X=xlabel(‘Frequency?[Hz]‘);
set(X‘FontSize‘14);
Y=ylabel(‘Single-Sided?ESD?[V^2s/Hz]‘);
set(Y‘FontSize‘14);
?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
?????文件???????2712??2008-09-30?18:35??bandwidth.m
-----------?---------??----------?-----??----
?????????????????2712????????????????????1
評論
共有 條評論