Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
T
tp-audio-ee-etudiant-a24barra
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-a24barra
tp-audio-ee-etudiant-a24barra
Commits
b7163f8e
Commit
b7163f8e
authored
1 month ago
by
BARRAQUE Alix
Browse files
Options
Downloads
Patches
Plain Diff
Ajout du code matlab sur la branche main
parent
e3b35032
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
SAR_fft.m
+441
-0
441 additions, 0 deletions
SAR_fft.m
with
441 additions
and
0 deletions
SAR_fft.m
0 → 100644
+
441
−
0
View file @
b7163f8e
%%
%Question 1.1
[
x
,
fe
]
=
audioread
(
"single_tone_guitar_nylon_string_a2.wav"
);
soundsc
(
x
,
fe
);
L
=
length
(
x
);
Y
=
fft
(
x
);
F
=
0
:
fe
/
L
:
fe
-
fe
/
L
;
figure
(
1
);
clf
;
plot
(
F
,(
abs
(
Y
)),
'r-'
);
grid
;
xlabel
(
'f(HZ)'
);
ylabel
(
'fft_guitare'
);
[
x2
,
fe2
]
=
audioread
(
"single_tone_sax-alto-a3.wav"
);
soundsc
(
x2
,
fe2
);
L2
=
length
(
x2
);
Y2
=
fft
(
x2
);
F2
=
0
:
fe2
/
L2
:
fe2
-
fe2
/
L2
;
figure
(
2
);
clf
;
plot
(
F2
,(
abs
(
Y2
)),
'r-'
);
grid
;
xlabel
(
'f(HZ)'
);
ylabel
(
'fft-saxo'
);
%Question 1.2
[
xp1
,
fep1
]
=
audioread
(
"single_tone_piano1.wav"
);
soundsc
(
xp1
,
fep1
);
Lp1
=
length
(
xp1
);
Yp1
=
fft
(
xp1
);
Fp1
=
0
:
fep1
/
Lp1
:
fep1
-
fep1
/
Lp1
;
[
xp2
,
fep2
]
=
audioread
(
"single_tone_piano2.wav"
);
soundsc
(
xp2
,
fep2
);
Lp2
=
length
(
xp2
);
Yp2
=
fft
(
xp2
);
Fp2
=
0
:
fep2
/
Lp2
:
fep2
-
fep2
/
Lp2
;
%Tracé en dB
figure
(
3
);
clf
;
plot
(
Fp1
,
20
*
log10
(
abs
(
Yp1
)),
'b-'
,
Fp2
,
20
*
log10
(
abs
(
Yp2
)),
'r-'
);
grid
;
xlabel
(
'f(HZ)'
);
ylabel
(
'fft'
);
legend
(
'piano1'
,
'piano2'
);
%Tracé sans le 20*log
figure
(
4
);
clf
;
plot
(
Fp1
,
(
abs
(
Yp1
)),
'b-'
,
Fp2
,(
abs
(
Yp2
)),
'r-'
);
grid
;
xlabel
(
'f(HZ)'
);
ylabel
(
'fft'
);
legend
(
'piano1'
,
'piano2'
);
%Question 1.3
%Tracé pour pouvoir lire les amplitudes des harmoniques et les fréquences
%correspondantes
figure
(
5
);
clf
;
plot
(
Fp1
,
abs
(
Yp1
),
'b-'
);
grid
;
xlabel
(
'f(HZ)'
);
ylabel
(
'fft-piano-harmonieux'
);
t
=
0
:
1
/
fep1
:
2
;
% Données des sinusoïdes
list_f
=
[
221
442
663
885
1108
1331
1556
1782
];
liste_a
=
[
7287.97
5565.18
1088.64
1414.52
980.919
671.72
528.634
101.402
];
% Construction du signal
s
=
zeros
(
size
(
t
));
for
k
=
1
:
8
s
=
s
+
liste_a
(
k
)
*
sin
(
2
*
pi
*
list_f
(
k
)
*
t
);
end
% Normalisation
s
=
s
/
max
(
abs
(
s
));
figure
(
6
);
plot
(
t
,
s
,
'r'
);
xlabel
(
'temps en secondes'
);
ylabel
(
'Son créé par superposition'
)
%Question 1.4
% constantes fixées arbitrairement
sustain_level
=
0.7
;
n_attack
=
fep1
*
0.2
;
n_decay
=
fep1
*
0.4
;
n_sustain
=
fep1
*
1
;
n_release
=
fep1
*
0.4
;
%création de l'enveloppe
attack_env
=
linspace
(
0
,
1
,
n_attack
);
decay_env
=
linspace
(
1
,
sustain_level
,
n_decay
);
sustain_env
=
sustain_level
*
ones
(
1
,
n_sustain
+
1
);
release_env
=
linspace
(
sustain_level
,
0
,
n_release
);
env
=
[
attack_env
,
decay_env
,
sustain_env
,
release_env
];
%signal synthétisé modulé par l'envelope
s_env
=
s
.*
env
;
% note de piano synthétisée avec enveloppe
figure
(
7
);
clf
;
plot
(
t
,
s_env
,
'r'
);
xlabel
(
'Temps en s'
)
ylabel
(
'Amplitude en Hz'
)
%Question 1.5
[
xp1
,
fep1
]
=
audioread
(
"single_tone_piano1.wav"
);
soundsc
(
xp1
,
fep1
);
% On initialise le spectre à 0
X
=
zeros
(
1
,
length
(
t
));
for
k
=
1
:
8
index
=
round
(
list_f
(
k
)
*
length
(
t
)
/
fep1
);
X
(
index
+
1
)
=
liste_a
(
k
)/
2
;
X
(
end
-
index
+
1
)
=
liste_a
(
k
)/
2
;
end
s_ifft
=
real
(
ifft
(
X
));
s_ifft
=
s_ifft
/
max
(
abs
(
s_ifft
));
soundsc
(
s_ifft
,
fep1
);
figure
(
8
);
plot
(
t
,
s_ifft
);
xlabel
(
'Temps (s)'
);
ylabel
(
'Amplitude'
);
title
(
'Signal reconstruit par IFFT à partir des harmoniques'
);
Partie
1
:
%%
%Question 1.1
[
x
,
fe
]
=
audioread
(
"single_tone_guitar_nylon_string_a2.wav"
);
soundsc
(
x
,
fe
);
L
=
length
(
x
);
Y
=
fft
(
x
);
F
=
0
:
fe
/
L
:
fe
-
fe
/
L
;
figure
(
1
);
clf
;
plot
(
F
,(
abs
(
Y
)),
'r-'
);
grid
;
xlabel
(
'f(HZ)'
);
ylabel
(
'fft_guitare'
);
[
x2
,
fe2
]
=
audioread
(
"single_tone_sax-alto-a3.wav"
);
soundsc
(
x2
,
fe2
);
L2
=
length
(
x2
);
Y2
=
fft
(
x2
);
F2
=
0
:
fe2
/
L2
:
fe2
-
fe2
/
L2
;
figure
(
2
);
clf
;
plot
(
F2
,(
abs
(
Y2
)),
'r-'
);
grid
;
xlabel
(
'f(HZ)'
);
ylabel
(
'fft-saxo'
);
%Question 1.2
[
xp1
,
fep1
]
=
audioread
(
"single_tone_piano1.wav"
);
soundsc
(
xp1
,
fep1
);
Lp1
=
length
(
xp1
);
Yp1
=
fft
(
xp1
);
Fp1
=
0
:
fep1
/
Lp1
:
fep1
-
fep1
/
Lp1
;
[
xp2
,
fep2
]
=
audioread
(
"single_tone_piano2.wav"
);
soundsc
(
xp2
,
fep2
);
Lp2
=
length
(
xp2
);
Yp2
=
fft
(
xp2
);
Fp2
=
0
:
fep2
/
Lp2
:
fep2
-
fep2
/
Lp2
;
%Tracé en dB
figure
(
3
);
clf
;
plot
(
Fp1
,
20
*
log10
(
abs
(
Yp1
)),
'b-'
,
Fp2
,
20
*
log10
(
abs
(
Yp2
)),
'r-'
);
grid
;
xlabel
(
'f(HZ)'
);
ylabel
(
'fft'
);
legend
(
'piano1'
,
'piano2'
);
%Tracé sans le 20*log
figure
(
4
);
clf
;
plot
(
Fp1
,
(
abs
(
Yp1
)),
'b-'
,
Fp2
,(
abs
(
Yp2
)),
'r-'
);
grid
;
xlabel
(
'f(HZ)'
);
ylabel
(
'fft'
);
legend
(
'piano1'
,
'piano2'
);
%Question 1.3
%Tracé pour pouvoir lire les amplitudes des harmoniques et les fréquences
%correspondantes
figure
(
5
);
clf
;
plot
(
Fp1
,
abs
(
Yp1
),
'b-'
);
grid
;
xlabel
(
'f(HZ)'
);
ylabel
(
'fft-piano-harmonieux'
);
t
=
0
:
1
/
fep1
:
2
;
% Données des sinusoïdes
list_f
=
[
221
442
663
885
1108
1331
1556
1782
];
liste_a
=
[
7287.97
5565.18
1088.64
1414.52
980.919
671.72
528.634
101.402
];
% Construction du signal
s
=
zeros
(
size
(
t
));
for
k
=
1
:
8
s
=
s
+
liste_a
(
k
)
*
sin
(
2
*
pi
*
list_f
(
k
)
*
t
);
end
% Normalisation
s
=
s
/
max
(
abs
(
s
));
figure
(
6
);
plot
(
t
,
s
,
'r'
);
xlabel
(
'temps en secondes'
);
ylabel
(
'Son créé par superposition'
)
%Question 1.4
% constantes fixées arbitrairement
sustain_level
=
0.7
;
n_attack
=
fep1
*
0.2
;
n_decay
=
fep1
*
0.4
;
n_sustain
=
fep1
*
1
;
n_release
=
fep1
*
0.4
;
%création de l'enveloppe
attack_env
=
linspace
(
0
,
1
,
n_attack
);
decay_env
=
linspace
(
1
,
sustain_level
,
n_decay
);
sustain_env
=
sustain_level
*
ones
(
1
,
n_sustain
+
1
);
release_env
=
linspace
(
sustain_level
,
0
,
n_release
);
env
=
[
attack_env
,
decay_env
,
sustain_env
,
release_env
];
%signal synthétisé modulé par l'envelope
s_env
=
s
.*
env
;
% note de piano synthétisée avec enveloppe
figure
(
7
);
clf
;
plot
(
t
,
s_env
,
'r'
);
xlabel
(
'Temps en s'
)
ylabel
(
'Amplitude en Hz'
)
%Question 1.5
[
xp1
,
fep1
]
=
audioread
(
"single_tone_piano1.wav"
);
soundsc
(
xp1
,
fep1
);
% On initialise le spectre à 0
X
=
zeros
(
1
,
length
(
t
));
for
k
=
1
:
8
index
=
round
(
list_f
(
k
)
*
length
(
t
)
/
fep1
);
X
(
index
+
1
)
=
liste_a
(
k
)/
2
;
X
(
end
-
index
+
1
)
=
liste_a
(
k
)/
2
;
end
s_ifft
=
real
(
ifft
(
X
));
s_ifft
=
s_ifft
/
max
(
abs
(
s_ifft
));
soundsc
(
s_ifft
,
fep1
);
figure
(
8
);
plot
(
t
,
s_ifft
);
xlabel
(
'Temps (s)'
);
ylabel
(
'Amplitude'
);
title
(
'Signal reconstruit par IFFT à partir des harmoniques'
);
Partie
2
:
% Question 2.1
freq
=
10000
t
=
0
:
1
/
freq
:
1
;
Fe
=
1
/
(
t
(
2
)
-
t
(
1
));
% Fréquence d'échantillonnage (ici 10 000 Hz)
L
=
length
(
t
);
f0
=
5
;
s_carre
=
square
(
2
*
pi
*
f0
*
t
+
pi
);
% signal carré à 5 Hz
s_dente
=
-
sawtooth
(
2
*
pi
*
f0
*
t
);
% signal dent de scie à 5 Hz
figure
(
8
);
plot
(
t
,
s_carre
);
title
(
'Signal carré'
);
xlabel
(
'Temps (s)'
);
ylabel
(
'Amplitude'
);
grid
on
;
plot
(
t
,
s_dente
);
title
(
'Signal dent de scie'
);
xlabel
(
'Temps (s)'
);
ylabel
(
'Amplitude'
);
grid
on
;
s_carre_fft
=
fft
(
s_carre
);
s_dente_fft
=
fft
(
s_dente
);
l
=
length
(
t
);
f_fft
=
(
0
:
l
-
1
)
*
(
freq
/
l
)
figure
(
9
);
clf
;
plot
(
f_fft
,
abs
(
s_carre_fft
),
'rd-'
);
grid
;
xlabel
(
'f(HZ)'
);
ylabel
(
'fft-s-carré'
);
figure
(
10
);
clf
;
plot
(
f_fft
,
abs
(
s_dente_fft
),
'rd-'
);
grid
;
xlabel
(
'f(HZ)'
);
ylabel
(
'fft-s-dente'
);
%Question 2.2
h
=
[
1
/
2
1
/
2
];
y
=
filter
(
h
,[
1
],
s_carre
);
Y
=
fft
(
y
);
figure
(
11
);
clf
;
plot
(
f_fft
,
abs
(
Y
),
'rd-'
);
hold
on
plot
(
f_fft
,
abs
(
s_carre_fft
),
'b*'
);
grid
;
xlabel
(
'f(HZ)'
);
ylabel
(
'fft-s-carre-filtre'
);
%Question 3.3
figure
(
15
);
subplot
(
2
,
1
,
1
);
xcorr1
=
xcorr
(
xe1
,
'coeff'
);
plot
(
xcorr1
);
title
(
'Autocorrélation de xe1'
);
subplot
(
2
,
1
,
2
);
xcorr2
=
xcorr
(
xe2
,
'coeff'
);
plot
(
xcorr2
);
title
(
'Autocorrélation de xe2'
);
% Question 3.4
y
=
simule_piece
(
xe1
,
fep1
);
xcorrxy
=
xcorr
(
y
,
xe1
);
figure
(
2
);
plot
(
xcorrxy
);
xlabel
(
'Temps (s)'
);
ylabel
(
'Amplitude'
);
title
(
'Réponse impulsionnelle estimée de la pièce'
);
% Question 3.5
function
[
y
]
=
effet_reverb
(
x
,
h
)
y
=
conv
(
x
,
h
,
'same'
);
end
%Question 3.6
h_causal
=
xcorrxy
;
[
x_test_effet
,
fe_test_effet
]
=
audioread
(
"single_tone_guitar_nylon_string_a2.wav"
);
soundsc
(
x_test_effet
,
fe_test_effet
);
tic
y
=
effet_reverb
(
x_test_effet
,
h_causal
);
temps_calcul
=
toc
;
fprintf
(
'Temps execution de effet_reverb :%.4f secondes\n '
,
temps_calcul
);
%Question 3.7
function
[
z
]
=
effet_reverb_FFT
(
h
,
x
)
NFFT
=
length
(
h
)
+
length
(
x
)
-
1
;
Z
=
fft
(
h
,
NFFT
)
.*
fft
(
x
,
NFFT
);
z
=
real
(
ifft
(
Z
));
z
=
z
(
1
:
NFFT
);
end
[
x_test_effet
,
fe_test_effet
]
=
audioread
(
"single_tone_guitar_nylon_string_a2.wav"
);
soundsc
(
x_test_effet
,
fe_test_effet
);
tic
y
=
effet_reverb_FFT
(
h_causal
,
x_test_effet
);
temps_calcul
=
toc
;
fprintf
(
'Temps execution de effet_reverb_FFT :%.4f secondes\n '
,
temps_calcul
);
%Question 3.12
function
[
y
]
=
analyse_delay
(
x
,
tau
,
g
)
a
=
zeros
(
1
,
tau
+
1
);
b
=
zeros
(
1
,
tau
+
1
);
a
(
1
)
=
1
;
a
(
tau
+
1
)
=-
g
;
b
(
1
)
=
1
;
y
=
filter
(
b
,
a
,
x
);
end
f_echantillonnage
=
44100
;
duree
=
0.5
;
N_echantillons
=
round
(
f_echantillonnage
*
duree
)
% Nombre d'échantillons à observer
delta
=
zeros
(
1
,
N_echantillons
);
delta
(
1
)
=
1
;
% Impulsion de Dirac : [1 0 0 0 ...]
h
=
analyse_delay
(
delta
,
100
,
0.9
);
figure
(
20
);
stem
(
0
:
N_echantillons
-
1
,
h
);
xlabel
(
'n'
);
ylabel
(
'h[n]'
);
title
(
'Réponse impulsionnelle du filtre'
);
%Question 3.14
g
=
0.5
;
tau
=
1
;
N
=
128
;
M
=
1000
;
nu
=
linspace
(
0
,
1
,
M
);
mod_theorique
=
1
.
/
sqrt
(
1
+
2
*
g
*
cos
(
2
*
pi
*
nu
*
tau
)
+
g
^
2
);
n
=
0
:
N
-
1
;
h
=
(
-
g
)
.^
n
;
H_fft
=
fft
(
h
,
M
);
mod_numerique
=
abs
(
H_fft
);
figure
(
21
);
plot
(
nu
,
mod_theorique
,
'r-'
,
'LineWidth'
,
2
);
hold
on
;
plot
(
nu
,
mod_numerique
,
'b--'
,
'LineWidth'
,
1.5
);
xlabel
(
'Fréquence \nu'
);
ylabel
(
'|ĥ(\nu)|'
);
legend
(
'Théorique'
,
'Numérique (FFT)'
);
title
(
'Comparaison du module de la réponse en fréquence'
);
grid
on
;
%Question 3.15
function
y
=
effet_delay
(
x
,
delay_s
,
g
,
fe
)
tau
=
round
(
delay_s
*
fe
);
if
tau
<
1
error
(
'Le délai spécifié est trop court (tau < 1).'
);
end
a
=
zeros
(
1
,
tau
+
1
);
a
(
1
)
=
1
;
a
(
end
)
=
-
g
;
b
=
1
;
y
=
filter
(
b
,
a
,
x
);
end
%Question 3.16
[
x
,
fe
]
=
audioread
(
'single_tone_piano2.wav'
);
delay_s
=
0.25
;
g
=
0.9
;
y
=
effet_delay
(
x
,
delay_s
,
g
,
fe
);
t
=
(
0
:
length
(
x
)
-
1
)/
fe
;
figure
(
22
);
subplot
(
2
,
1
,
1
);
plot
(
t
,
x
);
xlabel
(
'Temps (s)'
);
ylabel
(
'Amplitude'
);
title
(
'Signal original'
);
subplot
(
2
,
1
,
2
);
plot
(
t
,
y
);
xlabel
(
'Temps (s)'
);
ylabel
(
'Amplitude'
);
title
(
'Signal avec effet delay'
);
%Question 3.17
function
y
=
effet_delay_filtre
(
x
,
delay_s
,
g
,
K
,
Fe
)
N
=
length
(
x
);
tau
=
round
(
delay_s
*
Fe
);
y
=
zeros
(
size
(
x
));
for
k
=
1
:
N
somme
=
0
;
for
n
=
0
:
K
-
1
indice
=
k
-
tau
-
n
;
if
indice
>=
1
somme
=
somme
+
y
(
indice
);
end
end
y
(
k
)
=
x
(
k
)
-
(
g
/
K
)
*
somme
;
end
end
%Question 3.18
[
x
,
Fe
]
=
audioread
(
'single_tone_piano2.wav'
);
delay_s
=
0.25
;
g
=
0.9
;
K
=
10
;
y
=
effet_delay_filtre
(
x
,
delay_s
,
g
,
K
,
Fe
);
audiowrite
(
'piano_delay_filtre.wav'
,
y
,
Fe
);
soundsc
(
y
,
Fe
);
% Tracé des signaux
t
=
(
0
:
length
(
x
)
-
1
)/
Fe
;
figure
(
23
);
subplot
(
2
,
1
,
1
);
plot
(
t
,
x
);
xlabel
(
'Temps (s)'
);
ylabel
(
'Amplitude'
);
title
(
'Signal original'
);
subplot
(
2
,
1
,
2
);
plot
(
t
,
y
);
xlabel
(
'Temps (s)'
);
ylabel
(
'Amplitude'
);
title
(
'Signal avec effet delay filtré'
);
%Question 3.19
K
=
10
;
h_r
=
ones
(
1
,
K
)
/
K
;
N_fft
=
1024
;
H
=
fft
(
h_r
,
N_fft
);
H_mag
=
abs
(
H
(
1
:
N_fft
/
2
));
frequences
=
linspace
(
0
,
Fe
/
2
,
N_fft
/
2
);
figure
(
24
);
plot
(
frequences
,
20
*
log10
(
H_mag
));
xlabel
(
'Fréquence (Hz)'
);
ylabel
(
'Gain (dB)'
);
title
(
'Réponse en fréquence du filtre h_r(k)'
);
grid
on
;
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