Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
T
tp-audio-ee-etudiant-m24duboc
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-m24duboc
tp-audio-ee-etudiant-m24duboc
Commits
f03d9ab9
Commit
f03d9ab9
authored
1 month ago
by
DUBOC Marc
Browse files
Options
Downloads
Patches
Plain Diff
Upload New File
parent
96a3ac68
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
PARTIE2.m
+115
-0
115 additions, 0 deletions
PARTIE2.m
with
115 additions
and
0 deletions
PARTIE2.m
0 → 100644
+
115
−
0
View file @
f03d9ab9
%% ========================================================================
% PARTIE 2 — Synthese soustractive (Q 2.1 → Q 2.4)
% Poly « SAR – Traitements audio : partie signal » v1.0 (23 avril 2025)
% ------------------------------------------------------------------------
% Script sans caractere underscore, corrige pour l erreur designfilt.
% ------------------------------------------------------------------------
clear
;
close
all
;
clc
Fe
=
44100
;
% frequence d echantillonnage (Hz)
addpath
(
pwd
)
% acces aux fichiers wav
%% ========================================================================
%% Q 2.1 — Spectres carre et dent de scie
% -------------------------------------------------------------------------
dur
=
0.1
;
f0
=
440
;
t
=
(
0
:
1
/
Fe
:
dur
-
1
/
Fe
)
.'
;
xCarre
=
square
(
2
*
pi
*
f0
*
t
);
xScie
=
sawtooth
(
2
*
pi
*
f0
*
t
);
figure
(
'Name'
,
'Q2-1 Spectres'
);
hold
on
plotSpectrum
(
xCarre
,
Fe
,
'b'
,
'Carre FFT'
);
plotSpectrum
(
xScie
,
Fe
,
'r'
,
'Scie FFT'
);
nH
=
20
;
stem
(
f0
*
(
1
:
2
:(
2
*
nH
-
1
)),
20
*
log10
(
abs
(
4.
/(
pi
*
(
1
:
2
:(
2
*
nH
-
1
))))),
...
'k.'
,
'DisplayName'
,
'Carre theorie'
);
stem
(
f0
*
(
1
:
nH
),
20
*
log10
(
abs
(
2.
/(
pi
*
(
1
:
nH
)))
),
...
'm.'
,
'DisplayName'
,
'Scie theorie'
);
xlim
([
0
8
*
f0
]);
grid
on
;
legend
xlabel
(
'Frequence (Hz)'
);
ylabel
(
'|X| (dB)'
);
title
(
'Q 2.1 Spectres normalises'
);
%% ========================================================================
%% Q 2.2 — Filtre passe-bas ordre 1 : theorie et test
% -------------------------------------------------------------------------
dur
=
0.1
;
t
=
(
0
:
1
/
Fe
:
dur
-
1
/
Fe
)
.'
;
x
=
sawtooth
(
2
*
pi
*
f0
*
t
);
b
=
[
0.5
0.5
];
a
=
1
;
[
H
,
w
]
=
freqz
(
b
,
a
,
4096
,
'whole'
,
Fe
);
figure
(
'Name'
,
'Q2-2 Filtre ordre 1'
);
subplot
(
2
,
1
,
1
)
plot
(
w
,
20
*
log10
(
abs
(
H
)));
grid
on
title
(
'|H| theorique cos(w/2)'
);
xlabel
(
'f (Hz)'
);
ylabel
(
'dB'
)
y
=
filter
(
b
,
a
,
x
);
subplot
(
2
,
1
,
2
);
hold
on
plotSpectrum
(
x
,
Fe
,
'k'
,
'Entree'
);
plotSpectrum
(
y
,
Fe
,
'g'
,
'Sortie'
);
xlim
([
0
6
*
f0
]);
grid
on
;
legend
title
(
'Spectre dB verification'
);
soundsc
([
x
y
],
Fe
);
% gauche brut, droite filtre
%% ========================================================================
%% Q 2.3 — Ecoute comparative (sources + LPF)
% -------------------------------------------------------------------------
forms
=
{
'square'
,
'sawtooth'
,
'triangle'
};
fprintf
(
'\n===== Q 2.3 ecoute comparative =====\n'
);
pause
(
0.4
)
for
k
=
1
:
numel
(
forms
)
dur
=
0.5
;
t
=
(
0
:
1
/
Fe
:
dur
-
1
/
Fe
)
.'
;
switch
forms
{
k
}
case
'triangle'
x
=
sawtooth
(
2
*
pi
*
f0
*
t
,
0.5
)
.^
2
.*
sign
(
sin
(
2
*
pi
*
f0
*
t
));
otherwise
x
=
feval
(
forms
{
k
},
2
*
pi
*
f0
*
t
);
end
y
=
filter
(
b
,
a
,
x
);
fprintf
(
'-- %s non filtre ...\n'
,
forms
{
k
});
soundsc
(
x
,
Fe
);
pause
(
dur
+
0.25
)
fprintf
(
'-- %s filtre ...\n'
,
forms
{
k
});
soundsc
(
y
,
Fe
);
pause
(
dur
+
0.25
)
end
fprintf
(
'===== fin Q 2.3 =====\n'
);
%% ========================================================================
%% Q 2.4 — Variation Fc, ordre, FIR ou IIR
% -------------------------------------------------------------------------
dur
=
1
;
t
=
(
0
:
1
/
Fe
:
dur
-
1
/
Fe
)
.'
;
x
=
sawtooth
(
2
*
pi
*
110
*
t
);
% scie grave (La1)
% Parametres adaptes pour eviter l erreur designfilt
dFIR8
=
designfilt
(
'lowpassfir'
,
'FilterOrder'
,
8
,
'HalfPowerFrequency'
,
0.30
);
dFIR30
=
designfilt
(
'lowpassfir'
,
'FilterOrder'
,
30
,
'HalfPowerFrequency'
,
0.15
);
dIIR
=
designfilt
(
'lowpassiir'
,
'FilterOrder'
,
8
,
'HalfPowerFrequency'
,
0.20
,
...
'DesignMethod'
,
'butter'
);
bank
=
{
dFIR8
,
'FIR N=8 Fc=0.30'
;
...
dFIR30
,
'FIR N=30 Fc=0.15'
;
...
dIIR
,
'IIR Butter N=8 Fc=0.20'
};
fprintf
(
'\n===== Q 2.4 ecoute des filtres =====\n'
);
for
k
=
1
:
size
(
bank
,
1
)
y
=
filter
(
bank
{
k
,
1
},
x
);
fprintf
(
'-- %s ...\n'
,
bank
{
k
,
2
});
soundsc
(
y
,
Fe
);
pause
(
dur
+
0.35
)
end
figure
(
'Name'
,
'Q2-4 Reponses en frequence'
);
hold
on
for
k
=
1
:
size
(
bank
,
1
)
[
h
,
w
]
=
freqz
(
bank
{
k
,
1
},
4096
,
Fe
);
plot
(
w
,
20
*
log10
(
abs
(
h
)),
'DisplayName'
,
bank
{
k
,
2
});
end
grid
on
;
xlabel
(
'f (Hz)'
);
ylabel
(
'dB'
);
legend
title
(
'Filtres FIR et IIR influence de Fc et de l ordre'
);
fprintf
(
'===== fin Q 2.4 =====\n'
);
%% ========================================================================
%% === Fonction locale =====================================================
function
plotSpectrum
(
x
,
Fe
,
color
,
label
)
N
=
length
(
x
);
f
=
(
-
N
/
2
:
N
/
2
-
1
)
*
Fe
/
N
;
X
=
fftshift
(
fft
(
x
.*
hann
(
N
)));
SdB
=
20
*
log10
(
abs
(
X
)/
max
(
abs
(
X
))
+
eps
);
plot
(
f
,
SdB
,
color
,
'LineWidth'
,
1.2
,
'DisplayName'
,
label
);
end
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