?? sincy6.m
字號:
%對sin信號進行抽樣得到的結論6
clc
clear
fc=1;%sin信號的頻率
a=-4;%信號的起始時間
b=4;%信號的終止時間
ts=1/(16*fc);%為使信號能較平滑的畫出,設置的采樣時間間隔
fs=1/ts;%由上面的采樣時間間隔得到的采樣頻率
%----
f_s=fc*8;%采樣頻率是sin信號頻率的8倍,即每個sin周期取樣8個點
t_s=1/f_s;%由上面的采樣頻率得到的采樣時間間隔
t1=a:ts:b;%信號的持續時間
f1=-fs/2+fs/length(t1):fs/length(t1):fs/2;
z=sin(2*pi*fc*t1);%原始sin信號
z_spect=fftshift(abs(fft(z)));
t_c1=a:t_s:b;
x1=sin(2*pi*fc*t_c1);
y1=0;
for i=1:length(x1)
y1=y1+x1(i)*sinc((t1-t_c1(i))/t_s);
end
y1_spect=fftshift(abs(fft(y1)));
%----
bu_zeros=8;%補0的個數
t2=a:ts:b+bu_zeros*t_s;%按補0的個數將信號的持續時間延長
f2=-fs/2+fs/length(t2):fs/length(t2):fs/2;
t_c2=a:t_s:b+bu_zeros*t_s;
x2=[x1,zeros(1,bu_zeros)];%在抽樣值后補0
y2=0;
for i=1:length(x2)
y2=y2+x2(i)*sinc((t2-t_c2(i))/t_s);
end
y2_spect=fftshift(abs(fft(y2)));
figure(1)
subplot(2,2,1)
plot(t1,z,t_c1,x1,'*black');title('(a)原始信號,黑點為抽樣點');grid
subplot(2,2,2)
plot(f1,z_spect);title('(b)原始信號的頻譜');grid
subplot(2,2,3)
plot(t1,y1);title('(c)用抽樣點重建的信號');grid
subplot(2,2,4)
plot(f1,y1_spect);title('(d)重建信號的頻譜');grid
figure(2)
subplot(2,2,1)
plot(t1,z,t_c2,x2,'*black');title('(a)原始信號,黑點為抽樣點及補0點');grid
subplot(2,2,2)
plot(f1,z_spect);title('(b)原始信號的頻譜');grid
subplot(2,2,3)
plot(t2,y2);title('(c)用抽樣點及補0點重建的信號');grid
subplot(2,2,4)
plot(f2,y2_spect);title('(d)重建信號的頻譜');grid
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -