plot_freq.m
clear;clc;
maindir = 'D:/EDUCATION/datasets/';
subdir='XXX/';
subdirpath = fullfile( maindir, subdir, '*.wav' );
dat = dir( subdirpath ); % 子文件夹下找后缀为wav的文件
for i = 1 : 1 : 12
datapath=dat( i+25 ).name;
name=datapath(22:end); % wav文件名较长,截取部分文件名作为图片标题
filename = fullfile( maindir, subdir, datapath);
info = audioinfo(filename); % 提取信号附加信息,如采样率、信号时长等
[y,Fs] = audioread(filename);
y=y(60*Fs+1:61*Fs); % 随便取1s数据分析
y = y-mean(y);
y_fft=abs(fft(y));
subplot(3,4,i);
plot(y_fft);
ylim([0 120])
xlim([0 length(y_fft)/2])
title(name)
end