Skip to content
Snippets Groups Projects
Commit ab9b46bd authored by YE Victor's avatar YE Victor
Browse files

Upload New File

parent 95e680b6
No related branches found
No related tags found
No related merge requests found
%QUESTION 1.2
% Lire les deux fichiers audio
f1 = fullfile('wav', 'single_tone_piano1.wav')
f2 = fullfile('wav', 'single_tone_piano2.wav')
[y1, Fs1] = audioread(f1);
[y2, Fs2] = audioread(f2);
if size(y1,2) == 2
y1 = mean(y1,2);
end
if size(y2,2) == 2
y2 = mean(y2,2);
end
% Uniformiser la durée à 1 seconde max
N = min([length(y1), length(y2), Fs1]);
y1 = y1(1:N);
y2 = y2(1:N);
% Pour obtenir un graphe avec moins d'artefacts de fréquence
window = hann(N);
y1 = y1 .* window;
y2 = y2 .* window;
% FFT
Y1 = fft(y1);
Y2 = fft(y2);
% Spectres positifs
f = (0:N/2-1)*(Fs1/N);
mag1 = abs(Y1(1:N/2));
mag2 = abs(Y2(1:N/2));
% Normalisation
mag1 = mag1 / max(mag1);
mag2 = mag2 / max(mag2);
% Figure 1 pour piano1.wav
figure;
semilogx(f, mag1, 'b', 'LineWidth', 1.5);
grid on;
xlabel('Fréquence (Hz)');
ylabel('Amplitude (linéaire)');
title('Spectre de single_tone_piano1.wav');
xlim([20 Fs1/2]);
datacursormode on;
% Figure 2 pour piano2.wav
figure;
semilogx(f, mag2, 'r', 'LineWidth', 1.5);
grid on;
xlabel('Fréquence (Hz)');
ylabel('Amplitude (linéaire)');
title('Spectre de single_tone_piano2.wav');
xlim([20 Fs1/2]);
datacursormode on;
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment