?? sinhscy5.m
字號:
%對sin信號進行抽樣得到的結論5
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;%由上面的采樣頻率得到的采樣時間間隔
n=t_s/ts;
t1=a:ts:b;
f1=-fs/2+fs/length(t1):fs/length(t1):fs/2;
w1=sin(2*pi*fc*t1);
w1_spect=fftshift(abs(fft(w1)));
t_c1=a:t_s:b;%采樣時刻
x1=sin(2*pi*fc*t_c1);%在上面的采樣時刻采得的樣值,其長度包括了整數倍個周期
y1=zeros(1,n*(length(x1)-1)+1);
y1(1:n:n*length(x1))=x1;
y1_spect=fftshift(abs(fft(y1)));
z1=convn(y1,sinc(t1/t_s),'same');%重建信號
z1_spect=fftshift(abs(fft(z1)));%重建信號的頻譜
%----
s=4;%小于每個sin周期內的采樣點數
t2=a:ts:b-s*t_s;
f2=-fs/2+fs/length(t2):fs/length(t2):fs/2;
t_c2=a:t_s:b-s*t_s;%采樣時刻
x2=sin(2*pi*fc*t_c2);%在上面的采樣時刻采得的樣值,其長度包括了非整數倍個周期
y2=zeros(1,n*(length(x2)-1)+1);
y2(1:n:n*length(x2))=x2;
y2_spect=fftshift(abs(fft(y2)));
z2=convn(y2,sinc(t2/t_s),'same');%重建信號
z2_spect=fftshift(abs(fft(z2)));%重建信號的頻譜
figure(1)
subplot(3,2,1)
plot(t1,w1);title('初始相位為0的sin信號');grid
subplot(3,2,2)
plot(f1,w1_spect);title('初始相位為0的sin信號的頻譜');grid
subplot(3,2,3)
stem(t_c1,x1);title('每個sin周期取樣3個點得到的抽樣點');grid
subplot(3,2,4)
plot(f1,y1_spect);title('抽樣點的頻譜');grid
subplot(3,2,5)
plot(t1,z1);title('用抽樣點重建的信號');grid
subplot(3,2,6)
plot(f1,z1_spect);title('重建信號的頻譜');grid
figure(2)
subplot(3,2,1)
plot(t1,w1);title('初始相位為0的sin信號');grid
subplot(3,2,2)
plot(f1,w1_spect);title('初始相位為0的sin信號的頻譜');grid
subplot(3,2,3)
stem(t_c2,x2);title('每個sin周期取樣3個點得到的抽樣點');grid
subplot(3,2,4)
plot(f2,y2_spect);title('抽樣點的頻譜');grid
subplot(3,2,5)
plot(t2,z2);title('用抽樣點重建的信號');grid
subplot(3,2,6)
plot(f2,z2_spect);title('重建信號的頻譜');grid
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -