-
Notifications
You must be signed in to change notification settings - Fork 1
/
sns_final_project.m
297 lines (234 loc) · 7.85 KB
/
sns_final_project.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
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
clear all;
close all;
clc;
%f=55.*(10^(6)) + (5.*(10^(6))+5.*(10^(6)))*rand(1,1)
%use for random input oof 55 to 65 MHz
% Add extra code for Bandpass filter, Low pass etc.
%Add AWGN and analyse results
f=( 60.*(10^(6)) );
%For the normal input wave of frequency 60MHz
%f=( 60.*(10^(6)) )./ ( 100.*(10^(6)) ) ;
% Sampled wave at 100 MHz
t1=0:(10^(-8)):0.05;
y=@(t)sin(2*pi*f*t);
% Making the wave a sine function
d1=0.45*(10^(-6));
% Time duration for which the wave has non zero amplitude
t=1.45*(10^(-6));
% Time period (Total time for which a single wave exists) for the whole wave
fs = 10^8;
x2=0:1/fs:t;
f=@(x)[y(x).*(0<=x & x<d1)+0.*(d1<=x & x<t)];
% Division of the wave as per the desired time intervals
pfx2=f(x2);
plot(x2,pfx2);
title('Wave for a single Time Period');
figure;
intvl2=[-2*t 2*t];
z2=linspace(0,t-0.00000001);
fx2 = repmat(f(z2),1,diff(intvl2)/t);
% Repeats the copies of the arrays for the single wave (generated) to be repeated and appear as a complete wave with multiple clock cycles
x3 = linspace(intvl2(1),intvl2(2),length(fx2));
plot(x3,fx2);
title('The Final Input wave (Continuous Time)');
figure;
stem(x3,fx2);
title('The Final Input wave (Discreet Time)');
% The final input wave or the sampled wave
figure;
%Gaussian White Noise is added to the input signal
N0 = awgn(pfx2,10,'measured');
plot(x2,N0);
title(' Plot of the wave with external AWGN ');
figure;
F = fft(fx2);
stem(1./x3,F);
title('Fourier Transform of the Sampled Signal');
figure;
stem(1./x3,abs(F));
title('Magnitude spectrum of Fourier Transform');
figure;
fc = 40.*(10^(6));
I0 = F .* cos((2.*(pi).*fc).*x3);
plot(1./x3,I0);
title('Wave obtained on multiplying the fft with cos(fc*t), in the frequency domain');
figure;
Q0 = F .* sin((2.*(pi).*fc).*x3);
plot(1./x3,Q0);
title('Wave obtained on multiplying the fft with sin(fc*t), in the frequency domain');
%In the following steps we are designing an FIR Filter, through which we
%are going to pass the waves we obtain on getting the sine and cosine
%products of the Fourier Transformed Sampled Sine wave
d = fdesign.lowpass('Fp,Fst,Ap,Ast',0.1,0.15,1,60);
% We are setting the Passband Frequency at 10 MHz and the Stopband
% frequency at 15 MHz and thus, the input arguments of 0.1 and 0.15 in
% lowpass object
designmethods(d);
f = design(d, 'ellip');
%fvtool(f) ;
Q = filter(f,Q0);
I = filter(f,I0);
stem(1./x3,I);
title('Plot of the fft* with sin wave obtained after filtering, in the frequency domain');
figure;
K = ((I).^2 + (Q).^2);
K1 = log(K);
stem(x3,K);
title('Plot of the sum of sqaures of the waves obtained after filtering (I^2 + Q^2');
figure;
plot(x3,K1);
title('Plot of log of the sum of sqaures of the waves obtained after filtering log(I^2 + Q^2');
%% for the awgn noise:
clear all;
close all;
clc;
fn=(60.*(10^(6)));
fn1= 10.*(10^(6)):(10^(6)):120.*(10^(6))
n1 = length(fn1);
%t = 0:0.0000000001:0.000001
% What we have been doing so far which is wrong ( plot dekho zoom karke curved edges aani chahiye no sharp)
x1 = 0:0.00000001:1./fn;
%What we should have done ( see the pure sine wave hamare plot me pure nahi aa rahi bilkul
y = @(x)sin(2*pi*fn*x);
y1=y(x1);
plot(x1,y1);
%figure;
y1fft = abs(fft(y1));
%xf=-1*2*pi*fn:100000:2*pi*fn;
%plot (xf,y1fft);
%figure;
%plot(1./t,xdft);
d1=0.45*(10^(-6));
% Time duration for which the wave has non zero amplitude
d2=1.45*(10^(-6));
f=@(x)[y(x).*(0<=x & x<d1)+0.*(d1<=x & x<d2)];
x2=0:0.000000001:d2;
pfx2=f(x2);
t=d2;
intvl2=[-2*t 2*t];
z=linspace(0,t-0.0000001);
fx2 = repmat(f(z),1,diff(intvl2)/t);
x3 = linspace(intvl2(1),intvl2(2),length(fx2));
plot(x2,pfx2);
figure;
plot(x3,fx2);
figure;
stem(x3,fx2);
%Gaussian White Noise is added to the input signal
N0 = awgn(pfx2,10,'measured');
plot(x2,N0);
title(' Plot of the wave with external AWGN ');
figure;
F = fft(N0);
stem(1./x2,N0);
title('Fourier Transform of the Sampled Signal');
figure;
stem(x2,abs(N0));
title('Magnitude spectrum of Fourier Transform');
figure;
fc = 40.*(10^(6));
I0 = F .* cos((2.*(pi).*fc).*x2);
plot(1./x2,I0);
title('Wave obtained on multiplying the fft with cos(fc*t), in the frequency domain');
figure;
Q0 = F .* sin((2.*(pi).*fc).*x2);
plot(1./x2,Q0);
title('Wave obtained on multiplying the fft with sin(fc*t), in the frequency domain');
%In the following steps we are designing an FIR Filter, through which we
%are going to pass the waves we obtain on getting the sine and cosine
%products of the Fourier Transformed Sampled Sine wave
d = fdesign.lowpass('Fp,Fst,Ap,Ast',0.1,0.15,1,60);
% We are setting the Passband Frequency at 10 MHz and the Stopband
% frequency at 15 MHz and thus, the input arguments of 0.1 and 0.15 in
% lowpass object
designmethods(d);
f = design(d, 'ellip');
%fvtool(f) ;
Q = filter(f,Q0);
I = filter(f,I0);
stem(1./x2,I);
title('Plot of the fft* with sin wave obtained after filtering, in the frequency domain');
figure;
K = ((I).^2 + (Q).^2);
K1 = log(K);
stem(x2,K);
title('Plot of the sum of sqaures of the waves obtained after filtering (I^2 + Q^2');
figure;
plot(x2,K1);
title('Plot of log of the sum of sqaures of the waves obtained after filtering log(I^2 + Q^2');
%%
f=55.*(10^(6)) + (5.*(10^(6))+5.*(10^(6)))*rand(1,1)
%use for random input oof 55 to 65 MHz
%f=( 60.*(10^(6)) );
%For the normal input wave of frequency 60MHz
%f=( 60.*(10^(6)) )./ ( 100.*(10^(6)) ) ;
% Sampled wave at 100 MHz
t1=0:(10^(-8)):0.05;
y=@(t)sin(2*pi*f*t);
% Making the wave a sine function
d1=0.45*(10^(-6));
% Time duration for which the wave has non zero amplitude
t=1.45*(10^(-6));
% Time period (Total time for which a single wave exists) for the whole wave
fs = 10^8;
x2=0:1/fs:t;
f=@(x)[y(x).*(0<=x & x<d1)+0.*(d1<=x & x<t)];
% Division of the wave as per the desired time intervals
pfx2=f(x2);
plot(x2,pfx2);
title('Wave for a single Time Period');
figure;
intvl2=[-2*t 2*t];
z2=linspace(0,t-0.00000001);
fx2 = repmat(f(z2),1,diff(intvl2)/t);
% Repeats the copies of the arrays for the single wave (generated) to be repeated and appear as a complete wave with multiple clock cycles
x3 = linspace(intvl2(1),intvl2(2),length(fx2));
plot(x3,fx2);
title('The Final Input wave (Continuous Time)');
figure;
stem(x3,fx2);
title('The Final Input wave (Discreet Time)');
% The final input wave or the sampled wave
figure;
%Gaussian White Noise is added to the input signal
N0 = awgn(pfx2,10,'measured');
plot(x2,N0);
title(' Plot of the wave with external AWGN ');
figure;
F = fft(fx2);
stem(1./x3,F);
title('Fourier Transform of the Sampled Signal');
figure;
stem(x3,abs(F));
title('Magnitude spectrum of Fourier Transform');
figure;
fc = 40.*(10^(6));
I0 = F .* cos((2.*(pi).*fc).*x3);
plot(1./x3,I0);
title('Wave obtained on multiplying the fft with cos(fc*t), in the frequency domain');
figure;
Q0 = F .* sin((2.*(pi).*fc).*x3);
plot(1./x3,Q0);
title('Wave obtained on multiplying the fft with sin(fc*t), in the frequency domain');
%In the following steps we are designing an FIR Filter, through which we
%are going to pass the waves we obtain on getting the sine and cosine
%products of the Fourier Transformed Sampled Sine wave
d = fdesign.lowpass('Fp,Fst,Ap,Ast',0.1,0.15,1,60);
% We are setting the Passband Frequency at 10 MHz and the Stopband
% frequency at 15 MHz and thus, the input arguments of 0.1 and 0.15 in
% lowpass object
designmethods(d);
f = design(d, 'ellip');
%fvtool(f) ;
Q = filter(f,Q0);
I = filter(f,I0);
stem(1./x3,I);
title('Plot of the fft* with sin wave obtained after filtering, in the frequency domain');
figure;
K = ((I).^2 + (Q).^2);
K1 = log(K);
stem(x3,K);
title('Plot of the sum of sqaures of the waves obtained after filtering (I^2 + Q^2');
figure;
plot(x3,K1);
title('Plot of log of the sum of sqaures of the waves obtained after filtering log(I^2 + Q^2');