MATLAB上机 采样定理

来源:互联网 发布:郑州婚纱摄影知乎 编辑:程序博客网 时间:2024/05/16 13:51

采样定理

fft1.m

function result=fft1(w,hanshu,n)for i=1:length(w)    m=hanshu.*((exp(-1i*(i-1)*pi/100)).^n);    a{i}=sum(m);  endfor i=1:length(w)       result(i)=a{i};end

原始信号

x1=0:pi/10:(8*pi);   w=linspace(0,8*pi,length(x1)); figure  subplot(211)plot(x1,sin(x1)+2*cos(x1),'k');  %原时域连续信号y=sin(t)+2cost line([0 30],[0 0]);xlabel('t');ylabel('x(t)');title('原时域连续信号y=sin(t)+2cost');  grid  sin1=sin(x1)+2*cos(x1);   n=0:(length(x1)-1); subplot(212)  plot(w,abs(fft1(w,sin1,n)));      %其对应频域信号Y=FFT(sin(t))      xlabel('w');ylabel('x(w)');   title('其对应频域信号Y=FT(sin(t)+2cos(t))'); grid 

采样信号

n1=input('请输入采样点数n:'); n=0:n1;  zb=size(n);  figure  %sinf=sin(8*pi*n/zb(2)); sinf=sin(8*pi*n/zb(2))+2*cos(8*pi*n/zb(2));subplot(211);  stem(n,sinf,'.');   xlabel('n');ylabel('x(n)');title('采样后的时域信号y=x(n)'); w=0:(pi/100):4*pi;subplot(212)  plot(w,abs(fft1(w,sinf,n))); xlabel('w');ylabel('x(w)');   title('采样后的频域信号y=FT(sin(n))'); 

低通滤波器

 wp=0.1;ws=0.7;Rp=2;As=30; [N,wc]=buttord(wp,ws,Rp,As);  [B,A]=butter(N,wc);             [H,w]=freqz(B,A,512,1000);      %返回在采样频率下频率向量figure; plot(w*1000/(2*pi),abs(H));  xlabel('Hz');ylabel('频率响应幅度');title('低通滤波器');grid;

恢复信号

figurey=filter(B,A,sinf);subplot(2,1,1);plot(y,'k')%恢复后的连续信号xlabel('t');ylabel('x(t)');title('恢复后的连续信号y=sin(t)+2cost');grid;Y=fft(y,512);w=(0:255)/256*500;subplot(2,1,2),plot(w,abs([Y(1:256)]));%绘制频谱图xlabel('Hz');ylabel('频率响应幅度');title('频谱图');grid;