信號(hào)生成和可視化——周期性/非周期性波形
目錄
信號(hào)生成和可視化——周期性/非周期性波形
周期性波形
sawtooth 函數(shù)生成鋸齒波
square 函數(shù)生成方波
非周期性波形
tripuls、rectpuls?和?gauspuls?函數(shù)
gauspuls?函數(shù)使用指定時(shí)間、中心頻率和小數(shù)帶寬生成高斯調(diào)制正弦脈沖。
sinc?函數(shù)計(jì)算輸入向量或矩陣的數(shù)學(xué)正弦函數(shù)
掃頻波形
chirp?函數(shù)生成線性或二次、凸和凹二次 chirp
脈沖序列
pulstran 函數(shù)生成脈沖序列波
Dirichlet 函數(shù)
另請(qǐng)參閱
此示例說明如何使用 Signal Processing Toolbox? 中提供的函數(shù)生成廣泛使用的周期和非周期性波形、掃頻正弦波和脈沖序列。嘗試此示例Copy Command ?Copy Code
周期性波形
除了 MATLAB? 中的?sin?和?cos?函數(shù)外,Signal Processing Toolbox? 還提供其他函數(shù)(如?sawtooth
?和?square
)來生成周期性信號(hào)。
sawtooth 函數(shù)生成鋸齒波
sawtooth?函數(shù)生成鋸齒波,波峰在?±1,周期為?2π??蛇x寬度參數(shù)以?2π?的小數(shù)倍來指定信號(hào)最大值出現(xiàn)的位置。
square 函數(shù)生成方波
square?函數(shù)生成周期為?2π?的方波??蛇x參數(shù)指定占空比,即信號(hào)為正的周期的百分比。
% % 以 10 kHz 的采樣率生成 1.5 秒的 50 Hz 鋸齒波。對(duì)一個(gè)方波進(jìn)行重復(fù)計(jì)算。
fs = 10000; %以10kHz的采樣率
t = 0:1/fs:1.5;
x1 = sawtooth(2*pi*50*t); %鋸齒波
x2 = square(2*pi*50*t); %方波
subplot(2,1,1) % subplot(m,n,p) 將當(dāng)前圖窗劃分為 m×n 網(wǎng)格,并在 p 指定的位置創(chuàng)建坐標(biāo)區(qū)。
plot(t,x1)%二維線圖
axis([0 0.2 -1.2 1.2])%設(shè)置坐標(biāo)軸范圍x[0,0.2], y[-1.2,1.2]
xlabel('Time (sec)')
ylabel('Amplitude')
title('Sawtooth Periodic Wave')
subplot(2,1,2)
plot(t,x2)
axis([0 0.2 -1.2 1.2])
xlabel('Time (sec)')
ylabel('Amplitude')
title('Square Periodic Wave')
% 使用 dutycycle 函數(shù)驗(yàn)證方波的占空比是否為指定值。
% 不帶輸出參數(shù)調(diào)用該函數(shù)來繪制波形、中間參考瞬時(shí)電平的位置、相關(guān)聯(lián)的參考電平、狀態(tài)電平以及相關(guān)聯(lián)的狀態(tài)上下邊界。
figure
dc = dutycycle(x2,fs);
dc = dc(1);
% disp(dc);%輸出dc的值
fprintf('the value of dc is%6.2f\n',dc)%輸出dc的值
dutycycle(x2,fs);
xlim([0 0.2])
非周期性波形
tripuls
、rectpuls
?和?gauspuls
?函數(shù)
為了生成三角形、矩形和高斯脈沖,工具箱提供了?tripuls
、rectpuls
?和?gauspuls
?函數(shù)。
tripuls?函數(shù)生成以?t?= 0 為中心、默認(rèn)寬度為 1 的采樣非周期性單位高度三角形脈沖。
rectpuls?函數(shù)生成以?t?= 0 為中心、默認(rèn)寬度為 1 的采樣非周期性單位高度矩形脈沖。非零幅值的區(qū)間定義為在右側(cè)開放:rectpuls(-0.5) = 1
,而?rectpuls(0.5) = 0
。
% % 生成 2 秒的三角形脈沖,采樣率為 10 kHz,寬度為 20 ms。對(duì)一個(gè)矩形脈沖進(jìn)行重復(fù)計(jì)算。
fs = 10000;
t = -1:1/fs:1;
x1 = tripuls(t,20e-3);
x2 = rectpuls(t,20e-3);
figure
subplot(2,1,1)
plot(t,x1)
axis([-0.1 0.1 -0.2 1.2])
xlabel('Time (sec)')
ylabel('Amplitude')
title('Triangular Aperiodic Pulse')
subplot(2,1,2)
plot(t,x2)
axis([-0.1 0.1 -0.2 1.2])
xlabel('Time (sec)')
ylabel('Amplitude')
title('Rectangular Aperiodic Pulse')
gauspuls?函數(shù)使用指定時(shí)間、中心頻率和小數(shù)帶寬生成高斯調(diào)制正弦脈沖。
sinc?函數(shù)計(jì)算輸入向量或矩陣的數(shù)學(xué)正弦函數(shù)
sinc?函數(shù)計(jì)算輸入向量或矩陣?x?的數(shù)學(xué)正弦函數(shù)。作為時(shí)間或空間的函數(shù),sinc 函數(shù)是以零為中心、寬度為?2π?并具有單位高度的頻率的矩形脈沖的傅里葉逆變換:
% 生成帶寬為 60%、采樣率為 1 MHz 的 50 kHz 高斯 RF 脈沖。
% 當(dāng)包絡(luò)比峰值低 40 dB 時(shí),截?cái)嗝}沖。
tc = gauspuls('cutoff',50e3,0.6,[],-40);
t1 = -tc : 1e-6 : tc;
y1 = gauspuls(t1,50e3,0.6);
% 為一個(gè)線性間距向量生成正弦函數(shù):
t2 = linspace(-5,5);
y2 = sinc(t2);
figure
subplot(2,1,1)
plot(t1*1e3,y1)
xlabel('Time (ms)')
ylabel('Amplitude')
title('Gaussian Pulse')
subplot(2,1,2)
plot(t2,y2)
xlabel('Time (sec)')
ylabel('Amplitude')
title('Sinc Function')
掃頻波形
chirp
?函數(shù)生成線性或二次、凸和凹二次 chirp
工具箱還提供生成掃頻波形的函數(shù),如?chirp?函數(shù)。兩個(gè)可選參數(shù)以度為單位指定替代掃描方法和初始相位。
chirp 生成線性、對(duì)數(shù)或二次掃頻正弦信號(hào)??蛇x參數(shù)指定替代掃描方法。可選參數(shù)允許以度數(shù)指定初始相位。
下面是使用?chirp
?函數(shù)生成線性或二次、凸和凹二次 chirp 的幾個(gè)示例。
% 生成線性 chirp。
t = 0:0.001:2; % 2 secs @ 1kHz sample rate
ylin = chirp(t,0,1,150); % Start @ DC, cross 150Hz at t=1sec
% 繪制 chirp 的頻譜圖。指定相鄰窗段之間的重疊為 90%。
figure
pspectrum(ylin,t,'spectrogram','OverlapPercent',90)
% 生成二次 chirp。
t = -2:0.001:2; % +/-2 secs @ 1kHz sample rate
yq = chirp(t,100,1,200,'q'); % Start @ 100Hz, cross 200Hz at t=1sec
% 計(jì)算并顯示 chirp 的頻譜圖。
figure
subplot(2,1,1)
spectrogram(ylin,256,250,256,1E3,'yaxis')
title('Linear Chirp')
subplot(2,1,2)
spectrogram(yq,128,120,128,1E3,'yaxis')
title('Quadratic Chirp')
% 生成凸二次 chirp。
t = -1:0.001:1; % +/-1 second @ 1kHz sample rate
fo = 100;
f1 = 400; % Start at 100Hz, go up to 400Hz
ycx = chirp(t,fo,1,f1,'q',[],'convex');
% 生成凹二次 chirp。
t = -1:0.001:1; % +/-1 second @ 1kHz sample rate
fo = 400;
f1 = 100; % Start at 400Hz, go down to 100Hz
ycv = chirp(t,fo,1,f1,'q',[],'concave');
% 計(jì)算并顯示 chirp 的頻譜圖。
figure
subplot(2,1,1)
spectrogram(ycx,256,255,128,1000,'yaxis')
title('Convex Chirp')
subplot(2,1,2)
spectrogram(ycv,256,255,128,1000,'yaxis')
title('Concave Chirp')
另一個(gè)函數(shù)生成器是?vco(壓控振蕩器),它生成以輸入向量確定的頻率振蕩的信號(hào)。輸入向量可以是三角形、矩形或正弦波等。
% 生成以 10 kHz 采樣的 2 秒信號(hào),其瞬時(shí)頻率為三角形。對(duì)一個(gè)矩形進(jìn)行重復(fù)計(jì)算。
fs = 10000;
t = 0:1/fs:2;
x1 = vco(sawtooth(2*pi*t,0.75),[0.1 0.4]*fs,fs);
x2 = vco(square(2*pi*t),[0.1 0.4]*fs,fs);
% 繪制生成的信號(hào)的頻譜圖。
figure
subplot(2,1,1)
spectrogram(x1,kaiser(256,5),220,512,fs,'yaxis')
title('VCO Triangle')
subplot(2,1,2)
spectrogram(x2,256,255,256,fs,'yaxis')
title('VCO Rectangle')
脈沖序列
pulstran 函數(shù)生成脈沖序列波
要生成脈沖序列,您可以使用?pulstran?函數(shù)。
% 構(gòu)造一個(gè) 2 GHz 矩形脈沖序列,它以 7.5 ns 的間距和 100 GHz 的速率采樣。
fs = 100E9; % sample freq
D = [2.5 10 17.5]' * 1e-9; % pulse delay times
t = 0 : 1/fs : 2500/fs; % signal evaluation time
w = 1e-9; % width of each pulse
yp = pulstran(t,D,@rectpuls,w);
% 生成 10 kHz、50% 帶寬的周期性高斯脈沖信號(hào)。脈沖重復(fù)頻率為 1 kHz,采樣率為 50 kHz,
% 脈沖序列長度為 10 毫秒。重復(fù)幅值每次應(yīng)按 0.8 衰減。
% 使用函數(shù)句柄指定生成器函數(shù)。
T = 0 : 1/50e3 : 10e-3;
D = [0 : 1/1e3 : 10e-3 ; 0.8.^(0:10)]';
Y = pulstran(T,D,@gauspuls,10E3,.5);
figure
subplot(2,1,1)
plot(t*1e9,yp);
axis([0 25 -0.2 1.2])
xlabel('Time (ns)')
ylabel('Amplitude')
title('Rectangular Train')
subplot(2,1,2)
plot(T*1e3,Y)
xlabel('Time (ms)')
ylabel('Amplitude')
title('Gaussian Pulse Train')
Dirichlet 函數(shù)
diric
?函數(shù)計(jì)算輸入向量或矩陣?x
?的 Dirichlet 函數(shù),有時(shí)稱為周期性正弦函數(shù)或混疊正弦函數(shù)。Dirichlet 函數(shù)由下式定義
其中?N?是用戶指定的正整數(shù)。如果?N?為奇數(shù),則 Dirichlet 函數(shù)的周期為2π;如果?N?為偶數(shù),則其周期為?4π。此函數(shù)的幅值是?1/N?乘以包含?N?個(gè)點(diǎn)的矩形窗的離散時(shí)間傅里葉變換的幅值。
要為?N=7?和?N=8?繪制 0 和?4π?之間的 Dirichlet 函數(shù),使用:
figure
x = linspace(0,4*pi,300);
subplot(2,1,1)
plot(x/pi,diric(x,7))
title('N = 7')
subplot(2,1,2)
plot(x/pi,diric(x,8))
title('N = 8')
xlabel('x / \pi')
另請(qǐng)參閱
chirp?|?gauspuls?|?pulstran?|?rectpuls?|?sawtooth?|?sin?|?sinc?|?square?|?tripuls?|?vco文章來源:http://www.zghlxwxcb.cn/news/detail-419027.html
【我是小蜜蜂,知識(shí)的搬運(yùn)工!】文章來源地址http://www.zghlxwxcb.cn/news/detail-419027.html
到了這里,關(guān)于信號(hào)生成和可視化——周期性/非周期性波形的文章就介紹完了。如果您還想了解更多內(nèi)容,請(qǐng)?jiān)谟疑辖撬阉鱐OY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!