用for循环修改此代码[x,fs]=audioread('C:\Users\ASUS\Desktop\data信号课设\01-DTMF\1.wav'); t = linspace(0, length(x)/fs, length(x)); subplot(6,2,1); plot(t,x); title('时域图'); subplot(6,2,2); plot(x(1:800)); title('第一个分隔图'); %第1个数字 y=x(1:800); Y=fft(y); subplot(6,2,3); plot(abs(Y)); soundsc(y,fs); w=(0:length(y)-1)'*fs/length(y); plot(w,abs(Y)); title('第一个数字'); %第2个数字 y=x(1600:2400); Y=fft(y); subplot(6,2,4); plot(abs(Y)); soundsc(y,fs); w=(0:length(y)-1)'*fs/length(y); plot(w,abs(Y)); title('第二个数字'); %第3个数字 y=x(3200:4000); Y=fft(y); subplot(6,2,5); plot(abs(Y)); soundsc(y,fs); w=(0:length(y)-1)'*fs/length(y); plot(w,abs(Y)); title('第三个数字'); %第4个数字 y=x(4800:5600); Y=fft(y); subplot(6,2,6); plot(abs(Y)); soundsc(y,fs); w=(0:length(y)-1)'*fs/length(y); plot(w,abs(Y)); title('第四个数字'); %第5个数字 y=x(6400:7200); Y=fft(y); subplot(6,2,7); plot(abs(Y)); soundsc(y,fs); w=(0:length(y)-1)'*fs/length(y); plot(w,abs(Y)); title('第五个数字'); %第6个数字 y=x(8000:8800); Y=fft(y); subplot(6,2,8); plot(abs(Y)); soundsc(y,fs); w=(0:length(y)-1)'*fs/length(y); plot(w,abs(Y)); title('第六个数字'); %第7个数字 y=x(9600:10400); Y=fft(y); subplot(6,2,9); plot(abs(Y)); soundsc(y,fs); w=(0:length(y)-1)'*fs/length(y); plot(w,abs(Y)); title('第七个数字'); %第8个数字 y=x(11200:12000); Y=fft(y); subplot(6,2,10); plot(abs(Y)); soundsc(y,fs); w=(0:length(y)-1)'*fs/length(y); plot(w,abs(Y)); title('第八个数字'); %第9个数字 y=x(12800:13600); Y=fft(y); subplot(6,2,11); plot(abs(Y)); soundsc(y,fs); w=(0:length(y)-1)'*fs/length(y); plot(w,abs(Y)); title('第九个数字'); %第10个数字 y=x(14400:15200); Y=fft(y); subplot(6,2,12); plot(abs(Y)); soundsc(y,fs); w=(0:length(y)-1)'*fs/length(y); plot(w,abs(Y)); title('第十个数字');
时间: 2023-11-18 11:04:51 浏览: 83
可以使用一个for循环来简化代码,如下所示:
[x,fs]=audioread('C:\Users\ASUS\Desktop\data信号课设\01-DTMF\1.wav');
t = linspace(0, length(x)/fs, length(x));
figure; %创建新的图形窗口
for i = 1:10 % 循环10次,每次处理一个数字
y = x((i-1)*800+1:i*800); % 从x中取出当前数字的数据
Y = fft(y); % 进行FFT变换
subplot(5,2,i); % 将图像排列在5行2列的网格中的第i个位置
plot(abs(Y)); % 绘制幅度谱
soundsc(y,fs); % 播放音频
w = (0:length(y)-1)'*fs/length(y); % 计算频率坐标
plot(w,abs(Y)); % 绘制幅度谱和频率坐标
title(['第',num2str(i),'个数字']); % 设置子图标题
end
subplot(5,2,1); title('时域图'); % 设置第一个子图的标题
阅读全文