0% found this document useful (0 votes)
16 views4 pages

Latex

The document contains cleaned MATLAB scripts for various signal processing tasks, including audio analysis, LPC filtering, and image processing. Key operations include reading audio files, applying filters, performing FFT, and visualizing results through plots. The scripts demonstrate techniques for analyzing signals, estimating errors, and reconstructing images affected by motion blur.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
16 views4 pages

Latex

The document contains cleaned MATLAB scripts for various signal processing tasks, including audio analysis, LPC filtering, and image processing. Key operations include reading audio files, applying filters, performing FFT, and visualizing results through plots. The scripts demonstrate techniques for analyzing signals, estimating errors, and reconstructing images affected by motion blur.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

Cleaned MATLAB Scripts

tp2 2.m
[x, fs] = audioread(’d.wav’);
N = length(x);
duration = N / fs;
window = hamming(N);
xW = x .* window;
order = 50;
a = lpc(xW, order);
x_pred = filter([0 -a(2:end)], 1, xW);
t = (0:N-1) / fs;
figure;
plot(t, xW, ’b’);
hold on;
plot(t, x_pred, ’r--’);
xlabel(’Temps (s)’);
ylabel(’Amplitude’);
title(’Comparaison du Signal Original et du Signal Estimé’);
grid on;
e = xW - x_pred;
r_e = xcorr(e, ’biased’);
figure;
lags = -(N-1):(N-1);
plot(lags, r_e);
xlabel(’Lags’);
ylabel(’Autocorrélation’);
title(’Autocorrélation de l’’erreur de prédiction’);
grid on;
E_fft = abs(fftshift(fft(e)));
f = linspace(-fs/2, fs/2, length(E_fft));
figure;
plot(f, 20*log10(E_fft));
xlabel(’Fréquence (Hz)’);

1
ylabel(’Magnitude (dB)’);
title(’Transformée de Fourier de l’’erreur de prédiction’);
grid on;
E_error = sum(e.^2);
[pxx, f] = pwelch(xW, hamming(512), [], [], fs, ’power’);
figure;
plot(f, 10*log10(pxx), ’b’, ’LineWidth’, 1.5);
hold on;
xlabel(’Fréquence (Hz)’);
ylabel(’Densité spectrale de puissance (dB/Hz)’);
title(’Densité spectrale du signal xW et réponse fréquentielle du filtre LPC’);
grid on;
[H, f_response] = freqz(1, a, length(f), fs);
plot(f_response, 20*log10(abs(H)), ’r’, ’LineWidth’, 1.5);

tp2 1.m
load(’AR2.mat’);
N = length(x);
X = [-x(1:N-2), -x(2:N-1)];
y = x(3:N);
a = (X’ * X) \ (X’ * y);
a1 = a(1);
a2 = a(2);
r = xcorr(x, ’biased’);
gamma0 = r(N);
gamma1 = r(N+1);
gamma2 = r(N+2);
Gamma = [gamma0, gamma1; gamma1, gamma0];
gamma_vec = [gamma1; gamma2];
a = Gamma \ gamma_vec;
a1 = a(1);
a2 = a(2);
[x, fs] = audioread(’d.wav’);
num_samples = length(x);
duration = num_samples / fs;

2
tp3 gaussinoise.m
n = 1024;
Fs = 1;
f = load_signal("gaussiannoise", n);
sigma = 0.2 * (max(f) - min(f));
noise = sigma * randn(n, 1);
f_b = f + noise;
f_fft = fftshift(fft(f));
noise_fft = fftshift(fft(noise));
freqs = (-n/2:n/2-1) * (Fs/n);
figure;
subplot(3,1,1);
plot(f);
subplot(3,1,2);
plot(freqs, 10*log10(abs(f_fft).^2), ’b’);
hold on;
plot(freqs, 10*log10(abs(noise_fft).^2), ’r’);
subplot(3,1,3);
plot(f_b);
saveas(gcf, ’signal_bruit_DSP.png’);

TP3 2.m
img = imread(’car.jpg’);
img = im2double(img);
imshow(img);
motion_kernel = fspecial(’motion’, 35, 0);
[img_blur, OST] = convolve_image(img, motion_kernel);
figure;
imshow(img_blur);
img_blur_fft = fftn(img_blur);
img_reconstructed_fft = img_blur_fft ./ OST;
img_reconstructed = real(ifftn(img_reconstructed_fft));
figure;
imshow(img_reconstructed);

tp1 2.m
clc; clear; close all;

3
[signal, Fs] = audioread(’musique.wav’);
N = length(signal);
t = (0:N-1) / Fs;
sound(signal, Fs);
pause(length(signal)/Fs + 1);
Y = fftshift(fft(signal));
frequencies = (-N/2:N/2-1) * (Fs/N);
Y_positive = abs(Y);
figure;
plot(frequencies, Y_positive, ’b’);
xlabel(’Fréquence (Hz)’);
ylabel(’Amplitude’);
title(’Spectre du signal original’);
grid on;

tp1.m
[signal, Fs] = audioread(’sinusoides.wav’);
N = length(signal);
t = (0:N-1) / Fs;
figure;
plot(t(1:min(100,N)), signal(1:min(100,N)));
xlabel(’Temps (s)’);
ylabel(’Amplitude’);
title(’100 premiers échantillons du signal’);
grid on;
Y = fft(signal) / N;
frequencies = (0:N-1) * (Fs / N);
Y_positive = abs(Y(1:floor(N/2)));
frequencies_positive = frequencies(1:floor(N/2));
figure;
plot(frequencies_positive, Y_positive, ’r’);
xlabel(’Fréquence (Hz)’);
ylabel(’Amplitude’);
title(’Spectre du signal original’);
grid on;

You might also like