I have two xxx.wav input files recorded for 30 seconds in noise lab at different conditions with fs 44,100 need to plot normalized frequency Vs dB in one plot

5 visualizaciones (últimos 30 días)
I have two .wav input files recorded for 30 seconds with fs 44,100 each . I want a matlab code for frequency analysis plot in one panel to compare two wav file inputs

Respuesta aceptada

Walter Roberson
Walter Roberson el 4 de Sept. de 2021
Read the files. Isolate a single channel on each. If they are different frequencies, resample to a common frequency. If one is shorter than the other, truncate the longer. Subtract the mean of each signal from the signal.
Now fft each signal. plot() the real() or imag() or abs() of the first result. Use "hold on" . plot() the real() or imag() or abs() of the second result. Label the plot.
  9 comentarios
Walter Roberson
Walter Roberson el 5 de Sept. de 2021
[sig1, Fs] = audioread('s.wav');
[sig2, Fs2] = audioread('u.wav');
assert(Fs == Fs2); %sample rate must be same
assert(size(sig1,2) == 1 && size(sig2,2) == 1); %single channel only supported
minlen = min(length(sig1), length(sig2));
sig1 = sig1(1:minlen);
sig2 = sig2(1:minlen);
sig1 = sig1 - mean(sig1);
sig2 = sig2 - mean(sig2);
ff1 = fftshift(fft(sig1));
ff2 = fftshift(fft(sig2));
db1 = mag2db(ff1);
db2 = mag2db(ff2);
x = linspace(-Fs/2, Fs/2, length(db1));
bnd = 1000*floor(Fs/2000);
plot(x, real(db1), 'displayname', 's');
hold on
plot(x, real(db2), 'displayname', 'u');
hold off
xticks(-bnd:1000:bnd);
xlabel('Hz'); ylabel('dB')
legend show
Nega Ejjigu
Nega Ejjigu el 5 de Sept. de 2021
Thanks!I reallized that typo error (o missed).
now I got the below error :
Error using secondcode (line 4)
Assertion failed.

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Vibration Analysis en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by