I am designing a notch filter that removes unwanted frequencies at 60, 120 and 180 Hz for a VoIP call sampled at 180000 kHz. Here is my filter implemented in Scilab.
and the floating-point coefficients I obtained.
For testing, I want to generate a simple multitone test noise and visualize it with an FFT. Since I am still a student, I would like to know what characteristics the multitone noise should have to realistically simulate a VoIP call, and which practical aspects I should consider when generating that test noise.
Code:
clc; clear; close;
fs = 16000;
F = [60, 120, 180];
BW = 3;
Nsec = length(F);
bmat = zeros(Nsec,3);
amat = zeros(Nsec,3);
rvec = zeros(1,Nsec);
w0vec = zeros(1,Nsec);
for k = 1:Nsec
f0 = F(k);
w0 = 2*%pi*f0/fs;
r = exp(-%pi * BW / fs);
b = [1, -2*cos(w0), 1];
a = [1, -2*r*cos(w0), r^2];
bmat(k,:) = b;
amat(k,:) = a;
rvec(k) = r;
w0vec(k) = w0;
end
mprintf("Frecuencias: %s Hz\n\n", string(F));
for k = 1:Nsec
mprintf("Seccion %d: f0=%3d Hz\n", k, F(k));
mprintf(" b (float) = [ %.10f, %.10f, %.10f ]\n", bmat(k,1), bmat(k,2), bmat(k,3));
mprintf(" a (float) = [ %.10f, %.10f, %.10f ]\n\n", amat(k,1), amat(k,2), amat(k,3));
end
z = %z;
Hz_all = 1;
for k = 1:Nsec
w0 = w0vec(k);
z1 = exp(%i*w0);
z2 = exp(-%i*w0);
p1 = rvec(k)*exp(%i*w0);
p2 = rvec(k)*exp(-%i*w0);
num1 = real((z - z1)*(z - z2));
den1 = real((z - p1)*(z - p2));
Hk = num1 ./ den1;
Hz_all = Hz_all .* Hk;
end
[h1, fr] = frmag(Hz_all, 2048);
freqHz = fr * fs;
magdB = 20*log10(h1);
figure;
plot2d(freqHz, magdB);
xtitle("Magnitude response (all notches cascaded)", "Frequency (Hz)", "Magnitude (dB)");
xgrid();
figure;
for k = 1:Nsec
w0 = w0vec(k);
z1 = exp(%i*w0);
z2 = exp(-%i*w0);
p1 = rvec(k)*exp(%i*w0);
p2 = rvec(k)*exp(-%i*w0);
Hk = real((z - z1).*(z - z2)) ./ real((z - p1).*(z - p2));
[hk, frk] = frmag(Hk, 1024);
subplot(Nsec,1,k);
plot2d(frk*fs, 20*log10(hk));
xtitle("Seccion "+string(k)+" Magnitude (dB)", "Freq (Hz)", "dB");
xgrid();
end
Code:
Frecuencies: 60 Hz
Section 1: f0= 60 Hz
b (float) = [ 1.0000000000, -1.9994448604, 1.0000000000 ]
a (float) = [ 1.0000000000, -1.9982674370, 0.9988225964 ]
Section 2: f0=120 Hz
b (float) = [ 1.0000000000, -1.9977797499, 1.0000000000 ]
a (float) = [ 1.0000000000, -1.9966033070, 0.9988225964 ]
Section 3: f0=180 Hz
b (float) = [ 1.0000000000, -1.9950055928, 1.0000000000 ]
a (float) = [ 1.0000000000, -1.9938307836, 0.9988225964 ]
For testing, I want to generate a simple multitone test noise and visualize it with an FFT. Since I am still a student, I would like to know what characteristics the multitone noise should have to realistically simulate a VoIP call, and which practical aspects I should consider when generating that test noise.