Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
T
tp-audio-ee-etudiant-v24ye
Manage
Activity
Members
Labels
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
UEEE
sar-signal-audio
gr-vhdl-v24ye
tp-audio-ee-etudiant-v24ye
Commits
bef2e89b
Commit
bef2e89b
authored
2 weeks ago
by
YE Victor
Browse files
Options
Downloads
Patches
Plain Diff
Upload New File
parent
ab9b46bd
Branches
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/SAR1Q4.m
+104
-0
104 additions, 0 deletions
src/SAR1Q4.m
with
104 additions
and
0 deletions
src/SAR1Q4.m
0 → 100644
+
104
−
0
View file @
bef2e89b
%Q1.4
% Charger un son
fichier
=
fullfile
(
'wav'
,
'single_tone_piano1'
);
[
signal
,
Fs
]
=
audioread
(
fichier
);
if
size
(
signal
,
2
)
==
2
signal
=
mean
(
signal
,
2
);
end
duration
=
1
;
% (en secondes)
N
=
min
(
length
(
signal
),
round
(
duration
*
Fs
));
signal
=
signal
(
1
:
N
);
% Calculer la FFT
Y
=
fft
(
signal
);
Nfft
=
length
(
Y
);
f
=
(
0
:
Nfft
-
1
)
*
(
Fs
/
Nfft
);
% Utiliser uniquement la moitié du spectre
Y_half
=
Y
(
1
:
floor
(
Nfft
/
2
));
f_half
=
f
(
1
:
floor
(
Nfft
/
2
));
% Trouver la fréquence fondamentale automatiquement
[
~
,
idx_fundamental
]
=
max
(
abs
(
Y_half
));
f0
=
f_half
(
idx_fundamental
);
fprintf
(
'Fréquence fondamentale estimée : %.2f Hz\n'
,
f0
);
% Calculer les 8 premières harmoniques
harmonics_freqs
=
f0
*
(
1
:
8
);
harmonics_amps
=
zeros
(
1
,
8
);
for
k
=
1
:
8
% Trouver l'index dans f_half le plus proche de l'harmonique k
[
~
,
idx
]
=
min
(
abs
(
f_half
-
harmonics_freqs
(
k
)));
harmonics_amps
(
k
)
=
abs
(
Y_half
(
idx
));
end
% Durée du son synthétisé
t
=
(
0
:
1
/
Fs
:
duration
)
'
;
% Synthèse du son (superposition d'ondes)
synth_signal
=
zeros
(
size
(
t
));
for
k
=
1
:
8
synth_signal
=
synth_signal
+
harmonics_amps
(
k
)
*
sin
(
2
*
pi
*
harmonics_freqs
(
k
)
*
t
);
end
%------Ajout de l'enveloppe ADSR-----
% Paramètres de l'enveloppe (en secondes)
T_attack
=
0.05
;
T_decay
=
0.1
;
T_sustain
=
0.7
;
% niveau de sustain (entre 0 et 1)
T_release
=
0.2
;
% Créer l'enveloppe
n_attack
=
round
(
T_attack
*
Fs
);
n_decay
=
round
(
T_decay
*
Fs
);
n_release
=
round
(
T_release
*
Fs
);
n_sustain
=
length
(
t
)
-
(
n_attack
+
n_decay
+
n_release
);
if
n_sustain
<
0
error
(
'Durée totale trop courte par rapport aux durées ADSR.'
);
end
% Attack : linéaire de 0 à 1
env_attack
=
linspace
(
0
,
1
,
n_attack
)
'
;
% Decay : descend de 1 à T_sustain
env_decay
=
linspace
(
1
,
T_sustain
,
n_decay
)
'
;
% Sustain : niveau constant
env_sustain
=
T_sustain
*
ones
(
n_sustain
,
1
);
% Release : descend de T_sustain à 0
env_release
=
linspace
(
T_sustain
,
0
,
n_release
)
'
;
% Concaténer toutes les phases
envelope
=
[
env_attack
;
env_decay
;
env_sustain
;
env_release
];
% Appliquer l'enveloppe
synth_signal
=
synth_signal
.*
envelope
;
% Normaliser pour éviter saturation
synth_signal
=
synth_signal
/
max
(
abs
(
synth_signal
));
% Écouter le son synthétisé
sound
(
synth_signal
,
Fs
);
% Afficher les harmoniques trouvées
disp
(
'Fréquences et amplitudes des 8 premières harmoniques :'
);
for
k
=
1
:
8
fprintf
(
'Harmonique %d : %.2f Hz, amplitude = %.4f\n'
,
k
,
harmonics_freqs
(
k
),
harmonics_amps
(
k
));
end
% Pour sauvegarder dans un fichier
audiowrite
(
'synth_piano_ADSR.wav'
,
synth_signal
,
Fs
);
% Pour afficher l'enveloppe :
figure
;
plot
(
t
,
envelope
,
'LineWidth'
,
2
);
xlabel
(
'Temps (s)'
);
ylabel
(
'Amplitude'
);
title
(
'Enveloppe ADSR appliquée'
);
grid
on
;
\ No newline at end of file
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment