Skip to content
Snippets Groups Projects
Commit d818de15 authored by LERAYS Camille's avatar LERAYS Camille
Browse files

coucou

parent 215c82fb
No related branches found
No related tags found
No related merge requests found
File added
......@@ -6,9 +6,9 @@
[x,fe]=audioread("C:\Users\camil\Documents\IMT_A\semestre_6\electrical engineering\tp-audio-ee-etudiant-c24leray\src\wav\single_tone_celtic-harp-a3.wav");
soundsc(x,fe);
L1 = length(x1)
X1 = fftshift(fft(x1))
f1 = (-L1/2 : L1/2 - 1)*(fe1/L1)
L1 = length(x1);
X1 = fftshift(fft(x1));
f1 = (-L1/2 : L1/2 - 1)*(fe1/L1);
figure;
plot(f1, log(abs(X1)),'r');
......@@ -25,28 +25,28 @@ ylabel("log|X(f)|")
soundsc(x1,fe1);
soundsc(x2,fe2);
L1 = length(x1)
L2 = length(x2)
L1 = length(x1);
L2 = length(x2);
X1 = fftshift(fft(x1))
X2 = fftshift(fft(x2))
X1 = fftshift(fft(x1));
X2 = fftshift(fft(x2));
f1 = (-L1/2 : L1/2 - 1)*(fe1/L1)
f2 = (-L2/2 : L2/2 - 1)*(fe2/L2)
f1 = (-L1/2 : L1/2 - 1)*(fe1/L1);
f2 = (-L2/2 : L2/2 - 1)*(fe2/L2);
figure;
plot(f1, log(abs(X1)),'r');
hold on;
plot(f2, log(abs(X2)),'b')
title("spectre")
xlabel("fréquence en Hz")
ylabel("log|X(f)|")
plot(f2, log(abs(X2)),'b');
title("spectre");
xlabel("fréquence en Hz");
ylabel("10*log|X(f)|");
% Question 3 :
freq_r=[220;442;663;885;1108;1331;1556;1782;2009];
amplitude = [];
% Durée et fréquence d'échantillonnage
Fe = 44100; % fréquence d'échantillonnage (standard audio)
......@@ -58,7 +58,7 @@ s = zeros(size(t));
% Ajouter les sinusoïdes
for k = 1:length(freq_r)
s = s + sin(2*pi*freq_r(k)*t);
s = s + amplitude * sin(2*pi*freq_r(k)*t);
end
% Normaliser pour éviter la saturation (valeurs entre -1 et 1)
......@@ -71,21 +71,49 @@ soundsc(s, Fe);
% Question 4 :
function s = signal(t, freq_r)
s = zeros(size(t));
for k = 1:length(freq_r)
s = s + sin(2*pi*freq_r(k)*t);
end
end
% Define ADSR parameters
A = 0.1; % Attack time (seconds)
D = 0.005; % Decay time (seconds)
S = 0.8; % Sustain level (0 to 1)
R = 0.75; % Release time (seconds)
fs = 44100; % Sampling frequency (Hz)
% Total duration of the envelope
totalTime = A + D + R;
% totalTime = totalTime * 6; % Extend the envelope for 6 seconds
t = linspace(0, totalTime, totalTime * fs);
% Generate ADSR envelope
attack = linspace(0, 1, A * fs);
decay = linspace(1, S, D * fs);
release = linspace(S, 0, R * fs);
% Combine all segments
adsrEnvelope = [attack, decay, release];
% Plot the envelope
figure;
plot(t, signal(t, freq_r))
plot(t, adsrEnvelope);
xlabel('Time (s)');
ylabel('Amplitude');
title('ADSR Envelope');
[xA, feA] = audioread("C:\Users\camil\Documents\IMT_A\semestre_6\electrical engineering\tp-audio-ee-etudiant-c24leray\src\wav\single_tone_piano2.wav");
% Apply the ADSR envelope to the audio signal
adsrSignal = xA(1:length(adsrEnvelope)) .* adsrEnvelope';
sound(adsrSignal, feA);
t = [0.1 0.3 0.5 0.7 1]; % Temps en secondes
env = [signal(0.1) signal(0.3) signal(0.5) signal(0.7) signal(1)]; % Valeurs d'amplitude correspondantes
audiowrite("C:\Users\camil\Documents\IMT_A\semestre_6\electrical engineering\tp-audio-ee-etudiant-c24leray\src\wav\single_tone_piano2.wav", adsrSignal, fe);
t_total = length(s)/Fe; % Durée totale du signal en secondes
t_interpolated = linspace(0, t_total, length(s)); % Temps interpolé
env_interpolated = interp1(t, env, t_interpolated); % Enveloppe interpolée
s_envelope = s .* env_interpolated; % Signal avec enveloppe ADSR
\ No newline at end of file
% Question 5 :
\ No newline at end of file
% Question 1 :
[x,fe]=audioread("C:\Users\camil\Documents\IMT_A\semestre_6\electrical engineering\tp-audio-ee-etudiant-c24leray\src\wav\single_tone_celtic-harp-a3.wav");
soundsc(x,fe);
L1 = length(x1);
X1 = fftshift(fft(x1));
f1 = (-L1/2 : L1/2 - 1)*(fe1/L1);
figure;
plot(f1, log(abs(X1)),'r');
title("spectre")
xlabel("fréquence en Hz")
ylabel("log|X(f)|")
\ No newline at end of file
% Question 2 :
[x1,fe1]=audioread("C:\Users\camil\Documents\IMT_A\semestre_6\electrical engineering\tp-audio-ee-etudiant-c24leray\src\wav\single_tone_piano1.wav");
[x2,fe2]=audioread("C:\Users\camil\Documents\IMT_A\semestre_6\electrical engineering\tp-audio-ee-etudiant-c24leray\src\wav\single_tone_piano2.wav");
soundsc(x1,fe1);
soundsc(x2,fe2);
L1 = length(x1);
L2 = length(x2);
X1 = fftshift(fft(x1));
X2 = fftshift(fft(x2));
f1 = (-L1/2 : L1/2 - 1)*(fe1/L1);
f2 = (-L2/2 : L2/2 - 1)*(fe2/L2);
figure;
plot(f1, log(abs(X1)),'r');
hold on;
plot(f2, log(abs(X2)),'b');
title("spectre");
xlabel("fréquence en Hz");
ylabel("10*log|X(f)|");
\ No newline at end of file
% Question 3 :
freq_r=[220;442;663;885;1108;1331;1556;1782;2009];
amplitude = [8.89;8.62;6.89;7.25;6.22;6.51;6.35;4.74;5.85];
Amplitude = [7259; 5541; 982; 1408; ]
% Durée et fréquence d'échantillonnage
Fe = 44100; % fréquence d'échantillonnage (standard audio)
duree = 1; % durée du signal en secondes
t = 0:1/Fe:duree; % vecteur temps
% Initialiser le signal composite
s = zeros(size(t));
% Ajouter les sinusoïdes
for k = 1:length(freq_r)
s = s + amplitude(k) * sin(2*pi*freq_r(k)*t);
end
% Normaliser pour éviter la saturation (valeurs entre -1 et 1)
s = s / max(abs(s));
% Jouer le son
soundsc(s, Fe);
figure;
plot(t,s)
\ No newline at end of file
% Question 3 :
freq_r=[220;442;663;885;1108;1331;1556;1782;2009];
Amplitude = [7259; 5541; 982; 1408; 502; 672; 573; 114; 347];
% Durée et fréquence d'échantillonnage
Fe = 44100; % fréquence d'échantillonnage (standard audio)
duree = 1; % durée du signal en secondes
t = 0:1/Fe:duree; % vecteur temps
% Initialiser le signal composite
s = zeros(size(t));
% Ajouter les sinusoïdes
for k = 1:length(freq_r)
s = s + Amplitude(k) * sin(2*pi*freq_r(k)*t);
end
% Normaliser pour éviter la saturation (valeurs entre -1 et 1)
s = s / max(abs(s));
% Jouer le son
soundsc(s, Fe);
figure;
plot(t,s)
\ No newline at end of file
% Question 4
% Define ADSR parameters
A = 0.1; % Attack time (seconds)
D = 0.005; % Decay time (seconds)
S = 0.8; % Sustain level (0 to 1)
R = 0.75; % Release time (seconds)
fs = 44100; % Sampling frequency (Hz)
% Total duration of the envelope
totalTime = A + D + R;
% totalTime = totalTime * 6; % Extend the envelope for 6 seconds
t = linspace(0, totalTime, totalTime * fs);
% Generate ADSR envelope
attack = linspace(0, 1, A * fs);
decay = linspace(1, S, D * fs);
release = linspace(S, 0, R * fs);
% Combine all segments
adsrEnvelope = [attack, decay, release];
% Plot the envelope
plot(t, adsrEnvelope);
xlabel('Time (s)');
ylabel('Amplitude');
title('ADSR Envelope');
[x, fe] = audioread("C:\Users\camil\Documents\IMT_A\semestre_6\electrical engineering\tp-audio-ee-etudiant-c24leray\src\wav\single_tone_piano2.wav");
% Apply the ADSR envelope to the audio signal
adsrSignal = x(1:length(adsrEnvelope)) .* adsrEnvelope';
sound(adsrSignal, fe);
audiowrite("C:\Users\camil\Documents\IMT_A\semestre_6\electrical engineering\tp-audio-ee-etudiant-c24leray\src\wav\single_tone_piano2.wav", adsrSignal, fe);
\ No newline at end of file
No preview for this file type
[xA, feA] = audioread("C:\Users\camil\Documents\IMT_A\semestre_6\electrical engineering\tp-audio-ee-etudiant-c24leray\src\wav\single_tone_piano2.wav");
% Apply the ADSR envelope to the audio signal
adsrSignal = abs(ifftshift(ifft(xA)));
sound(adsrSignal, feA);
% Plot the envelope
figure;
plot(feA, adsrSignal);
xlabel('Time (s)');
ylabel('Amplitude');
title('ADSR Envelope');
audiowrite("C:\Users\camil\Documents\IMT_A\semestre_6\electrical engineering\tp-audio-ee-etudiant-c24leray\src\wav\single_tone_piano2.wav", adsrSignal, fe);
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment