1.代码
% 指定要读取的.wav文件路径 filename = 'jay.wav'; % 使用audioread函数读取.wav文件 [sound_data, sample_rate] = audioread(filename); sound_data = sound_data(:, 1); % 计算音频数据的长度 sound_length = length(sound_data); % 计算FFT的点数 % fft_points = 2^nextpow2(sound_length); fft_points = sound_length; % 执行FFT变换 sound_fft = fft(sound_data, fft_points); % 结果是复数 %%%%%%%%%%%%%%画fft实部的%%%%%%%%%%%%% subplot(3, 1, 1); x1 = sample_rate*(0:(fft_points-1))/fft_points; y1 = sound_fft; plot(x1, y1); % 默认忽略虚部,有两个边带,且幅度有正有负 xlabel('Frequency (Hz)'); ylabel('Magnitude'); title('FFT Spectrum'); %%%%%%%%%%%%%%画fft的幅度值%%%%%%%%%%%%% subplot(3, 1, 2); x2 = sample_rate*(0:(fft_points-1))/fft_points; y2 = abs(sound_fft); plot(x2, y2); % 有两个边带,且幅度有正有负 xlabel('Frequency (Hz)'); ylabel('Magnitude'); title('FFT Spectrum'); %%%%%%%%%%%%%%画fft的幅度值, 只要半个边带%%%%%%%%%%%%% subplot(3, 1, 3); x3 = sample_rate*(0:(fft_points/2))/fft_points; y3 = abs(sound_fft(1:fft_points/2+1)); plot(x3, y3); % 有两个边带,且幅度有正有负 xlabel('Frequency (Hz)'); ylabel('Magnitude'); title('FFT Spectrum');
标签:sound,FFT,fft,points,Matlab,wav,data From: https://www.cnblogs.com/judes/p/17521717.html