Obisidian vault auto-backup: 06-01-2026 13:44:16 on . 4 files edited

This commit is contained in:
2026-01-06 13:44:16 +01:00
parent b6655a7e71
commit 6819a1a59b
4 changed files with 142 additions and 13 deletions

View File

@@ -219,17 +219,17 @@
},
"active": "8beea5ef99c3c6ed",
"lastOpenFiles": [
"ISEN/Traitement du signal/CIPA4/TP/TP3/~WRL2809.tmp",
"ISEN/Traitement du signal/CIPA4/TP/TP3/~WRD2801.tmp",
"ISEN/Traitement du signal/CIPA4/TP/TP3/TP3_Experience3.m",
"ISEN/Traitement du signal/CIPA4/TP/TP3/Copy_of_TP3_Experience2.m",
"ISEN/Traitement du signal/CIPA4/TP/TP3/~WRD2818.tmp",
"ISEN/Traitement du signal/CIPA4/TP/TP3/~WRL1378.tmp",
"ISEN/Traitement du signal/CIPA4/TP/TP3/~WRD1374.tmp",
"ISEN/Traitement du signal/CIPA4/TP/TP3/~WRL2201.tmp",
"ISEN/Traitement du signal/CIPA4/TP/TP3/~WRD2193.tmp",
"ISEN/Traitement du signal/CIPA4/TP/TP3/TP3_Experience2.m",
"ISEN/Traitement du signal/CIPA4/TP/TP3/Copy_of_TP3_Experience1.m",
"ISEN/Traitement du signal/CIPA4/TP/TP3/~WRL0005.tmp",
"ISEN/Traitement du signal/CIPA4/TP/TP3/~WRD0004.tmp",
"ISEN/Traitement du signal/CIPA4/TP/TP3/E71marquet.wav",
"ISEN/Traitement du signal/CIPA4/TP/TP3/~WRL0003.tmp",
"ISEN/Traitement du signal/CIPA4/TP/TP3/~WRD0002.tmp",
"ISEN/Réseau/CIPA4/TP/TP M02 Conversion.md",
"Protocol Data Units (PDU).md",
"ISEN/English/CIPA4/Elevator pitch.md",

View File

@@ -3,7 +3,7 @@
% - Sampling period Ts = 0.13*T
% - Add narrowband jamming at 800 Hz and white noise
% - Design IIR notch filter (order 15 then 5) to remove the jamming tone
% - Use subplot to show time-domain signal and magnitude spectrum. [web:216][web:223]
% - Use subplot to show time-domain signal and magnitude spectrum.
clc;
clear;
@@ -14,7 +14,7 @@ close all;
T = 2e-3; % Symbol period (s)
beta = 0.5; % Roll-off factor
Ts = 0.13 * T; % Sampling period (s)
Fs = 1 / Ts; % Sampling frequency (Hz) [web:202]
Fs = 1 / Ts; % Sampling frequency (Hz)
t = -10*T : Ts : 10*T; % Time vector
N = length(t);
@@ -23,11 +23,11 @@ f_axis = (-N/2 : N/2-1) * (Fs / N); % Hz
%% 2) Raised cosine pulse h(t)
h = arrayfun(@(tt) raisedCosineSample(tt, T, beta), t); % [web:223]
h = arrayfun(@(tt) raisedCosineSample(tt, T, beta), t);
% Time-domain h(t) and magnitude spectrum
H = fft(h);
magH = abs(fftshift(H)); % magnitude, zero frequency at center [web:202]
magH = abs(fftshift(H)); % magnitude, zero frequency at center
figure('Name','Experiment 2 - h(t) and |H(f)|');
subplot(2,1,1);
@@ -49,7 +49,7 @@ grid on;
fJam = 800; % Jamming frequency (Hz)
x = 0.2 * cos(2*pi*fJam*t); % narrowband jamming (adjust amplitude if needed)
n = 0.02 * randn(size(t)); % ambient white noise (low level) [web:223]
n = 0.02 * randn(size(t)); % ambient white noise (low level)
z = h + x + n; % corrupted signal
@@ -74,7 +74,7 @@ grid on;
%% 4) Design 15th-order notch (bandstop) filter at 800 Hz (no butter)
% We build an IIR notch with zeros at exp(±j*w0) and poles at r*exp(±j*w0),
% then cascade enough sections to reach an effective order 15. [web:238]
% then cascade enough sections to reach an effective order 15.
w0 = 2*pi*fJam/Fs; % digital radian frequency
r = 0.98; % pole radius (controls notch width)
@@ -150,7 +150,7 @@ grid on;
function h = raisedCosineSample(t, T, beta)
% Raised cosine pulse sample at time t (scalar).
% h(t) = sinc(t/T) * cos(pi*beta*t/T) / (1 - (4*beta^2*t^2)/T^2)
% with sinc(x) = sin(pi*x)/(pi*x). [web:216][web:223]
% with sinc(x) = sin(pi*x)/(pi*x).
x = t / T;
@@ -165,7 +165,7 @@ function h = raisedCosineSample(t, T, beta)
if abs(t) < 1e-12
h = 1;
elseif beta ~= 0 && abs(abs(t) - T/(2*beta)) < 1e-12
h = (beta/pi) * sin(pi/(2*beta)); % limit at t = ±T/(2*beta) [web:223]
h = (beta/pi) * sin(pi/(2*beta)); % limit at t = ±T/(2*beta)
else
h = sx * cos(pi*beta*x) / (1 - (4*beta^2*x^2));
end

View File

@@ -0,0 +1,129 @@
%% Experiment 3 : Modulation and demodulation of a guitar signal
% Load guitar signal y(t) from 'guitar.wav'
% Fmod = 8820 Hz
% ym(t) = y(t) * sin(2*pi*Fmod*t)
% ys(t) = ym(t) * sin(2*pi*Fmod*t)
% yc(t) = ym(t) * cos(2*pi*Fmod*t)
% Plot amplitude spectrum of y, ym, ys, yc and listen to each.
clc;
clear;
close all;
%% 1) Load audio file
[y, Fs] = audioread('guitar.wav'); % y: audio vector, Fs: sampling rate
if size(y,2) > 1
y = mean(y,2); % convert to mono if stereo
end
N = length(y);
t = (0:N-1)/Fs; % time vector
Fmod = 8820; % modulation frequency in Hz
%% 2) Generate modulated signals
ym = y .* sin(2*pi*Fmod*t.'); % column vector; DSB-SC around ±Fmod
ys = ym .* sin(2*pi*Fmod*t.'); % second multiplication by sin
yc = ym .* cos(2*pi*Fmod*t.'); % multiplication by cos
%% 3) Helper to compute single-sided amplitude spectrum |Y(f)|
computeSpec = @(sig) ...
deal( ...
(0:floor(length(sig)/2)) * (Fs/length(sig)), ... % f axis
abs(fft(sig)) / length(sig) ... % scale
);
[f_y, P_y] = computeSpec(y);
[f_ym, P_ym] = computeSpec(ym);
[f_ys, P_ys] = computeSpec(ys);
[f_yc, P_yc] = computeSpec(yc);
P_y = P_y(1:length(f_y));
P_ym = P_ym(1:length(f_ym));
P_ys = P_ys(1:length(f_ys));
P_yc = P_yc(1:length(f_yc));
%% 4) Plot amplitude spectra
figure('Name','Amplitude spectra of y, ym, ys, yc');
subplot(4,1,1);
plot(f_y, P_y(1:numel(f_y)), 'g');
xlim([0 Fs/2]);
xlabel('Frequency (Hz)');
ylabel('|Y(f)|');
title('Original signal y(t) - spectrum');
grid on;
subplot(4,1,2);
plot(f_ym, P_ym(1:numel(f_ym)), 'g');
xlim([0 Fs/2]);
xlabel('Frequency (Hz)');
ylabel('|Y_m(f)|');
title('ym(t) = y(t) * sin(2\pi F_{mod} t)');
grid on;
subplot(4,1,3);
plot(f_ys, P_ys(1:numel(f_ys)), 'g');
xlim([0 Fs/2]);
xlabel('Frequency (Hz)');
ylabel('|Y_s(f)|');
title('ys(t) = ym(t) * sin(2\pi F_{mod} t)');
grid on;
subplot(4,1,4);
plot(f_yc, P_yc(1:numel(f_yc)), 'g');
xlim([0 Fs/2]);
xlabel('Frequency (Hz)');
ylabel('|Y_c(f)|');
title('yc(t) = ym(t) * cos(2\pi F_{mod} t)');
grid on;
%% 5) Listen to the signals (uncomment in MATLAB to hear)
% sound(y, Fs); pause(length(y)/Fs + 1);
% sound(ym, Fs); pause(length(y)/Fs + 1);
% sound(ys, Fs); pause(length(y)/Fs + 1);
% sound(yc, Fs);
%% 6) Demodulation to recover original sound
% Theory:
% - ym(t) = y(t)*sin(2*pi*Fmod*t) is DSB-SC modulation.
% - Multiplying again by sin(2*pi*Fmod*t) gives:
% ys(t) = ym(t)*sin(2*pi*Fmod*t)
% = y(t)*sin^2(2*pi*Fmod*t)
% = 0.5*y(t) - 0.5*y(t)*cos(4*pi*Fmod*t)
% => low-frequency term 0.5*y(t) + high-frequency image around 2*Fmod.
% - A low-pass filter on ys(t) recovers a scaled version of y(t).
%
% So ys(t) is the best candidate for demodulation.
% Simple low-pass filter: moving average (FIR) without toolboxes.
% Choose window length so cut-off is << Fmod (keep audio band, remove 2*Fmod).
LpOrder = 101; % odd length for symmetry
h_lp = ones(LpOrder,1)/LpOrder; % simple averaging filter
y_rec = filter(h_lp, 1, ys); % demodulated / low-passed version
% Optionally compensate scaling (~0.5) by multiplying by 2
y_rec = 2 * y_rec;
%% 7) Spectrum of demodulated signal
[f_rec, P_rec] = computeSpec(y_rec);
P_rec = P_rec(1:length(f_rec));
figure('Name','Demodulated signal spectrum');
plot(f_rec, P_rec, 'g');
xlim([0 Fs/2]);
xlabel('Frequency (Hz)');
ylabel('|Y_{rec}(f)|');
title('Amplitude spectrum of demodulated signal (approx. original y(t))');
grid on;
%% 8) Listen to recovered sound (optional)
% sound(y_rec, Fs);