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?
조회 수: 1 (최근 30일)
이전 댓글 표시
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)
댓글 수: 2
채택된 답변
Mathieu NOE
2021년 12월 9일
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')
댓글 수: 0
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Filter Design에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!