matlab 音频输入画出信号时域波形和SignalSpectrum,然后通过带通滤波器,画出滤波后的信号时域波形和SignalSpectrum
时间: 2024-03-23 21:42:00 浏览: 185
好的,以下是一些Matlab代码示例:
1. 读取音频文件并绘制时域波形
```matlab
% 读取音频文件
[y, Fs] = audioread('audio.wav');
% 绘制时域波形
t = (0:length(y)-1)/Fs;
figure;
plot(t, y);
xlabel('Time (s)');
ylabel('Amplitude');
title('Audio Signal in Time Domain');
```
2. 计算音频信号的频谱
```matlab
% 计算信号的功率谱密度
[P, f] = periodogram(y, [], [], Fs);
% 绘制频谱图
figure;
semilogx(f, 10*log10(P));
xlabel('Frequency (Hz)');
ylabel('Power Spectral Density (dB/Hz)');
title('Power Spectral Density of Audio Signal');
```
3. 设计带通滤波器并对信号进行滤波
```matlab
% 设计带通滤波器
fpass = [500 5000];
Wn = fpass/(Fs/2);
[b, a] = butter(4, Wn, 'bandpass');
% 对信号进行滤波
y_filtered = filter(b, a, y);
% 绘制滤波后的时域波形
figure;
plot(t, y_filtered);
xlabel('Time (s)');
ylabel('Amplitude');
title('Filtered Audio Signal in Time Domain');
% 绘制滤波后的频谱图
[P_filtered, f_filtered] = periodogram(y_filtered, [], [], Fs);
figure;
semilogx(f_filtered, 10*log10(P_filtered));
xlabel('Frequency (Hz)');
ylabel('Power Spectral Density (dB/Hz)');
title('Power Spectral Density of Filtered Audio Signal');
```
以上代码示例可以实现读取音频文件并绘制时域波形,计算音频信号的频谱,设计带通滤波器并对信号进行滤波,最后绘制滤波后的时域波形和频谱图。希望对你有所帮助。
阅读全文