您好,欢迎访问三七文档
当前位置:首页 > 行业资料 > 其它行业文档 > MATLAB信号频谱分析
题1-周期信号频谱分析题目:给定输入信号x(n)为一周期信号,含基波及若干次谐波分量。要求:1、给出信号基波频率及谐波个数2、基波及各个谐波信号的相位和幅值clearclcA=[0.250.50.25];f=[124];fi=[00.5*pi0.75*pi];N=59;fs=10;t=(1:N)./fs;x_n=A(1).*sin(2*pi*f(1)*t+fi(1))+A(2).*sin(2*pi.*f(2)*t+fi(2))+A(3).*sin(2pi.*f(3)*t+fi(3));save('Signal.mat','x_n')程序如下fs=10;N=60;n=1:N;t=n/fs;x=0.25*sin(2*pi*t)+0.5*sin(2*pi*2*t)+0.25*sin(2*pi*4*t);figure(1)subplot(211);plot(x);grid;y=fft(x,N);mag=abs(y);k=0:length(y)-1;f=fs/N*k;subplot(212);plot(f,mag);xlabel('Frequence(Hz)');ylabel('Magnitude');grid;title('对周期信号的一个周期进行频谱分析')figure(2)x=[xxxxx];figure(2)subplot(211);plot(x);grid;N=length(x)y=fft(x,N);mag=abs(y);k=0:length(y)-1;f=fs/N*ksubplot(212);plot(f,mag);xlabel('Frequence(Hz)');ylabel('Magnitude');grid;title('对周期信号的多个周期进行频谱分析')0102030405060-1-0.500.5101234567891005101520Frequence(Hz)Magnitude对周期信号的一个周期进行频谱分析050100150200250300-1-0.500.51012345678910020406080Frequence(Hz)Magnitude对周期信号的多个周期进行频谱分析题2-数字滤波器设计题目:已知输入信号x(t)=0.6sin(200πt)+sin(400πt)+0.3sin(800πt)。要求:通过MATLAB编程设计一1)低通滤波器,输出信号x(t)的最低频率成份.2)高通滤波器,输出信号x(t)的最高频率成份.3)带通滤波器,输出信号x(t)的中间频率成份.4)带阻滤波器,输出信号x(t)的最低+最高频率成份.(Rp=1dB,Rs=16dB,Fs=3倍最高频率,截止频率、滤波器设计方法及类型自己选择.)解:编写程序如下:Fs=1200;N=1024;n=0:N;t=n/Fs;x=0.6*sin(200*pi*t)+sin(400*pi*t)+0.3*sin(800*pi*t);y=fft(x,N);mag=abs(y);k=0:length(y)-1;f=Fs/N*k;figure(1)plot(f,mag);xlabel('Frequence(Hz)');ylabel('Magnitude');title('N=1024');grid;020040060080010001200050100150200250300350400450Frequence(Hz)MagnitudeN=1024Wp=0.12*pi;Ws=0.2*pi;rp=1;rs=16;Fs=1200;%数字滤波器指标wp=Wp*Fs;ws=Ws*Fs;%模拟技术指标[n,wn]=buttord(wp,ws,rp,rs,'s');[z,p,k]=buttap(n);[b,a]=zp2tf(z,p,k);[b,a]=lp2lp(b,a,wn);figure(2)h1=freqs(b,a);freqs(b,a);title('模拟低通的幅频和相频特性图');[bz,az]=impinvar(b,a,Fs);figure(3)freqz(bz,az,256);title('数字底通的幅频和相频特性图');y1=filter(bz,az,x);y=fft(y1,N);mag=abs(y);k=0:length(y)-1;f=Fs/N*k;figure(10)plot(f,mag);grid;title('输出信号x(t)的最低频率成份')0200400600800100012000102030405060708090100输出信号x(t)的最低频率成份wp=.4*pi;ws=.35*pi;rp=1;rs=16;Fs=1200;%数字滤波器指标wap=2*Fs*tan(wp/2);was=2*Fs*tan(ws/2);[n,wn]=buttord(wap,was,rp,rs,'s');[z,p,k]=buttap(n);[b,a]=zp2tf(z,p,k);[bt,at]=lp2hp(b,a,wap);w=0:pi:4000*pi;figure(4)freqs(bt,at,w);title('模拟高通的幅频和相频特性图');[bz,az]=bilinear(bt,at,Fs);figure(7)freqz(bz,az,256,1);title('数字高通的幅频和相频特性图');y2=filter(bz,az,x);y=fft(y2,N);mag=abs(y);k=0:length(y)-1;f=Fs/N*k;figure(11)plot(f,mag);grid;title('输出信号x(t)的最高频率成份')020040060080010001200020406080100120140输出信号x(t)的最高频率成份wp=[0.2*pi0.35*pi];ws=[0.12*pi0.4*pi];rp=1;rs=30;Fs=1200;%数子滤波器指标wap=2*Fs*tan(wp./2);was=2*Fs*tan(ws./2);%模拟滤波器指标[n,wn]=buttord(wap,was,rp,rs,'s');[z,p,k]=buttap(n);[bp,ap]=zp2tf(z,p,k);bw=wap(2)-wap(1);w0=sqrt(wap(1)*wap(2));[bs,as]=lp2bp(bp,ap,w0,bw);w=0:pi:4000*pi;figure(6)freqs(bs,as,w);title('模拟带通的幅频和相频图');[bz,az]=bilinear(bs,as,Fs);figure(7)freqz(bz,az,256,Fs);title('数字带通的幅频和相频图')y3=filter(bz,az,x);y=fft(y3,N);mag=abs(y);k=0:length(y)-1;f=Fs/N*k;figure(12)plot(f,mag);grid;title('输出信号x(t)的中间频率成份')020040060080010001200050100150200250300350400450输出信号x(t)的中间频率成份wp=[0.15*pi0.4*pi];ws=[0.2*pi0.35*pi];rp=1;rs=16;Fs=1200;%数值指标wap=2*Fs*tan(wp./2);was=2*Fs*tan(ws./2);%模拟指标[n,wn]=buttord(wap,was,rp,rs,'s');[z,p,k]=buttap(n);[b,a]=zp2tf(z,p,k);bw=wap(2)-wap(1);w0=sqrt(wap(1)*wap(2));[bt,at]=lp2bs(b,a,w0,bw);figure(8)w=0:pi:4000*pi;freqs(bt,at,w);title('模拟带阻的幅频和相频图')[bz1,az1]=bilinear(bt,at,Fs);%模拟到数字figure(9)freqz(bz1,az1,256,Fs);title('数字带阻的幅频和相频图')y4=filter(bz1,az1,x);y=fft(y4,N);mag=abs(y);k=0:length(y)-1;f=Fs/N*k;figure(13)plot(f,mag);grid;title('输出信号x(t)的最低+最高频率成份')020040060080010001200020406080100120140输出信号x(t)的最低+最高频率成份题3-语音信号采集与处理初步题目:1.语音信号的采集2.语音信号的频谱分析3.设计数字滤波器和画出频率响应4.用滤波器对信号进行滤波5.比较滤波前后语音信号的波形及频谱6.回放和存储语音信号解:编程如下[x,fs,bits]=wavread('类似爱情.wav');wavplay(x,fs);X=fft(x,4096);magX=abs(X);angX=angle(X);figure(1)subplot(221);plot(x);title('原始信号波形');subplot(222);plot(X);title('原始信号频谱');subplot(223);plot(magX);title('原始信号幅值');subplot(224);plot(angX);title('原始信号相位');n=length(x);t=0:1/fs:(n-1)/fs;051015x104-1-0.500.51原始信号波形-400-2000200-400-2000200400原始信号频谱02000400060000100200300400原始信号幅值0200040006000-4-2024原始信号相位noise=0.5*sin(100*pi*t)+sin(400*pi*t)+0.5*sin(1600*pi*t);figure(2)plot(t,noise);grid;xlabel('时间(t)');ylabel('幅度(y)');title('噪声的时域图');Noise=fft(noise,n);N1=abs(Noise);n1=floor(n/2);f=(0:n1)*fs/n;figure(3);%画出噪声的频谱图plot(f,N1(1:n1+1));gridon;xlabel('频率(f)');ylabel('幅度(N1)');title('噪声的频谱图');01234567-2-1.5-1-0.500.511.52时间(t)幅度(y)噪声的时域图02000400060008000100001200000.511.522.533.544.55x104频率(f)幅度(N1)噪声的频谱图x=x(:,1);x1=noise+x';sound(x1,fs);wavwrite(x1,16,'类似爱情1.wav');figure(4)%画出加噪声前后的时域比较图subplot(221);plot(t,x);gridon;xlabel('时间(t)');ylabel('幅度(x)');title('加噪声前的时域图');subplot(222);plot(t,x1);gridon;xlabel('时间(t)');ylabel('幅度(Y1)');title('加噪声后的时域图');X=fft(x,n);%对加噪声前的采样信号1进行傅立叶变换MagX=abs(X);X1=fft(x1,n);%对加噪声后的采样信号1进行傅立叶变换MagX1=abs(X1);subplot(223);plot(f,MagX(1:n1+1));gridon;xlabel('频率(f)');ylabel('幅度(MagX)');title('加噪声前的频谱图');subplot(224);plot(f,MagX1(1:n1+1));gridon;xlabel('频率(f)');ylabel('幅度(MagX1)');title('加噪声后的频谱图');02468-1-0.500.51时间(t)幅度(x)加噪声前的时域图02468-4
本文标题:MATLAB信号频谱分析
链接地址:https://www.777doc.com/doc-6990308 .html