1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81
| clear all; fig=1;
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% dsp_bandpass %
% dspguide chapter 19, page 326 %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function [b,a] = dsp_bandpass (BW,f,fs)
R = 1 - 3*BW;
K = (1 - 2*R*cos(2*pi*f) +R*R) / (2 - 2*cos(2*pi*f));
a0 = 1 - K;
a1 = 2 * (K-R) * cos(2*pi*f);
a2 = R*R - K;
b1 = 2 * R * cos(2*pi*f);
b2 = - R*R;
b = [a0 a1 a2];
a = [1 -b1 -b2];
endfunction
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Modulation/bruitage/filtrage %
% / démodulation de code Morse %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
morse = [ 0 1 0 1 0 1 1 1 0 0 ];
fs = 5000; % Fréquence échantillonnage
fc = 1000/fs; % Fréquence porteuse 1000Hz
dot = 0.1; % Durée du point (secondes)
morse = repmat (morse,dot*fs,1);
morse = reshape (morse, 1, prod (size(morse)));
figure (fig++, 'name', 'code emis');
plot (morse); ylim ([-1,2]);
% Modulation
duree = (length(morse)-1)/fs;
time = 0:1/fs:duree;
porteuse = sin(2*pi*fc*fs*time);
signal = porteuse .* morse;
wavwrite(signal, fs, 'signal.wav');
figure (fig++, 'name', 'signal');
plot (signal); ylim ([-3,3]);
% Bruitage
bruit = 1.0; % Amplitude du bruit
signal = signal + bruit*wgn(1,size(signal,2),1);
wavwrite(signal, fs, 'signal+bruit.wav');
figure (fig++, 'name', 'signal + bruit');
plot (signal); ylim ([-3,3]);
% Filtrage
BW = 20/fs; % Largeur de bande
[b,a] = dsp_bandpass (BW,fc,fs);
filtrage = filter (b, a, signal);
wavwrite(filtrage, fs, 'filtrage.wav');
figure (fig++, 'name', 'filtrage');
plot (filtrage); ylim ([-3,3]);
% Démodulation
demod = abs( hilbert (filtrage) );
demod = tsmovavg (demod,'s',100,2);
demod = demod > 0.5;
figure (fig++, 'name', 'code recu');
plot (demod); ylim ([-1,2]); |
Partager