diff --git a/Q1_4_song.wav b/Q1_4_song.wav new file mode 100644 index 0000000000000000000000000000000000000000..61ae7f2b5c7f9276eed27370bdab09c81fb6ac82 Binary files /dev/null and b/Q1_4_song.wav differ diff --git a/SAR.m b/SAR.m index 7322cde6af179eab15994169ebcbeff86346c6a4..9d1fc9ac79e1ed03d8ac7589b37665c35530e302 100644 --- a/SAR.m +++ b/SAR.m @@ -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 diff --git a/question_1.m b/question_1.m new file mode 100644 index 0000000000000000000000000000000000000000..02adce553650ed807026dd84f2a95564eae72909 --- /dev/null +++ b/question_1.m @@ -0,0 +1,14 @@ +% 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 diff --git a/question_2.m b/question_2.m new file mode 100644 index 0000000000000000000000000000000000000000..ad21a52f22aa6886b9f0ff74d5375ce968441435 --- /dev/null +++ b/question_2.m @@ -0,0 +1,24 @@ +% 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 diff --git a/question_3.asv b/question_3.asv new file mode 100644 index 0000000000000000000000000000000000000000..c75d0e33cc80660806127f03a65e35f8ae45f501 --- /dev/null +++ b/question_3.asv @@ -0,0 +1,27 @@ +% 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 diff --git a/question_3.m b/question_3.m new file mode 100644 index 0000000000000000000000000000000000000000..1e2405027f12eefd1855df1747d92296ee192a72 --- /dev/null +++ b/question_3.m @@ -0,0 +1,26 @@ +% 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 diff --git a/question_4.m b/question_4.m new file mode 100644 index 0000000000000000000000000000000000000000..e83689b2c438c66c2836f21fa07152f8ce03cf8e --- /dev/null +++ b/question_4.m @@ -0,0 +1,35 @@ +% 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 diff --git a/src/wav/single_tone_piano2.wav b/src/wav/single_tone_piano2.wav index 9e5acb3d5b0fbca6a66214152c40ded4e9285829..609d4fbf95cd2a8b8690229d05a06d5123192de1 100644 Binary files a/src/wav/single_tone_piano2.wav and b/src/wav/single_tone_piano2.wav differ diff --git a/untitled3.m b/untitled3.m new file mode 100644 index 0000000000000000000000000000000000000000..f4c7c4836483f6e80e8c9bca99d14a6e0c02f6e1 --- /dev/null +++ b/untitled3.m @@ -0,0 +1,18 @@ + +[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);