-
Notifications
You must be signed in to change notification settings - Fork 6
/
am_modulation.m
234 lines (142 loc) · 12.4 KB
/
am_modulation.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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
%{
plot_in_time
plot_in_frequency
generate_filter
env_demod
coh_demod
%}
%-------------------------------------------------clear--------------------------------------------------------------------
clc;
close all;
clear all;
%-------------------------------------------------read file--------------------------------------------------------------------
FILE = 'eric.wav';
fc = 100000;
fs_res = 5*fc;
modulation_index = 0.5;
[yt, fs]= audioread(FILE);
max_amp = max(abs(yt));
f_filter = 4000;
%-------------------------------------------------plotting--------------------------------------------------------------------
plot_in_time(yt,fs,'Signal in time domain');
%-------------------------------------------------message in frequency domain--------------------------------------------------------------------
yf = fftshift(fft(yt));
%-------------------------------------------------plotting--------------------------------------------------------------------
plot_in_frequency(real(yf),fs,'Signal in frequency domain');
%-------------------------------------------------filter--------------------------------------------------------------------
filter = generate_filter(length(yf),fs,f_filter);
yf_filtered = filter.*yf;
%-------------------------------------------------plotting--------------------------------------------------------------------
plot_in_frequency(real(filter),fs,'Filter');
plot_in_frequency(real(yf_filtered),fs,'Filtered message in frequency domain');
%-------------------------------------------------back to time domain--------------------------------------------------------------------
yt_filtered= real(ifft(ifftshift(yf_filtered)));
%-------------------------------------------------sound--------------------------------------------------------------------
%sound(yt_filtered,fs);
%-------------------------------------------------plotting--------------------------------------------------------------------
t = linspace(0,length(yt_filtered)/fs, length(yt_filtered));
plot_in_time(yt_filtered,fs, 'Filtered signal in time domain');
%-------------------------------------------------resmple--------------------------------------------------------------------
yt_resampled = resample(yt_filtered,fs_res,fs);
%-------------------------------------------------carrier signal--------------------------------------------------------------------
t_carr = linspace(0,length(yt_resampled)/fs_res, length(yt_resampled)); %(x2-x1)/(n-1) = 1/5*fc, linspace(x1,x2,n)
carrier_t = cos(2*pi*fc*t_carr).';
carrier_f = fftshift(fft(carrier_t));
%-------------------------------------------------DSBSC modulation--------------------------------------------------------------------
yt_sc = carrier_t.*yt_resampled;
yf_sc = fftshift(fft(yt_sc));
%sound(yt_sc, fs);
%-------------------------------------------------plotting--------------------------------------------------------------------
plot_in_time(yt_sc,fs_res,'DSBSC modulated signal in time domain');
plot_in_frequency(real(yf_sc),fs_res,'DSBSC modulated signal in frequency domain');
%-------------------------------------------------DSBTC modulation--------------------------------------------------------------------
max_message = max(abs(yt_resampled));
A = 2*max_message;
yt_tc = (A+yt_resampled).*carrier_t;
yf_tc = fftshift(fft(yt_tc));
%-------------------------------------------------plotting--------------------------------------------------------------------
plot_in_time(yt_tc,fs_res,'DSBTC modulated signal in time domain');
plot_in_frequency(real(yf_tc),fs_res,'DSBTC modulated signal in frequency domain');
%sound(yt_tc,fs);
%-------------------------------------------------DSBSC envelope detector demodulation--------------------------------------------------------------------
[yt_sc_env, yf_sc_env] = env_demod(yt_sc,fs_res,fs,0,0);
%-------------------------------------------------plotting--------------------------------------------------------------------
plot_in_time(yt_sc_env, fs, 'DSBSC demodulated signal in time domain using envelope detector');
plot_in_frequency(real(yf_sc_env), fs, 'DSBSC demodulated signal in frequency domain using envelope detector');
%-------------------------------------------------sound--------------------------------------------------------------------
%sound(yt_sc_env,fs); %should not be good
%#################################################################################################################################################################
%-------------------------------------------------DSBTC no snr envelope detector demodulation--------------------------------------------------------------------
[yt_tc_env, yf_tc_env] = env_demod(yt_tc,fs_res,fs,0,0);
%-------------------------------------------------plotting--------------------------------------------------------------------
plot_in_time(yt_tc_env, fs, 'DSBTC demodulated signal no snr, in time domain using envelope detector');
plot_in_frequency(real(yf_tc_env), fs, 'DSBTC demodulated signal no snr in frequency domain using envelope detector');
%-------------------------------------------------sound--------------------------------------------------------------------
%sound(yt_tc_env,fs); %should be good
%-------------------------------------------------DSBTC 0 snr envelope detector demodulation--------------------------------------------------------------------
[yt_tc_env, yf_tc_env] = env_demod(yt_tc,fs_res,fs,1,0);
%-------------------------------------------------plotting--------------------------------------------------------------------
plot_in_time(yt_tc_env, fs, 'DSBTC demodulated signal snr=0, in time domain using envelope detector');
plot_in_frequency(real(yf_tc_env), fs, 'DSBTC demodulated signal snr=0, in frequency domain using envelope detector');
%-------------------------------------------------sound--------------------------------------------------------------------
%sound(yt_tc_env,fs);
%-------------------------------------------------DSBTC 10 snr envelope detector demodulation--------------------------------------------------------------------
[yt_tc_env, yf_tc_env] = env_demod(yt_tc,fs_res,fs,1,10);
%-------------------------------------------------plotting--------------------------------------------------------------------
plot_in_time(yt_tc_env, fs, 'DSBTC demodulated signal snr=10, in time domain using envelope detector');
plot_in_frequency(real(yf_tc_env), fs, 'DSBTC demodulated signal snr=10, in frequency domain using envelope detector');
%-------------------------------------------------sound--------------------------------------------------------------------
%sound(yt_tc_env,fs);
%-------------------------------------------------DSBTC 30 snr envelope detector demodulation--------------------------------------------------------------------
[yt_tc_env, yf_tc_env] = env_demod(yt_tc,fs_res,fs,1,30);
%-------------------------------------------------plotting--------------------------------------------------------------------
plot_in_time(yt_tc_env, fs, 'DSBTC demodulated signal snr=30, in time domain using envelope detector');
plot_in_frequency(real(yf_tc_env), fs, 'DSBTC demodulated signal snr=30, in frequency domain using envelope detector');
%-------------------------------------------------sound--------------------------------------------------------------------
%sound(yt_tc_env,fs);
%#################################################################################################################################################################
%#################################################################################################################################################################
%-------------------------------------------------DSBSC no snr coherent demodulation--------------------------------------------------------------------
[yt_sc_coh, yf_sc_coh] = coh_demod(yt_sc,fs_res,fs,0,0,fc,0,f_filter);
%-------------------------------------------------plotting--------------------------------------------------------------------
plot_in_time(real(yt_sc_coh), fs, 'DSBSC demodulated signal no snr in time domain using coherent detector');
plot_in_frequency(real(yf_sc_coh), fs, 'DSBSC demodulated signal no snr in frequency domain using coherent detector');
%-------------------------------------------------sound--------------------------------------------------------------------
% sound(real(yt_sc_coh),fs); %should be good
%-------------------------------------------------DSBSC 0 snr coherent demodulation--------------------------------------------------------------------
[yt_sc_coh, yf_sc_coh] = coh_demod(yt_sc,fs_res,fs,1,0,fc,0,f_filter);
%-------------------------------------------------plotting--------------------------------------------------------------------
plot_in_time(real(yt_sc_coh), fs, 'DSBSC demodulated signal snr=0, in time domain using coherent detector');
plot_in_frequency(real(yf_sc_coh), fs, 'DSBSC demodulated signal snr=0, in frequency domain using coherent detector');
%-------------------------------------------------sound--------------------------------------------------------------------
%sound(real(yt_sc_coh),fs); %should be good
%-------------------------------------------------DSBSC 10 snr coherent demodulation--------------------------------------------------------------------
[yt_sc_coh, yf_sc_coh] = coh_demod(yt_sc,fs_res,fs,1,10,fc,0,f_filter);
%-------------------------------------------------plotting--------------------------------------------------------------------
plot_in_time(real(yt_sc_coh), fs, 'DSBSC demodulated signal snr=10, in time domain using coherent detector');
plot_in_frequency(real(yf_sc_coh), fs, 'DSBSC demodulated signal snr=10, in frequency domain using coherent detector');
%-------------------------------------------------sound--------------------------------------------------------------------
%sound(real(yt_sc_coh),fs);
%-------------------------------------------------DSBSC 30 snr coherent demodulation--------------------------------------------------------------------
[yt_sc_coh, yf_sc_coh] = coh_demod(yt_sc,fs_res,fs,1,30,fc,0,f_filter);
%-------------------------------------------------plotting--------------------------------------------------------------------
plot_in_time(real(yt_sc_coh), fs, 'DSBSC demodulated signal snr=30, in time domain using coherent detector');
plot_in_frequency(real(yf_sc_coh), fs, 'DSBSC demodulated signal snr=30 in frequency domain using coherent detector');
%-------------------------------------------------sound--------------------------------------------------------------------
%sound(real(yt_sc_coh),fs);
%#################################################################################################################################################################
%-------------------------------------------------DSBSC no snr coherent demodulation with fc error--------------------------------------------------------------------
[yt_sc_coh, yf_sc_coh] = coh_demod(yt_sc,fs_res,fs,0,0,fc+100,0,f_filter);
%-------------------------------------------------plotting--------------------------------------------------------------------
plot_in_time(real(yt_sc_coh), fs, 'DSBSC demodulated signal in time domain using coherent detector with fc error');
plot_in_frequency(real(yf_sc_coh), fs, 'DSBSC demodulated signal in frequency domain using coherent detector with fc error');
%-------------------------------------------------sound--------------------------------------------------------------------
% sound(real(yt_sc_coh),fs);
%-------------------------------------------------DSBSC no snr coherent demodulation with phase shift --------------------------------------------------------------------
phaseshift = degtorad(20);
[yt_sc_coh, yf_sc_coh] = coh_demod(yt_sc,fs_res,fs,0,0,fc,phaseshift,f_filter);
%-------------------------------------------------plotting--------------------------------------------------------------------
plot_in_time(real(yt_sc_coh), fs, 'DSBSC demodulated signal in time domain using coherent detector with phase shift');
plot_in_frequency(real(yf_sc_coh), fs, 'DSBSC demodulated signal in frequency domain using coherent detector with phase shift');
%-------------------------------------------------sound--------------------------------------------------------------------
%sound(real(yt_sc_coh),fs);