修改这段代码[x,fs]=audioread('E:/MATLAB/R2017a/bin/1.wav'); %第1个数字 %subplot(5,1,1); %plot(x(1:8000)); y=x(1:800); Y=fft(y); subplot(5,2,1); plot(abs(Y)); soundsc(y,fs); w=(0:length(y)-1)'*fs/length(y); plot(w,abs(Y)); %第2个数字 y=x(1600:2400); Y=fft(y); subplot(5,2,2); plot(abs(Y)); soundsc(y,fs); w=(0:length(y)-1)'*fs/length(y); plot(w,abs(Y)); %第3个数字 y=x(3200:4200); Y=fft(y); subplot(5,2,3); plot(abs(Y)); soundsc(y,fs); w=(0:length(y)-1)'*fs/length(y); plot(w,abs(Y)); %第4个数字 y=x(4800:5600); Y=fft(y); subplot(5,2,4); plot(abs(Y)); soundsc(y,fs); w=(0:length(y)-1)'*fs/length(y); plot(w,abs(Y)); %第5个数字 y=x(6500:7400); Y=fft(y); subplot(5,2,5); plot(abs(Y)); soundsc(y,fs); w=(0:length(y)-1)'*fs/length(y); plot(w,abs(Y)); %第6个数字 y=x(8134:8959); Y=fft(y); subplot(5,2,6); plot(abs(Y)); soundsc(y,fs); w=(0:length(y)-1)'*fs/length(y); plot(w,abs(Y)); %第7个数字 y=x(9768:10610); Y=fft(y); subplot(5,2,7); plot(abs(Y)); soundsc(y,fs); w=(0:length(y)-1)'*fs/length(y); plot(w,abs(Y)); %第8个数字 y=x(11380:12210); Y=fft(y); subplot(5,2,8); plot(abs(Y)); soundsc(y,fs); w=(0:length(y)-1)'*fs/length(y); plot(w,abs(Y)); %第9个数字 y=x(13020:13840); Y=fft(y); subplot(5,2,9); plot(abs(Y)); soundsc(y,fs); w=(0:length(y)-1)'*fs/length(y); plot(w,abs(Y)); %第10个数字 y=x(14650:15480); Y=fft(y); subplot(5,2,10); plot(abs(Y)); soundsc(y,fs); w=(0:length(y)-1)'*fs/length(y); plot(w,abs(Y)); 以读取和分析不同的音频文件
时间: 2023-08-12 21:07:22 浏览: 39
你可以将代码中的第一行修改为指定不同的音频文件路径:
```
[x,fs]=audioread('E:/MATLAB/R2017a/bin/1.wav'); %第1个数字
```
改为:
```
[x,fs]=audioread('E:/MATLAB/R2017a/bin/2.wav'); %第2个数字
```
以此类推,每次修改对应的数字和文件路径即可读取和分析不同的音频文件。
相关问题
When I use updated Matlab2017b, I met:Can't load '/usr/local/MATLAB/R2017b/bin/glnxa64/libmwdastudio.so': /lib/x86_64-linux-gnu/libfontconfig.so.1: undefined symbol: FT_Done_MM_Var. How to solve the problem
The error message you encountered, "Can't load '/usr/local/MATLAB/R2017b/bin/glnxa64/libmwdastudio.so': /lib/x86_64-linux-gnu/libfontconfig.so.1: undefined symbol: FT_Done_MM_Var," suggests a problem with the fontconfig library used by MATLAB.
To solve this issue, you can try the following steps:
1. Update fontconfig library: First, try updating the fontconfig library on your system. You can do this by running the following command in your terminal:
```
sudo apt-get update
sudo apt-get install libfontconfig1
```
This will update the fontconfig library to the latest version available in your Linux distribution's package manager.
2. Check library paths: Ensure that the library path for fontconfig is correctly set in MATLAB. You can do this by running the following command in MATLAB's command window:
```
getenv LD_LIBRARY_PATH
```
Make sure the output includes the correct path to the fontconfig library (e.g., `/usr/lib/x86_64-linux-gnu`).
3. Verify system compatibility: Verify that your system is compatible with MATLAB 2017b. Ensure that you are using a supported version of Linux and that all system requirements for MATLAB are met.
4. Reinstall MATLAB: If the above steps do not resolve the issue, you may need to reinstall MATLAB. Uninstall MATLAB completely and then reinstall it, making sure to follow all installation instructions and prompts carefully.
If the problem persists after trying these steps, it might be helpful to contact MathWorks support for further assistance, as they can provide more specific guidance tailored to your system and setup.
这段代码[x,fs]=audioread('E:/MATLAB/R2017a/bin/1.wav'); %第1个数字 %subplot(5,1,1); %plot(x(1:8000)); y=x(1:800); Y=fft(y); subplot(5,2,1); plot(abs(Y)); soundsc(y,fs); w=(0:length(y)-1)'*fs/length(y); plot(w,abs(Y)); %第2个数字 y=x(1600:2400); Y=fft(y); subplot(5,2,2); plot(abs(Y)); soundsc(y,fs); w=(0:length(y)-1)'*fs/length(y); plot(w,abs(Y)); %第3个数字 y=x(3200:4200); Y=fft(y); subplot(5,2,3); plot(abs(Y)); soundsc(y,fs); w=(0:length(y)-1)'*fs/length(y); plot(w,abs(Y)); %第4个数字 y=x(4800:5600); Y=fft(y); subplot(5,2,4); plot(abs(Y)); soundsc(y,fs); w=(0:length(y)-1)'*fs/length(y); plot(w,abs(Y)); %第5个数字 y=x(6500:7400); Y=fft(y); subplot(5,2,5); plot(abs(Y)); soundsc(y,fs); w=(0:length(y)-1)'*fs/length(y); plot(w,abs(Y)); %第6个数字 y=x(8134:8959); Y=fft(y); subplot(5,2,6); plot(abs(Y)); soundsc(y,fs); w=(0:length(y)-1)'*fs/length(y); plot(w,abs(Y)); %第7个数字 y=x(9768:10610); Y=fft(y); subplot(5,2,7); plot(abs(Y)); soundsc(y,fs); w=(0:length(y)-1)'*fs/length(y); plot(w,abs(Y)); %第8个数字 y=x(11380:12210); Y=fft(y); subplot(5,2,8); plot(abs(Y)); soundsc(y,fs); w=(0:length(y)-1)'*fs/length(y); plot(w,abs(Y)); %第9个数字 y=x(13020:13840); Y=fft(y); subplot(5,2,9); plot(abs(Y)); soundsc(y,fs); w=(0:length(y)-1)'*fs/length(y); plot(w,abs(Y)); %第10个数字 y=x(14650:15480); Y=fft(y); subplot(5,2,10); plot(abs(Y)); soundsc(y,fs); w=(0:length(y)-1)'*fs/length(y); plot(w,abs(Y));不管导入什么文件生成的图像都一样
这段代码是用 MATLAB 对音频文件进行读取、FFT 变换和绘图。其中,audioread 函数用于读取音频文件,fft 函数用于进行 FFT 变换,subplot 函数用于绘制子图,plot 函数用于绘制图像,soundsc 函数用于播放音频文件。这段代码通过截取音频文件中的不同片段,对每个片段进行 FFT 变换并绘制其频谱图。由于每个片段长度相同,因此绘制的图像相同,不会因为导入不同的文件而有所变化。