Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
T
tp-audio-ee-etudiant-t24dherv
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-t24dherv
tp-audio-ee-etudiant-t24dherv
Commits
305c5024
Commit
305c5024
authored
2 weeks ago
by
D'HERVE Tristan
Browse files
Options
Downloads
Patches
Plain Diff
Edit SARaudio.m
parent
f1203019
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
docs/SARaudio.m
+176
-39
176 additions, 39 deletions
docs/SARaudio.m
with
176 additions
and
39 deletions
docs/SARaudio.m
+
176
−
39
View file @
305c5024
%{
clear
all
;
clear
all
;
close
all
;
close
all
;
%{
[
x
,
fe
]
=
audioread
(
'/homes/t24dherv/Documents/SAR_audio/single_tone_cello-a3.wav'
);
[
x
,
fe
]
=
audioread
(
'/homes/t24dherv/Documents/SAR_audio/single_tone_cello-a3.wav'
);
soundsc
(
x
,
fe
);
soundsc
(
x
,
fe
);
...
@@ -19,11 +20,19 @@ freq = -fe/2 : fe/n : fe/2-fe/n;
...
@@ -19,11 +20,19 @@ freq = -fe/2 : fe/n : fe/2-fe/n;
freq2
=
-
fe2
/
2
:
fe2
/
n2
:
fe2
/
2
-
fe2
/
n2
;
freq2
=
-
fe2
/
2
:
fe2
/
n2
:
fe2
/
2
-
fe2
/
n2
;
plot
(
freq
,
abs
(
y
))
plot
(
freq
,
10
*
log
(
abs
(
y
)));
xlabel
(
'Fréquence (Hz)'
);
ylabel
(
'Amplitude du signal (dB)'
);
title
(
'Single tone cello'
);
figure
;
figure
;
clf
;
clf
;
plot
(
freq2
,
abs
(
y2
));
plot
(
freq2
,
10
*
log
(
abs
(
y2
)));
xlabel
(
'Fréquence (Hz)'
)
ylabel
(
'Amplitude du signal (dB)'
)
title
(
'Single tone guitar nylon string'
)
%}
%{
clear
all
;
clear
all
;
close
all
;
close
all
;
...
@@ -43,13 +52,15 @@ n4 = length(y4);
...
@@ -43,13 +52,15 @@ n4 = length(y4);
freq4
=
-
fe4
/
2
:
fe4
/
n4
:
fe4
/
2
-
fe4
/
n4
;
freq4
=
-
fe4
/
2
:
fe4
/
n4
:
fe4
/
2
-
fe4
/
n4
;
plot
(
freq3
,
abs
(
y3
));
plot
(
freq3
,
10
*
log
(
abs
(
y3
)),
freq4
,
10
*
log
(
abs
(
y4
)));
hold
on
legend
(
'single-tone-piano1'
,
'single-tone-piano2'
);
plot
(
freq4
,
abs
(
y4
));
xlabel
(
'Fréquence (Hz)'
);
ylabel
(
'Amplitude du signal (dB)'
);
fe
=
44100
;
fe
=
44100
;
D
=
2
;
D
=
5
;
t
=
linspace
(
0
,
D
,
D
*
fe
);
t
=
linspace
(
0
,
D
,
D
*
fe
);
% Exemple d’amplitudes relatives (normalisées)
% Exemple d’amplitudes relatives (normalisées)
...
@@ -58,13 +69,20 @@ f = [220.374, 442.041, 663.24, 885.538, 1108.34, 1331.46, 1556.2, 1782.88];
...
@@ -58,13 +69,20 @@ f = [220.374, 442.041, 663.24, 885.538, 1108.34, 1331.46, 1556.2, 1782.88];
x_synth
=
zeros
(
size
(
t
));
x_synth
=
zeros
(
size
(
t
));
for
k
=
1
:
8
for
k
=
1
:
8
x_synth
=
x_synth
+
A
(
k
)
*
sin
(
2
*
pi
*
f
(
k
)
*
t
);
x_synth
=
x_synth
+
10
*
log
(
A
(
k
)
)
*
sin
(
2
*
pi
*
f
(
k
)
*
t
);
end
end
x_synth
=
x_synth
/
max
(
abs
(
x_synth
));
x_synth
=
x_synth
/
max
(
abs
(
x_synth
));
%soundsc(x_synth, fe);
%soundsc(x_synth, fe);
audiowrite
(
'synth_piano.wav'
,
x_synth
,
fe
);
audiowrite
(
'synth_piano.wav'
,
x_synth
,
fe
);
plot
(
t
,
x_synth
)
xlabel
(
'Temps (s)'
)
ylabel
(
'Signal normalisé'
)
title
(
'Signal engendré'
)
% Durées de chaque phase
% Durées de chaque phase
A
=
0.1
;
Dd
=
0.4
;
S
=
1
;
R
=
0.5
;
A
=
0.1
;
Dd
=
0.4
;
S
=
1
;
R
=
0.5
;
...
@@ -103,29 +121,38 @@ xlabel('Temps (s)');
...
@@ -103,29 +121,38 @@ xlabel('Temps (s)');
ylabel
(
'Amplitude'
);
ylabel
(
'Amplitude'
);
title
(
'Enveloppe ADSR'
);
title
(
'Enveloppe ADSR'
);
%}
%{
A
=
[
7287.97
,
5565.18
,
1088.64
,
1414.52
,
980.919
,
671.72
,
570.373
,
101.402
];
A
=
[
7287.97
,
5565.18
,
1088.64
,
1414.52
,
980.919
,
671.72
,
570.373
,
101.402
];
f
=
[
220.374
,
442.041
,
663.24
,
885.538
,
1108.34
,
1331.46
,
1556.2
,
1782.88
];
f
=
[
220.374
,
442.041
,
663.24
,
885.538
,
1108.34
,
1331.46
,
1556.2
,
1782.88
];
fe
=
44100
;
fe
=
44100
;
D
=
2
;
D
=
5
;
t
=
linspace
(
0
,
D
,
D
*
fe
);
t
=
linspace
(
0
,
D
,
D
*
fe
);
N
=
D
*
fe
;
N
=
D
*
fe
;
x_synth
=
zeros
(
size
(
t
));
x_synth
=
zeros
(
size
(
t
));
for
k
=
1
:
8
for
k
=
1
:
8
x_synth
=
x_synth
+
A
(
k
)
*
sin
(
2
*
pi
*
f
(
k
)
*
t
);
x_synth
=
x_synth
+
10
*
log
(
A
(
k
)
)
*
sin
(
2
*
pi
*
f
(
k
)
*
t
);
end
end
x_synth
=
x_synth
/
max
(
abs
(
x_synth
));
nu
=
zeros
(
size
(
t
));
nu
=
zeros
(
size
(
t
));
for
k
=
1
:
8
for
k
=
1
:
8
nu
=
nu
+
A
(
k
)
*
fftshift
(
fft
(
sin
(
2
*
pi
*
f
(
k
)
*
t
)));
nu
=
nu
+
10
*
log
(
A
(
k
)
)
*
fftshift
(
fft
(
sin
(
2
*
pi
*
f
(
k
)
*
t
)));
end
end
x_synth2
=
ifft
(
nu
)
x_synth2
=
ifft
(
nu
)/
max
(
abs
(
ifft
(
nu
)));
plot
(
t
,
x_synth2
)
plot
(
t
,
x_synth2
);
title
(
'Nouveau signal'
)
xlabel
(
'Temps (s)'
)
ylabel
(
'Signal normalisé'
)
%}
%{
fe
=
44100
;
% fréquence d’échantillonnage
fe
=
44100
;
% fréquence d’échantillonnage
T
=
1
/
440
;
% période = 1/f0 = La4
T
=
1
/
440
;
% période = 1/f0 = La4
D
=
100
*
T
;
D
=
100
*
T
;
...
@@ -148,34 +175,36 @@ figure;
...
@@ -148,34 +175,36 @@ figure;
subplot
(
2
,
1
,
1
);
subplot
(
2
,
1
,
1
);
plot
(
f
,
(
X_carre
));
plot
(
f
,
(
X_carre
));
title
(
'Spectre signal carré'
);
title
(
'Spectre signal carré'
);
xlabel
(
'Fréquence (Hz)'
);
ylabel
(
'Amplitude
(dB)
'
);
xlabel
(
'Fréquence (Hz)'
);
ylabel
(
'Amplitude'
);
xlim
([
0
5000
]);
xlim
([
0
5000
]);
subplot
(
2
,
1
,
2
);
subplot
(
2
,
1
,
2
);
plot
(
f
,
(
X_saw
));
plot
(
f
,
(
X_saw
));
title
(
'Spectre signal dent de scie'
);
title
(
'Spectre signal dent de scie'
);
xlabel
(
'Fréquence (Hz)'
);
ylabel
(
'Amplitude
(dB)
'
);
xlabel
(
'Fréquence (Hz)'
);
ylabel
(
'Amplitude'
);
xlim
([
0
5000
]);
xlim
([
0
5000
]);
%}
%{
% Signal d’entrée : signal dent de scie
% Signal d’entrée : signal dent de scie
fe
=
44100
;
fe
=
44100
;
f0
=
10
;
f0
=
10
;
D
=
100
/
f0
;
D
=
100
/
f0
;
t
=
linspace
(
0
,
D
,
D
*
fe
);
t
=
linspace
(
0
,
D
,
D
*
fe
);
x
=
sawtooth
(
2
*
pi
*
f0
*
t
);
%
x = sawtooth(2*pi*f0*t);
z
=
square
(
2
*
pi
*
f0
*
t
);
z
=
square
(
2
*
pi
*
f0
*
t
);
% Filtrage passe-bas d’ordre 1
% Filtrage passe-bas d’ordre 1
b
=
[
0.5
0.5
];
b
=
[
0.5
0.5
];
a
=
1
;
a
=
1
;
y
=
filter
(
b
,
a
,
x
);
%
y = filter(b, a, x);
w
=
filter
(
b
,
a
,
z
);
w
=
filter
(
b
,
a
,
z
);
% FFT
% FFT
N
=
length
(
x
);
N
=
length
(
x
);
X
=
fftshift
(
abs
(
fft
(
x
))/
N
);
%
X = fftshift(abs(fft(x))/N);
Y
=
fftshift
(
abs
(
fft
(
y
))/
N
);
%
Y = fftshift(abs(fft(y))/N);
Z
=
fftshift
(
abs
(
fft
(
z
))/
N
);
Z
=
fftshift
(
abs
(
fft
(
z
))/
N
);
W
=
fftshift
(
abs
(
fft
(
w
))/
N
);
W
=
fftshift
(
abs
(
fft
(
w
))/
N
);
f
=
linspace
(
-
fe
/
2
,
fe
/
2
,
N
);
f
=
linspace
(
-
fe
/
2
,
fe
/
2
,
N
);
...
@@ -183,28 +212,53 @@ f = linspace(-fe/2, fe/2, N);
...
@@ -183,28 +212,53 @@ f = linspace(-fe/2, fe/2, N);
% Affichage
% Affichage
figure
;
figure
;
plot
(
f
,
2
0
*
log
10
(
X
),
'b'
);
hold
on
;
%
plot(f,
1
0*log(X), 'b'); hold on;
plot
(
f
,
2
0
*
log
10
(
Y
),
'r'
);
%
plot(f,
1
0*log(Y), 'r');
legend
(
'Entrée (signal brut)'
,
'Sortie filtrée'
);
%
legend('Entrée (signal brut)', 'Sortie filtrée');
xlabel
(
'Fréquence (Hz)'
);
%
xlabel('Fréquence (Hz)');
ylabel
(
'Amplitude (dB)'
);
%
ylabel('Amplitude (dB)');
title
(
'Spectre avant et après filtrage passe-bas'
);
%
title('Spectre avant et après filtrage passe-bas');
xlim
([
0
5000
]);
%
xlim([0 5000]);
figure
;
figure
;
plot
(
f
,
2
0
*
log
(
Z
),
'b'
);
hold
on
;
plot
(
f
,
1
0
*
log
(
Z
),
'b'
);
hold
on
;
plot
(
f
,
2
0
*
log
(
W
),
'r'
);
plot
(
f
,
1
0
*
log
(
W
),
'r'
);
figure
(
2
);
figure
(
2
);
legend
(
'Entrée (signal brut)'
,
'Sortie filtrée'
);
legend
(
'Entrée (signal brut)'
,
'Sortie filtrée'
);
xlabel
(
'Fréquence (Hz)'
);
xlabel
(
'Fréquence (Hz)'
);
ylabel
(
'Amplitude
(dB)
'
);
ylabel
(
'Amplitude'
);
title
(
'Spectre avant et après filtrage passe-bas'
);
title
(
'Spectre avant et après filtrage passe-bas'
);
xlim
([
0
5000
]);
xlim
([
0
5000
]);
soundsc
(
w
,
fe
)
soundsc
(
w
,
fe
)
audiowrite
(
'square_filtre.wav'
,
w
,
fe
);
audiowrite
(
'square_filtre.wav'
,
w
,
fe
);
%}
%{
% Signal d’entrée : signal dent de scie
fe
=
44100
;
f0
=
10
;
D
=
100
/
f0
;
t
=
linspace
(
0
,
D
,
D
*
fe
);
%x = sawtooth(2*pi*f0*t);
z
=
square
(
2
*
pi
*
f0
*
t
);
% Filtrage passe-bas d’ordre 1
b
=
[
0.5
0.5
];
a
=
1
;
%y = filter(b, a, x);
w
=
filter
(
b
,
a
,
z
);
% FFT
N
=
length
(
x
);
%X = fftshift(abs(fft(x))/N);
%Y = fftshift(abs(fft(y))/N);
Z
=
fftshift
(
abs
(
fft
(
z
))/
N
);
W
=
fftshift
(
abs
(
fft
(
w
))/
N
);
f
=
linspace
(
-
fe
/
2
,
fe
/
2
,
N
);
d
=
designfilt
(
'lowpassiir'
,
'FilterOrder'
,
3
,
'HalfPowerFrequency'
,
1
);
d
=
designfilt
(
'lowpassiir'
,
'FilterOrder'
,
3
,
'HalfPowerFrequency'
,
1
);
...
@@ -213,8 +267,8 @@ y_2 = filter(d,z);
...
@@ -213,8 +267,8 @@ y_2 = filter(d,z);
Y_2
=
fftshift
(
abs
(
fft
(
y_2
))/
N
);
Y_2
=
fftshift
(
abs
(
fft
(
y_2
))/
N
);
figure
;
figure
;
plot
(
f
,
2
0
*
log10
(
X
),
'b'
);
hold
on
;
plot
(
f
,
1
0
*
log10
(
X
),
'b'
);
hold
on
;
plot
(
f
,
2
0
*
log10
(
Y_2
),
'r'
);
plot
(
f
,
1
0
*
log10
(
Y_2
),
'r'
);
legend
(
'Entrée (signal brut)'
,
'Sortie filtrée'
);
legend
(
'Entrée (signal brut)'
,
'Sortie filtrée'
);
xlabel
(
'Fréquence (Hz)'
);
xlabel
(
'Fréquence (Hz)'
);
ylabel
(
'Amplitude (dB)'
);
ylabel
(
'Amplitude (dB)'
);
...
@@ -224,16 +278,17 @@ xlim([0 5000]);
...
@@ -224,16 +278,17 @@ xlim([0 5000]);
soundsc
(
y_2
,
fe
);
soundsc
(
y_2
,
fe
);
%}
%}
load
(
'signal_excitation.mat'
);
%{
%{
plot
(
xcorr
(
xe1
,
xe1
))
plot
(
xcorr
(
xe2
,
xe2
))
load
(
'signal_excitation.mat'
);
load
(
'signal_excitation.mat'
);
plot
(
xcorr
(
xe1
,
xe1
));
title
(
'Autocorrélation du signal xe1'
);
plot
(
xcorr
(
xe2
,
xe2
));
title
(
'Autocorrélation du signal xe2'
);
y
=
simule_piece
(
xe1
,
fe
);
y
=
simule_piece
(
xe1
,
fe
);
plot
(
xcorr
(
y
,
xe1
));
plot
(
xcorr
(
y
,
xe1
));
%}
title
(
'Réponse impulsionnelle'
)
[
x_test
,
fe_test
]
=
audioread
(
'/homes/t24dherv/Documents/SAR_audio/single_tone_guitar_nylon_string_a3.wav'
);
[
x_test
,
fe_test
]
=
audioread
(
'/homes/t24dherv/Documents/SAR_audio/single_tone_guitar_nylon_string_a3.wav'
);
soundsc
(
x_test
,
fe_test
);
soundsc
(
x_test
,
fe_test
);
...
@@ -244,4 +299,86 @@ y = conv(xe1,x_test(:,2));
...
@@ -244,4 +299,86 @@ y = conv(xe1,x_test(:,2));
%plot(y);
%plot(y);
soundsc
(
y
,
fe
);
soundsc
(
y
,
fe
);
\ No newline at end of file
%}
%{
function
y
=
effet_reverb
(
x
,
h
);
y
=
conv
(
x
,
h
);
y
=
y
/
max
(
abs
(
y
));
end
% Charger le signal source (guitare)
[
x4
,
fe4
]
=
audioread
(
'/homes/t24dherv/Documents/SAR_audio/single_tone_piano2.wav'
);
% Charger la réponse impulsionnelle estimée
y
=
simule_piece
(
xe1
,
fe
);
% Mesurer le temps de calcul
tic
;
w
=
effet_reverb
(
x
,
y
);
t_exec
=
toc
;
% Afficher le temps mesuré
fprintf
(
'Temps d_exécution de effet_reverb : %.6f secondes\n'
,
t_exec
);
% Lecture et sauvegarde du signal réverbéré
soundsc
(
w
,
fe
);
audiowrite
(
'guitare_reverberee.wav'
,
w
,
fe
);
%}
fe
=
44100
;
f0
=
440
;
t
=
linspace
(
0
,
D
,
D
*
fe
);
function
y
=
effet_reverb_FFT
(
x
,
h
)
% Réverbération par convolution dans le domaine fréquentiel
% Taille minimale de FFT
NFFT
=
max
(
length
(
x
),
length
(
h
));
% Chronométrage
tic
;
% FFT des deux signaux
X
=
fft
(
x
,
NFFT
);
H
=
fft
(
h
,
NFFT
);
% Multiplication dans le domaine fréquentiel
Y
=
X
.*
H
;
% Retour dans le domaine temporel
y
=
ifft
(
Y
,
NFFT
);
y
=
real
(
y
);
% Supprimer éventuelles parties imaginaires
y
=
y
/
max
(
abs
(
y
));
% Normalisation
% Affichage du temps d'exécution
t_exec
=
toc
;
fprintf
(
'Temps d
''
exécution (FFT) : %.6f secondes\n'
,
t_exec
);
end
% Charger le signal source (guitare)
[
x4
,
fe4
]
=
audioread
(
'/homes/t24dherv/Documents/SAR_audio/single_tone_piano2.wav'
);
% Charger la réponse impulsionnelle estimée
y
=
simule_piece
(
xe1
,
fe
);
% Mesurer le temps de calcul
tic
;
w
=
effet_reverb_FFT
(
x4
,
y
);
t_exec
=
toc
;
% Afficher le temps mesuré
fprintf
(
'Temps d_exécution de effet_reverb : %.6f secondes\n'
,
t_exec
);
% Lecture et sauvegarde du signal réverbéré
soundsc
(
w
,
fe
);
audiowrite
(
'guitare_reverberee.wav'
,
w
,
fe
);
plot
(
linspace
(
0
,
1
,
length
(
w
)),
w
)
\ 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