matlab声音信号高通滤波后显示频谱图
时间: 2023-06-24 17:04:17 浏览: 113
使用MATLAB进行声音信号高通滤波后显示频谱图的步骤如下:
1. 读取声音信号并播放:
```matlab
[x, Fs] = audioread('example.wav');
sound(x, Fs);
```
2. 设计高通滤波器:
```matlab
fc = 1000; % 截止频率
order = 4; % 滤波器阶数
[b, a] = butter(order, fc/(Fs/2), 'high');
```
3. 对声音信号进行高通滤波:
```matlab
y = filter(b, a, x);
```
4. 绘制原始信号和滤波后信号的时域波形图:
```matlab
t = (0:length(x)-1)/Fs;
subplot(2,1,1);
plot(t, x);
title('Original Signal');
xlabel('Time (s)');
ylabel('Amplitude');
subplot(2,1,2);
plot(t, y);
title('HPF Signal');
xlabel('Time (s)');
ylabel('Amplitude');
```
5. 绘制原始信号和滤波后信号的频谱图:
```matlab
N = length(x);
X = fft(x);
Y = fft(y);
f = (0:N-1)*(Fs/N);
subplot(2,1,1);
plot(f, abs(X));
title('Original Signal Spectrum');
xlabel('Frequency (Hz)');
ylabel('Magnitude');
xlim([0 Fs/2]);
subplot(2,1,2);
plot(f, abs(Y));
title('HPF Signal Spectrum');
xlabel('Frequency (Hz)');
ylabel('Magnitude');
xlim([0 Fs/2]);
```
完整的MATLAB代码如下:
```matlab
[x, Fs] = audioread('example.wav');
sound(x, Fs);
fc = 1000; % 截止频率
order = 4; % 滤波器阶数
[b, a] = butter(order, fc/(Fs/2), 'high');
y = filter(b, a, x);
t = (0:length(x)-1)/Fs;
subplot(2,1,1);
plot(t, x);
title('Original Signal');
xlabel('Time (s)');
ylabel('Amplitude');
subplot(2,1,2);
plot(t, y);
title('HPF Signal');
xlabel('Time (s)');
ylabel('Amplitude');
N = length(x);
X = fft(x);
Y = fft(y);
f = (0:N-1)*(Fs/N);
subplot(2,1,1);
plot(f, abs(X));
title('Original Signal Spectrum');
xlabel('Frequency (Hz)');
ylabel('Magnitude');
xlim([0 Fs/2]);
subplot(2,1,2);
plot(f, abs(Y));
title('HPF Signal Spectrum');
xlabel('Frequency (Hz)');
ylabel('Magnitude');
xlim([0 Fs/2]);
```
阅读全文