diff --git a/question_12.m b/question_12.m index ad21a52f22aa6886b9f0ff74d5375ce968441435..7499e34a56ec57ff290f04981f67e119d10817a5 100644 --- a/question_12.m +++ b/question_12.m @@ -17,7 +17,7 @@ f2 = (-L2/2 : L2/2 - 1)*(fe2/L2); figure; plot(f1, log(abs(X1)),'r'); -hold on; +hold on plot(f2, log(abs(X2)),'b'); title("spectre"); xlabel("fréquence en Hz"); diff --git a/question_14.m b/question_14.m index e83689b2c438c66c2836f21fa07152f8ce03cf8e..02a1167d45c2484accb2aabc97a4e543aeeb4dc8 100644 --- a/question_14.m +++ b/question_14.m @@ -12,7 +12,7 @@ fs = 44100; % Sampling frequency (Hz) totalTime = A + D + R; % totalTime = totalTime * 6; % Extend the envelope for 6 seconds -t = linspace(0, totalTime, totalTime * fs); +t = linspace(0, totalTime, totalTime * 6); % Generate ADSR envelope attack = linspace(0, 1, A * fs); @@ -30,6 +30,6 @@ 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 +audiowrite("C:\Users\camil\Documents\IMT_A\semestre_6\electrical engineering\tp-audio-ee-etudiant-c24leray\src\wav\single_tone_piano2.wav", adsrSignal, fe); 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 +soundsc(adsrSignal, fs); \ No newline at end of file diff --git a/question_21.m b/question_21.m index 08cb3251953a046aa2f8804afe0628098d2bbf03..506672f1c16939d711987db505c599c11885d951 100644 --- a/question_21.m +++ b/question_21.m @@ -19,8 +19,6 @@ title('spectre du signal carré'); x_2 = sawtooth(2*pi*t/T); -plot(t,x_2) -title('sawtooth') %fft X_2 = 10*log10(abs(fftshift(fft(x_2)))); @@ -71,4 +69,29 @@ xlim([-5000 5000]); %question 2.3 -sound(y,fe) +soundsc(x_1,fe) + + +% 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) + +% Total duration of the envelope +totalTime = A + D + R; + +% totalTime = totalTime * 6; % Extend the envelope for 6 seconds +t = linspace(0, totalTime, totalTime * 6); + +% Generate ADSR envelope +attack = linspace(0, 1, A * fe); +decay = linspace(1, S, D * fe); +release = linspace(S, 0, R * fe); + + % Combine all segments +adsrEnvelope = [attack, decay, release]; + +adsrSignal = x_1(1:length(adsrEnvelope)) .* adsrEnvelope'; +soundsc(adsrSignal, fe); \ No newline at end of file