Bandpass, lowpass and highpass filtering

조회 수: 18 (최근 30일)
Mercede Erfanian
Mercede Erfanian 2020년 12월 16일
댓글: Mercede Erfanian 2020년 12월 17일
Hello,
I wrote the code below to plot .wav/.mp3 files in both time and frequnency domains then filter each selected sound and plot again (bandpass filtering). The first part of the code works fine. Then the filter designer GUI pops up and I export the filter in Hd and run the rest of the code. The output (.wav or .mp3 and the last plot) seem to be the issue. Can you please help? I can not pinpoint what I did wrong.
%% Filtering
% clear all; clc;close all;
[signal,Fs] = audioread('Rooster_un3 copy.mp3');
%% Check channels and convert to mono
if size(signal,2)==2
y= mean(signal,2);
else
y=signal;
end
Nsamps = length(y);
t = (1/Fs)*(1:Nsamps);
soundsc(signal,Fs)
%% Time_domain plotting
subplot(3,1,1)
plot(t, y)
xlim ([0,5])
xlabel('Time (s)')
ylabel('Amplitude')
title ('Signal in Time-domain')
%% Fast Fourier Transform
yFT = fft(y);
%% Prepare plot FT
y_fft = abs(yFT); %Retain Magnitude
y_fft = y_fft(1:floor(Nsamps/2)); %Discard Half of Points
f = Fs*(0:Nsamps/2-1)/Nsamps; %Prepare freq data for plot
%% Frequency_domain plotting
subplot (3,1,2)
plot(f, y_fft)
xlim([0 20000])
xlabel('Frequency [Hz]');
ylabel('Magnitude');
title ('Signal in Frequency-domain')
%% Filtering
% filterDesigner
%% Generating bandpass filter and plotting
FilteredSignal = filter (Hd,y_fft);
FilteredSignalTransform =ifft (FilteredSignal);
subplot (3,1,3)
plot (abs(FilteredSignalTransform(:,1)));
xlim([0 20000])
xlabel('Frequency [Hz]');
ylabel('Magnitude');
title ('Filtered Signal in frquency_domain');
sound (FilteredSignal,Fs)
audiowrite('Filtered.wav',FilteredSignal,Fs)
PLEASE note that to run this code completely you need to design a filter.
Thank you,
  댓글 수: 1
Jan
Jan 2020년 12월 16일
What does "The output seem to be the issue" exactly mean? What do you get and what do you expect instead?

댓글을 달려면 로그인하십시오.

채택된 답변

Mercede Erfanian
Mercede Erfanian 2020년 12월 16일
I have attached the final plot as well as the output sound.
1- It seems the output file is shorter than the input file.
2- The output file is not correctly filtered (attached). I used lowpass filter with frequency pass (3kHz) and frequency stop (3010Hz). Design method FIR (equiripple).
I hope this is clear,
  댓글 수: 1
Suresh Maddina
Suresh Maddina 2020년 12월 17일
편집: Suresh Maddina 2020년 12월 17일
It seems there is a mistake in your code
FilteredSignal = filter (Hd,y_fft);
Should be corrected as,
FilteredSignal = filter (Hd,y); % Apply filter to original noise signal and not the FFT output
It gives correct output for "handel.mat" audio file. Attached the outputs and the code setup. The output file length is same as input file length. Please take a look into this

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Suresh Maddina
Suresh Maddina 2020년 12월 16일
편집: Suresh Maddina 2020년 12월 16일
Hi, it is my understanding that you are using filterDesigner to remove high frequency noise from the audio file. However, you are unable to obtain correct output using the filter Hd obtained from the filterDesigner
In your code it seems you are applying the filter Hd to the fft output (y_fft) instead of the original audio signal (y).
Applying the filter to audio signal y as shown below would produce the output that you are looking for:
%% Filtering
% filterDesigner
%% Generating bandpass filter and plotting
FilteredSignal = filter (Hd,y); % in your code this was FilteredSignal=filter(Hd,y_fft) which is incorrect
Some references you may look at:

카테고리

Help CenterFile Exchange에서 Digital and Analog Filters에 대해 자세히 알아보기

제품


릴리스

R2018b

Community Treasure Hunt

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

Start Hunting!

Translated by