-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMain.m
66 lines (52 loc) · 2.2 KB
/
Main.m
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
%% Test case I
%{
%Reading the audio signal
[signal, fm] = audioread('input_audio.wav');
input_signal = signal(:,1); %only the left channel of the input signal
sound(input_signal, fm);
%Sampler
fs = 40e2; %the required sampling rate
[t, sampled_signal, Fs] = sampler(input_signal, fm, fs);
%Quantizer
quantization_mode = 0; %Mid-rise
L = 256; %the number of quantization levels
[quantized_signal, mean_sqr_q_error, bit_stream, mp_max, mp_min, R] = quantizer(sampled_signal, t, L, quantization_mode);
%Encoder
pulse_amplitude = 5;
line_code = 1;
bit_rate = 10000;
n = 100;
[PCM_t, PCM_signal] = encoder(Fs, R, bit_stream, pulse_amplitude, line_code, bit_rate, n) ;
%Neither Channel nor regenerative repeaters are included (in this test case)
%Decoder
[restored_bit_stream, restored_quantized_signal] = decoder(t, PCM_signal, mp_max, mp_min, L, quantization_mode, line_code, n, pulse_amplitude);
sound(restored_quantized_signal, Fs);
%}
%% Test case II
%Reading the audio signal
[signal, fm] = audioread('input_audio.wav');
input_signal = signal(:,1); %only the left channel of the input signal
sound(input_signal, fm);
%Sampler
fs = 50e2; %the required sampling rate
[t, sampled_signal, Fs] = sampler(input_signal, fm, fs);
%Quantizer
quantization_mode = 1;
L = 256; %the number of quantization levels
[quantized_signal, mean_sqr_q_error, bit_stream, mp_max, mp_min, R] = quantizer(sampled_signal, t, L, quantization_mode);
%Encoder
line_code = 1;
pulse_amplitude = 5;
bit_rate = 10000;
n = 100;
[PCM_t, PCM_signal] = encoder(Fs, R, bit_stream, pulse_amplitude, line_code, bit_rate, n) ;
%Channel
N0 = 4; %noise power (variance)
noisy_signal = AWGN_channel(PCM_t, PCM_signal, N0, n);
%Regenerative repeaters
regenerated_PCM_signal = regenerative_repeater(PCM_t, noisy_signal, n, line_code, pulse_amplitude);
%Decoder
[restored_bit_stream, restored_quantized_signal] = decoder(t, regenerated_PCM_signal, mp_max, mp_min, L, quantization_mode, line_code, n, pulse_amplitude);
sound(restored_quantized_signal, Fs);
%audiowrite("restored_signal.wav", restored_quantized_signal, Fs)
%%uncomment to export the restored signal file