Digital Signal Processing Filters
9 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Mustafa Kemal Tasci
el 25 de Dic. de 2022
Comentada: Mustafa Kemal Tasci
el 26 de Dic. de 2022
Hello, I am new to Matlab. I have problems could you help me with these ? I recorded my speech that said "Hello Friend" in a noisy environment. I want to design a filter that reduces noise and uses group delay to observe "Friend Hello" at the output. I designed an arbitrary filter to observe what is happening I have an issue also in the graph of frequency axises are wrong filter parameters and they are not match
Here are my codes:
clc
close all
clear
[y,Fs] = audioread("mySpeech.wav");
[N,P] = size(y);
ts = 1/Fs; % ts is the sampling period
tmax= (N-1)*ts; % tmax is the maxmimum period
t = 0:ts:tmax; % Defines a vector t that starts from 0 upto tmax increaments by the amount of sampling period
f = 0:pi/N:pi-pi/N; % For plotting the frequency spectrum
figure("Name","Time Domain Analysis")
subplot(2,1,1)
plot(t,y)
title("Unfiltered Signal in Time"); xlim([0, tmax]); xlabel("Time (sec)"); ylabel("Magnitude")
%%sound(y, Fs)
z = filter(Filter,y);
subplot(2,1,2)
plot(t,z)
title("Filtered Signal in Time"); xlim([0, tmax]); xlabel("Time (sec)"); ylabel("Magnitude")
sound(z, Fs)
Y = fftshift(fft(y));
figure("Name", "Frequency Domain Analysis")
subplot(2,1,1);
plot(f/pi,20*log10(abs(Y)))
title("Unfiltered Signal in Frequency"); xlabel("Frequency (Hz)"); ylabel("Magnitude (dB)")
Z = fftshift(fft(z))
subplot(2,1,2);
plot(f/pi,20*log10(abs(Z)))
title("Filtered Signal in Frequency"); xlabel("Frequency (Hz)"); ylabel("Magnitude (dB)")
fvtool(Filter)
freqz(Filter)
title("Magnitude Response")
subplot(2,1,2)
plot("""");
title("Phase Response")
function Hd = Filter
%FILTER Returns a discrete-time filter object.
% MATLAB Code
% Generated by MATLAB(R) 9.11 and Signal Processing Toolbox 8.7.
% Generated on: 25-Dec-2022 22:16:37
% Equiripple Bandpass filter designed using the FIRPM function.
% All frequency values are normalized to 1.
Fstop1 = 0.09; % First Stopband Frequency
Fpass1 = 0.12; % First Passband Frequency
Fpass2 = 0.25; % Second Passband Frequency
Fstop2 = 0.3; % Second Stopband Frequency
Dstop1 = 0.001; % First Stopband Attenuation
Dpass = 0.057501127785; % Passband Ripple
Dstop2 = 0.0001; % Second Stopband Attenuation
dens = 20; % Density Factor
% Calculate the order from the parameters using FIRPMORD.
[N, Fo, Ao, W] = firpmord([Fstop1 Fpass1 Fpass2 Fstop2], [0 1 0], ...
[Dstop1 Dpass Dstop2]);
% Calculate the coefficients using the FIRPM function.
b = firpm(N, Fo, Ao, W, {dens});
Hd = dfilt.dffir(b);
% [EOF]
end
0 comentarios
Respuestas (1)
Paul
el 25 de Dic. de 2022
Editada: Paul
el 25 de Dic. de 2022
Hi Mustafa,
Not checking all of the code in detail, but I did notice that the fft plots don't look correct. They should be:
f = ceil(linspace(-N/2,N/2-1,N))/N*Fs; % Hz
Y = fftshift(fft(y));
figure("Name", "Frequency Domain Analysis")
subplot(2,1,1);
%plot(f/pi,20*log10(abs(Y)))
plot(f,20*log10(abs(Y)))
title("Unfiltered Signal in Frequency"); xlabel("Frequency (Hz)"); ylabel("Magnitude (dB)")
Z = fftshift(fft(z))
subplot(2,1,2);
%plot(f/pi,20*log10(abs(Z)))
plot(f,20*log10(abs(Z)))
title("Filtered Signal in Frequency"); xlabel("Frequency (Hz)"); ylabel("Magnitude (dB)")
Also, can this statement be clarified: "uses group delay to observe "Friend Hello" at the output." I'm not sure how group delay relates to swapping two portions of the signal.
1 comentario
Ver también
Categorías
Más información sobre Digital Filter Design en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!