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?

1 回表示 (過去 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 Center および File ExchangeSimulation, Tuning, and Visualization についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by