⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 s2_10_sample.m

📁 信号与系统的讲义
💻 M
字号:
%标准信号,高频采样
tmax = 2;
st = [0:0.0001:tmax];	%时域显示范围[0:tmax]
sx = 2*cos(2*pi*1*st)+2*cos(2*pi*4*st)+cos(2*pi*10*st);

%测试采样定理(最高频率fmax=10Hz)
flag =1;				%1:一阶保持;0:零阶保持
N = 4096;				%变换点数:2的幂次
Fs =20; 				%采样频率
Ts = 1/Fs;				%采样周期
N0 = floor(tmax*Fs)+1;	%时域显示范围[0:tmax]
t = 0:Ts:(N-1)*Ts;		%时域采样
x = 2*cos(2*pi*1*t)+2*cos(2*pi*4*t)+cos(2*pi*10*t);

%时域绘图
subplot(211);
if(flag)
	h11 = plot(st,sx,'b.',t(1:N0),x(1:N0),'r'); set(h11,'LineWidth',[2]);
else
	h1=plot(st,sx,'b.'); set(h1,'LineWidth',[2]);hold on;
	h11 = stairs(t(1:N0),x(1:N0),'r'); set(h11,'LineWidth',[2]);hold off
end
h12 = title(strcat('时域,采样频率Fs=',num2str(Fs),'Hz'));
set(h12,'Color',[1 0 0],'FontSize',[24],'FontWeight','bold','LineWidth',[2]);
h13 = xlabel('时间s');

%频域绘图
Fdm=12;							%频率显示范围Fdm=Fs/2
w = [0:Fs/N:Fdm];
ytemp = [abs(fft(x))/N]; 
ytemp(N/2+1)=ytemp(N/2+1)/2;	%重叠计算,所以除2
if(Fs<2*Fdm)
	y = [ytemp([1:N/2+1]), zeros(1,length(w)-N/2-1)]; 
else
	y = ytemp([1:length(w)]); 
end
subplot(212);
h21 = plot(w,y,'r'); 
set(h21,'LineWidth',[2]);
h22 = title('频域                     '); 
set(h22,'Color',[1 0 0],'FontSize',[24],'FontWeight','bold','LineWidth',[2]);
h23 = xlabel('频率Hz');
set(gca,'XTick',[0:Fdm])
set(gca,'XTickLabel',[0:Fdm])

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -