-
Notifications
You must be signed in to change notification settings - Fork 1
/
fft_method.m
64 lines (54 loc) · 1.89 KB
/
fft_method.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
clear all;
close all;
clc
%Sampling Frequency
fs = 250e6;
Ts = 1/fs;
t = 0:Ts:1e-6;
%Center Frequency
fc = 70e6;
%Moving Average Filter
lpf = ones(1,16);
lpf = lpf/length(lpf);
%noise coefficient
n = 0.2;
%First Signal
x1= cos(2 * pi * fc * t) + (n * randn(1, length(t)));
%Delay
delay = 0.5e-9;
%Delayed Signal
x2 = cos(2 * pi * fc *(t + delay)) + (n * randn(1, length(t)));
numberofPoints = ceil((length(t) + 1) / 2);% numberofPoints is 126
f = ((0:numberofPoints - 1) * fs) / length(t);
figure(1)
subplot(2, 1, 1),plot(x1)
title('Original Signal')
subplot(2, 1, 2),plot(x2)
title('Delayed Signal')
fftFirstSignal = fft(x1);
fftSecondSignal = fft(x2);
%MAGNITUDERESPONSEPART
figure(2)
subplot(2, 1, 1);
plot(f, abs(fftFirstSignal(1:numberofPoints)));
title('First Transformation : Magnitude response');
subplot(2, 1, 2)
plot(f, abs(fftSecondSignal(1:numberofPoints)));
title('Second Transformation : Magnitude response')
%PHASE RESPONSE PART
figure(3)
subplot(2, 1, 1),plot(f, angle(fftFirstSignal(1:numberofPoints)));
title('Phase Response of First Transformation');
subplot(2, 1, 2),plot(f, angle(fftSecondSignal(1:numberofPoints)));
title('Phase Response of Second Transformation');
%taking consideration into maximum points of the signals
%by doing that we ignore the rest of the signal
%but just maximum points in comparison
[magnitudeofFirstSignal indexofFirstSignalAmplitude] = max(abs(fftFirstSignal));
[magnitudeofSecondSignal indexofSecondSignalAmplitude] = max(abs(fftSecondSignal));
phaseofFirstSignal = angle(fftFirstSignal(indexofFirstSignalAmplitude));
phaseofSecondSignal = angle(fftSecondSignal(indexofSecondSignalAmplitude));
phaseLag = phaseofFirstSignal - phaseofSecondSignal
timeDelay= abs(phaseLag)/((fc)*2*pi)
%ratio of second signal to first signal, amplitudewise.
amplitudeRatio = magnitudeofSecondSignal/magnitudeofFirstSignal;