I want to edit this code to plot a time domain graph for the LPF, HPF, BPF filtered audio signal, how can I do it?

2 次查看(过去 30 天)
%Part 1 - (a, b, c)
[x, fs] = audioread('audio.wav')
x = x(:, 1);
n = length(x)
t = (0:n-1)/fs
n/fs
%Figure 1 - Time domain representation
figure(1)
plot(t, x)
grid on
xlabel('Time(s)')
ylabel('Amplitude')
title('Time domain ')
%Figure 2 - Spectrogram
figure(2)
spectrogram(x, 1024, 512, 1024, fs, 'yaxis')
title('Spectrogram')
%Figure 3 - Power spectrum density
figure(3)
w = hanning(n, 'periodic');
periodogram(x, w, n, fs, 'power')
title('power spectrum density')
%Play the audio
sound(x,fs)
%Part 2 - d
% define filters
freq = linspace(1000,(fs/2),500);
% 1 - LPF FIR / cutoff frequency 3 KHz
N = 64;
fc_lp = 3000;
B_lp = fir1(N,2*fc_lp/fs);
h=freqz(B_lp,1,freq,fs);
m_lp=20*log10(abs(h));
% 2 - BPF FIR / cutoff frequencies 2 and 5 KHz
N = 64;
fc_low = 2000;
fc_high = 5000;
B_bp = fir1(N,2*[fc_low fc_high]/fs);
h=freqz(B_bp,1,freq,fs);
m_bp=20*log10(abs(h));
% 3 - HPF FIR / cutoff frequency 4 KHz
N = 64;
fc_high = 4000;
B_hp = fir1(N,2*fc_high/fs,'high');
h=freqz(B_hp,1,freq,fs);
m_hp=20*log10(abs(h));
% apply filters on audio file
%LPF
x_lp = filter(B_lp,1,x); % filtered by LPF
figure(4)
figure(5)
spectrogram(x_lp, 1024, 512, 1024, fs, 'yaxis')
title('Spectrogram - LPF filtered signal')
figure(6)
w = hanning(n, 'periodic');
periodogram(x, w, n, fs, 'power')
title('LPF power spectrum density')
%BPF
x_bp = filter(B_bp,1,x); % filtered by BPF
figure(7)
figure(8)
spectrogram(x_bp, 1024, 512, 1024, fs, 'yaxis')
title('Spectrogram - BPF filtered signal')
figure(9)
x_hp = filter(B_hp,1,x); % filtered by HPF
figure(10)
figure(12)
  8 个评论
Walter Roberson
Walter Roberson 2021-12-11
You already have
figure(5)
spectrogram(x_lp, 1024, 512, 1024, fs, 'yaxis')
title('Spectrogram - LPF filtered signal')
so it is not obvious what else you are looking for?
If you want to plot just the signal, then do that,
plot(t, x_lp)
with appropriate titles and figure numbers and so on.

请先登录,再进行评论。

回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Simulation, Tuning, and Visualization 的更多信息

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by