matlab生成两个音频的频谱图和语谱图对比代码
以下是一份使用MATLAB生成两个音频的频谱图和语谱图对比的代码示例:
% 读取第一个音频文件
[y1, fs1] = audioread('audio1.wav');
% 计算信号的时频分析
[s1, f1, t1] = spectrogram(y1, hann(256), 128, 1024, fs1);
% 绘制频谱图
figure(1)
imagesc(t1, f1, abs(s1).^2)
axis xy
colormap(jet)
colorbar
title('Spectrogram of Audio 1')
xlabel('Time (s)')
ylabel('Frequency (Hz)')
% 读取第二个音频文件
[y2, fs2] = audioread('audio2.wav');
% 计算信号的时频分析
[s2, f2, t2] = spectrogram(y2, hann(256), 128, 1024, fs2);
% 绘制频谱图
figure(2)
imagesc(t2, f2, abs(s2).^2)
axis xy
colormap(jet)
colorbar
title('Spectrogram of Audio 2')
xlabel('Time (s)')
ylabel('Frequency (Hz)')
% 绘制两个音频的语谱图对比
figure(3)
subplot(2,1,1)
spectrogram(y1, hann(256), 128, 1024, fs1, 'yaxis');
title('Spectrogram of Audio 1')
xlabel('Time (s)')
ylabel('Frequency (Hz)')
subplot(2,1,2)
spectrogram(y2, hann(256), 128, 1024, fs2, 'yaxis');
title('Spectrogram of Audio 2')
xlabel('Time (s)')
ylabel('Frequency (Hz)')
这份代码从两个音频文件中读取数据,分别计算它们的频谱图和语谱图,并将它们绘制在不同的图像窗口上。最后,它将两个音频的语谱图绘制在同一个图像窗口上进行对比。注意,这份代码中使用的窗口长度、窗口重叠和FFT大小等参数可能需要根据实际情况进行调整
原文地址: http://www.cveoy.top/t/topic/ewGD 著作权归作者所有。请勿转载和采集!