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
Admin message
La purge estivale des projets de gitlab-df sera réalisée jeudi 10 juillet vers 10h.
Show more breadcrumbs
UEEE
sar-signal-audio
gr-vhdl-v24ye
tp-audio-ee-etudiant-v24ye
Commits
36d45994
Commit
36d45994
authored
1 month ago
by
YE Victor
Browse files
Options
Downloads
Patches
Plain Diff
Upload New File
parent
ccc73d0a
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/SAR1Q5.m
+84
-0
84 additions, 0 deletions
src/SAR1Q5.m
with
84 additions
and
0 deletions
src/SAR1Q5.m
0 → 100644
+
84
−
0
View file @
36d45994
%Q1_5
% Chargement du son
fichier
=
fullfile
(
'wav'
,
'single_tone_piano1'
);
[
signal
,
Fs
]
=
audioread
(
fichier
);
% Mono si besoin
if
size
(
signal
,
2
)
==
2
signal
=
mean
(
signal
,
2
);
end
% Extraire 1 seconde de son
duration
=
1
;
N
=
min
(
length
(
signal
),
round
(
duration
*
Fs
));
signal
=
signal
(
1
:
N
);
% FFT
Nfft
=
length
(
signal
);
Y
=
fft
(
signal
);
f
=
(
0
:
Nfft
-
1
)
*
(
Fs
/
Nfft
);
% Spectre moitié
Y_half
=
Y
(
1
:
floor
(
Nfft
/
2
));
f_half
=
f
(
1
:
floor
(
Nfft
/
2
));
% Détection du fondamentale
[
~
,
idx_fundamental
]
=
max
(
abs
(
Y_half
));
f0
=
f_half
(
idx_fundamental
);
% Récupérer les indices des 8 premières harmoniques
harmonics_freqs
=
f0
*
(
1
:
8
);
harmonic_indices
=
zeros
(
1
,
8
);
for
k
=
1
:
8
[
~
,
idx
]
=
min
(
abs
(
f
-
harmonics_freqs
(
k
)));
harmonic_indices
(
k
)
=
idx
;
end
% Construire un nouveau spectre : garder seulement les harmoniques
Y_harmonics
=
zeros
(
size
(
Y
));
for
idx
=
harmonic_indices
Y_harmonics
(
idx
)
=
Y
(
idx
);
% Fréquence positive
if
idx
~=
1
% éviter de doubler le DC
Y_harmonics
(
end
-
idx
+
2
)
=
conj
(
Y
(
idx
));
% Fréquence négative conjuguée
end
end
% Reconstruction via IFFT
synth_ifft
=
real
(
ifft
(
Y_harmonics
));
% Normalisation
synth_ifft
=
synth_ifft
/
max
(
abs
(
synth_ifft
));
% Appliquer enveloppe ADSR
t
=
(
0
:
length
(
synth_ifft
)
-
1
)
'
/
Fs
;
% ADSR paramètres
T_attack
=
0.05
;
T_decay
=
0.1
;
T_sustain
=
0.7
;
T_release
=
0.2
;
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 insuffisante pour l’ADSR définie.'
);
end
env_attack
=
linspace
(
0
,
1
,
n_attack
)
'
;
env_decay
=
linspace
(
1
,
T_sustain
,
n_decay
)
'
;
env_sustain
=
T_sustain
*
ones
(
n_sustain
,
1
);
env_release
=
linspace
(
T_sustain
,
0
,
n_release
)
'
;
envelope
=
[
env_attack
;
env_decay
;
env_sustain
;
env_release
];
% Appliquer l’enveloppe
synth_ifft
=
synth_ifft
.*
envelope
;
% Écoute
sound
(
synth_ifft
,
Fs
);
% Sauvegarde si besoin
audiowrite
(
'synth_ifft_ADSR.wav'
,
synth_ifft
,
Fs
);
\ 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