原文地址:http://blog.chinaunix.net/uid-11829250-id-4992257.htmlcss
以高斯信號爲例,計算幅度譜、相位譜、雙邊功率譜、雙邊功率譜密度、單邊功率譜、單邊功率譜密度。(轉載請註明出處)html
MATLAB程序代碼:
ui
- %==========================================================================
%Name: spectrum_analysis.m
%Desc: 以高斯信號爲例,求解其頻譜、雙邊功率譜、單邊功率譜、雙邊功率譜密度、
% 單邊功率譜密度,這裏高斯信號的半波全寬FWHM=50ps,中心點位於2.5ns處。
%Parameter:
%Return:
%Author: yoyoba(stuyou@126.com)
%Date: 2015-4-28
%Modify: 2015-4-29
%=========================================================================
clc;
clear;
FWHM=50e-12; %高斯信號FWHM寬度,爲50ps
time_window=100*FWHM; %高斯信號的採樣窗口寬度,該值決定了傅里葉變換後的頻率分辨率
Ns=2048; %採樣點
dt=time_window/(Ns-1); %採樣時間間隔
t=0:dt:time_window; %採樣時間
gauss_time=exp(-0.5*(2*sqrt(2*log(2))*(t-2.5e-9)/FWHM).^2); %高斯脈衝,中心位於2.5ns處。
plot(t*1e+9,gauss_time,'linewidth',2.5);
xlabel('Time/ns');
ylabel('Amplitude/V');
title('Gauss pulse');
%===========如下計算雙邊譜、雙邊功率譜、雙邊功率譜密度=================
gauss_spec=fftshift(fft(ifftshift(gauss_time))); %傅里葉變換,而且進行fftshift移位操做。
gauss_spec=gauss_spec/Ns; %求實際的幅度值;
df=1/time_window; %頻率分辨率
k=floor(-(Ns-1)/2:(Ns-1)/2);
% k=0:Ns-1;
double_f=k*df; %雙邊頻譜對應的頻點
figure; %幅度譜
plot(double_f*1e-9,abs(gauss_spec),'linewidth',2.5);
xlabel('Frequency/GHz');
ylabel('Amplitude/V');
title('double Amplitude spectrum');
figure; %相位譜
plot(double_f*1e-9,angle(gauss_spec),'linewidth',2.5);
xlabel('Frequency/GHz');
ylabel('Phase/rad');
title('double Phase spectrum');
figure; %功率譜
double_power_spec_W=abs(gauss_spec).^2; %雙邊功率譜,單位W;
double_power_spec_mW=double_power_spec_W*1e+3; %雙邊功率譜,單位mW;
double_power_spec_dBm=10*log10(double_power_spec_mW); %雙邊功率譜,單位dBm;
plot(double_f*1e-9,double_power_spec_dBm,'linewidth',2.5);
xlabel('Frequency/GHz');
ylabel('Power/dBm');
title('double Power spectrum');
figure; %功率譜密度
double_power_specD_W=abs(gauss_spec).^2/(df); %雙邊功率譜密度,單位W/Hz
double_power_specD_mW=double_power_specD_W*1e+3; %雙邊功率譜密度,單位mW/Hz
double_power_specD_dBm=10*log10(double_power_specD_mW);%雙邊功率譜密度,單位dBm/Hz
plot(double_f*1e-9,double_power_specD_dBm,'linewidth',2.5);
xlabel('Frequency/GHz');
ylabel('Power/(dBm/Hz)');
title('double power spectrum Density');
%==========如下計算單邊譜、單邊功率譜及單邊功率譜密度=========
gauss_spec=fft(ifftshift(gauss_time)); %計算單邊譜無需fftshift
gauss_spec=gauss_spec/Ns; %計算真實的幅度值
single_gauss_spec=gauss_spec(1:floor(Ns/2));
single_f=(0:floor(Ns/2)-1)*df;
figure; %幅度譜
plot(single_f*1e-9,abs(single_gauss_spec),'linewidth',2.5);
xlabel('Frequency/GHz');
ylabel('Amplitude/V');
title('single Amplitude spectrum');
figure; %相位譜
plot(single_f*1e-9,angle(single_gauss_spec),'linewidth',2.5);
xlabel('Frequency/GHz');
ylabel('Phase/rad');
title('single Phase spectrum');
figure;%功率譜
double_power_spec_W=abs(gauss_spec).^2;
single_power_spec_W=2*double_power_spec_W(1:floor(Ns/2)); %單邊功率譜,單位W
single_power_spec_mW=single_power_spec_W*1e+3; %單邊功率譜,單位mW;
single_power_spec_dBm=10*log10(single_power_spec_mW); %雙邊功率譜,單位dBm;
plot(single_f*1e-9,single_power_spec_dBm,'linewidth',2.5);
xlabel('Frequency/GHz');
ylabel('Power/dBm');
title('single Power spectrum');
figure;%功率譜密度
double_power_specD_W=abs(gauss_spec).^2/(df);
single_power_specD_W=2*double_power_specD_W(1:floor(Ns/2)); %單邊功率譜密度,單位W/Hz
single_power_specD_mW=single_power_specD_W*1e+3; %單邊功率譜密度,單位mW/Hz
single_power_specD_dBm=10*log10(single_power_specD_mW); %單邊功率譜密度,單位dBm/Hz
plot(single_f*1e-9,single_power_specD_mW,'linewidth',2.5);
xlabel('Frequency/GHz');
ylabel('Power/(dBm/Hz)');
title('single power spectrum density');
運行結果:
spa