《音乐信号的处理 matlab【知识分析】》由会员分享,可在线阅读,更多相关《音乐信号的处理 matlab【知识分析】(26页珍藏版)》请在金锄头文库上搜索。
1、1、音乐信号的音谱和频谱观察y,fs,bit=wavread(2);sound(y,fs);plot(y);y1=y(:,1);M=512;fh1=fft(y1,M);w=2/M*0:M-1;figure;plot(w,abs(fh1);2、音乐信号的抽取(减抽样)y,fs,bit=wavread(2);sound(y,fs);figure;subplot(1,2,1);plot(y);title(原音乐信号波形);y1=y(:,1);M=512;fh1=fft(y1,M);w=2/M*0:M-1;subplot(1,2,2);plot(w,fh1);title(原音乐信号频谱);grid o
2、n;j=0;d=10; %减抽样间隔 取3和10 代表混叠与非混叠 y3=y1(1:100000); for i=1:d:length(y3); j=j+1; yd(j)=y1(i); endsound(yd,fs/d); figure;subplot(1,2,1);plot(yd);title(减抽样时域);fh2=fft(yd);l1=length(fh2);w2=2/l1*(0:l1-1);subplot(1,2,2);plot(w2,abs(fh2);title(减抽样频域);3、音乐信号的AM调制和巴特沃斯IIR滤波器滤波w,fs,bit=wavread(2);w1=w(:,1);l
3、=length(w1);ww=2/l*(0:l-1);n=0:length(w1)-1;t1=w1.*cos(0.6*pi*n); T1=fft(t1);plot(t1);title(AM低/高频调制后波形);figure;plot(ww,abs(T1);title(AM低/高频调制后频谱);sound(t1,fs);t2=t1.*cos(0.6*pi*n);T2=fft(t2);figure;plot(t2);title(AM低/高频解调后波形);figure;plot(ww,abs(T2);title(AM低/高频解调后频谱);sound(t2,fs);N,wc=buttord(0.2,0
4、.3,2,15); b1,a=butter(N,wc);h,wi=freqz(b1,a);figure;plot(wi/pi,abs(h);title(iir滤波器频谱);%用iir对信号滤波y=filter(b1,a,t2);Y=fft(y);figure;plot(y);title(低/高频解调滤波后时域);figure;plot(ww,abs(Y);title(低/高频解调滤波后的频域);sound(y,fs);用窗函数法设计FIR滤波器(矩形窗和布莱克曼窗)w,fs,bit=wavread(2);w1=w(:,1);n=0:length(w1)-1;t1=w1.*cos(0.6*pi*
5、n); j1=t1.*cos(0.6*pi*n);%用FIR对信号同步解调N=55;wc=pi/4;% boxcar N取9hd=ideal(N,wc);w=blackman(N);%blackman和boxcarh=hd.*w;M=512;fh=fft(h,M);ww=2/M*(0:M-1);plot(ww,abs(fh);title(矩形窗fir滤波器频率响应);y=conv(j1,h);Y=fft(y,M);figureplot(y);title(矩形窗fir滤波后时域);figureplot(ww,abs(Y);title(矩形窗fir滤波后频域);sound(y,fs);三余弦和白噪
6、声的实验y,fs,bit=wavread(2);y1=y(:,1);f=fft(y1);l=length(f);ww=2/l*(0:l-1);n=0:length(y1)-1;x=0.05*(cos(2*pi*3000*n/fs)+cos(2*pi*5000*n/fs)+cos(2*pi*8000*n/fs);fx1=fft(x);plot(ww,abs(fx1);title(三余弦噪声频谱);r=rand(size(y1),1)-0.5;fx2=fft(r);figureplot(ww,abs(fx2);title(随机白噪声频谱);x1=y1+x;figureplot(x1);title(
7、加三余弦噪声的信号音谱);fx3=fft(x1);figureplot(ww,abs(fx3);title(加三余弦噪声的信号频谱);x2=y1+r;figureplot(x2);title(加白噪声的信号音谱);fx4=fft(x2);figureplot(ww,abs(fx4);title(加白噪声的信号频谱);sound(x1,fs);sound(x2,fs);三余弦噪声滤波y,fs,bit=wavread(2);y1=y(:,1);f=fft(y1);l=length(f);ww=2/l*(0:l-1);n=0:length(y1)-1;x=0.05*(cos(2*pi*3000*n/
8、fs)+cos(2*pi*5000*n/fs)+cos(2*pi*8000*n/fs);fx1=fft(x);plot(ww,abs(fx1);title(三余弦噪声频谱);x1=y1+x;figureplot(x1);title(加三余弦噪声的信号音谱);fx3=fft(x1);figureplot(ww,abs(fx3);title(加三余弦噪声的信号频谱);sound(x1,fs);N,wc=buttord(0.1,0.14,5,20);b1,a=butter(N,wc);R=filter(b1,a,x1);fr=fft(R);figureplot(R);title(滤波去噪后信号的音谱
9、);figureplot(ww,abs(fr);title(滤波去噪后信号频谱);sound(R,fs);随机白噪声滤波y,fs,bit=wavread(2);y1=y(:,1);f=fft(y1);l=length(f);ww=2/l*(0:l-1);n=0:length(y1)-1;r=rand(size(y1),1)-0.5;fx2=fft(r);figureplot(ww,abs(fx2);title(随机白噪声频谱);x2=y1+r;figureplot(x2);title(加白噪声的信号音谱);fx4=fft(x2);figureplot(ww,abs(fx4);title(加白噪
10、声的信号频谱);N,wc=buttord(0.06,0.1,2,20);b1,a=butter(N,wc);G=filter(b1,a,x2);fg1=fft(G);figureplot(G);title(滤波去噪后信号的音谱);figureplot(ww,abs(fg1);title(滤波去噪后信号频谱);sound(x2,fs);sound(G,fs);设计低通滤波器y,fs,bit=wavread(2);y1=y(:,1);fx1=fft(y1);l=length(fx1);ww=2/l*(0:l-1);figure;plot(ww,abs(fx1);title(原信号频谱);N,wc=
11、buttord(0.1,0.15,1,20); b1,a=butter(N,wc);h,wi=freqz(b1,a);figure;plot(wi/pi,abs(h);title(滤波器特性曲线);y=filter(b1,a,y1);fx2=fft(y);figure;plot(ww,abs(fx2);title(滤波后频谱);sound(y1,fs);sound(y,fs);设计高通滤波器y,fs,bit=wavread(1);y1=y(:,1);fx1=fft(y1);l=length(fx1);ww=2/l*(0:l-1);figure;plot(ww,abs(fx1);title(原信
12、号频谱);N,wc=buttord(0.15,0.2,1,20); b1,a=butter(N,wc,high);h,wi=freqz(b1,a,whole);figure;plot(wi/pi,abs(h);title(滤波器特性曲线);y2=filter(b1,a,y1);fx2=fft(y2);figure;plot(ww,abs(fx2);title(滤波后频谱);sound(y1,fs);sound(y2,fs);幅度谱和相位谱交叉组合x,fs,bit=wavread(1);x1=x(:,1);y,fs,bit=wavread(2);y1=y(:,1);N=10240;fx1=fft(x1,N);fy1=fft(y1,N);Ffx1=abs(fx1);Afx2=angle(fy1);F3=Ffx1.*exp(j*Afx2);x3=ifft(F3);sound(real(x3);26谷风书苑#