From beebc534b00a1891ad54efa30d44e6ed5c033f32 Mon Sep 17 00:00:00 2001 From: c24leray <camille.lerays@imt-atlantique.net> Date: Mon, 19 May 2025 10:46:44 +0200 Subject: [PATCH] coucou --- question_12.m | 2 +- question_14.m | 6 +++--- question_21.m | 29 ++++++++++++++++++++++++++--- 3 files changed, 30 insertions(+), 7 deletions(-) diff --git a/question_12.m b/question_12.m index ad21a52..7499e34 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 e83689b..02a1167 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 08cb325..506672f 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 -- GitLab