i have a code for a .wav file which then outputs 3 graphs, but now i want to edit the code and apply three filters (LPF,HPF,BPF) how can i do that and also output the TF?

3 visualizaciones (últimos 30 días)
TF is the transfer function
LPF is low pass filter
HPF is high pass filter
BPF is band pass filter
this my code now:
[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)

Respuesta aceptada

Mathieu NOE
Mathieu NOE el 9 de Dic. de 2021
hello again
this is the code with the FIR filters implemented
hope it helps !
% LPF cutoff frequency 3 KHz
% BPF cutoff frequencies 2 and 5 KHz
% HPF cutoff frequency 4 KHz
% L/B/HPF FIR filter order 64 taps
[x, fs] = audioread('audio.wav');
x = x(:, 1);
n = length(x);
t = (0:n-1)/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')
colormap(jet);
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)
%% 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));
figure(4),plot(freq,m_lp,freq,m_bp,freq,m_hp);title('FIR Filters Response');
ylabel('Gain in dB');xlabel('Frequency (Hz)');
legend('LPF','BPF','HPF');
%% apply filters on audio file
x_lp = filter(B_lp,1,x); % filtered by LPF
figure(5)
spectrogram(x_lp, 1024, 512, 1024, fs, 'yaxis')
colormap(jet);
title('Spectrogram - LPF filtered signal')
x_bp = filter(B_bp,1,x); % filtered by BPF
figure(6)
spectrogram(x_bp, 1024, 512, 1024, fs, 'yaxis')
colormap(jet);
title('Spectrogram - LPF filtered signal')
x_hp = filter(B_hp,1,x); % filtered by HPF
figure(7)
spectrogram(x_hp, 1024, 512, 1024, fs, 'yaxis')
colormap(jet);
title('Spectrogram - LPF filtered signal')

Más respuestas (0)

Community Treasure Hunt

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

Start Hunting!

Translated by