-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfiltering.m
142 lines (108 loc) · 2.55 KB
/
filtering.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
clc % clear command prompt
clear all % clear all previous data
close all % close all figure
sampleFreq=40; % 40Hz
Ts= 1/sampleFreq;
L = 500; % Length of signal
t = (0:L-1)*Ts; % 1000 time points
NFFT = 2^nextpow2(L);
f = sampleFreq/2*linspace(0,1,NFFT/2+1);
% (could be x) 0 to 3s
f1=1; %frequency in cycles per second (Hertz)
f2=3;
f3=7;
y1=2*sin(2*pi*f1*t); % Observations or data at each interval t
y2=4*sin(2*pi*f2*t);
y3=6*sin(2*pi*f3*t);
figure
N =8; %fontsize
thk= 2;
% time series
subplot(4,1,1)
plot(t,y1, 'r', 'LineWidth',thk); % plot the data
axis([0,6,-10,10])
xlabel('Time (s)')
set(gca,'FontSize',N)
subplot(4,1,2)
plot(t,y2 ,'r', 'LineWidth',thk); % plot the data
axis([0,6,-10,10])
xlabel('Time (s)')
set(gca,'FontSize',N)
subplot(4,1,3)
plot(t,y3 ,'r', 'LineWidth',thk); % plot the data
axis([0,6,-10,10])
xlabel('Time (s)')
set(gca,'FontSize',N)
ytotal=y1+y2+y3;
subplot(4,1,4)
plot(t,ytotal ,'r', 'LineWidth',thk); % plot the data
axis([0,6,-10,10])
xlabel('Time (s)')
set(gca,'FontSize',N)
% FFTs
figure
Y1 = fft(y1 , NFFT);
Y2 = fft(y2 , NFFT);
Y3 = fft(y3 , NFFT);
YT = fft(ytotal,NFFT);
subplot(4,1,1)
plot(f(1:L/5),abs(Y1(1:L/5)) ,'r', 'LineWidth',thk);
axis([0,8,0,2000])
xlabel('Frequency (Hz)')
set(gca,'FontSize',N)
subplot(4,1,2)
plot(f(1:L/5),abs(Y2(1:L/5)) ,'r', 'LineWidth',thk);
axis([0,8,0,2000])
xlabel('Frequency (Hz)')
set(gca,'FontSize',N)
subplot(4,1,3)
plot(f(1:L/5),abs(Y3(1:L/5)) ,'r', 'LineWidth',thk);
axis([0,8,0,2000])
xlabel('Frequency (Hz)')
set(gca,'FontSize',N)
subplot(4,1,4)
plot(f(1:L/5),abs(YT(1:L/5)) ,'r', 'LineWidth',thk);
axis([0,8,0,2000])
xlabel('Frequency (Hz)')
set(gca,'FontSize',N)
% Not using this
%{
figure
axis([0,6,-10,10])
subplot(4,1,2)
plot(t,y2); % plot the data
axis([0,6,-10,10])
subplot(4,1,3)
plot(t,y3); % plot the data
axis([0,6,-10,10])
ytotal=y1+y2+y3;
subplot(4,1,4)
plot(t,ytotal); % plot the data
axis([0,6,-10,10])
ytotal =y1+y2+y3;
Y3 = fft(ytotal,NFFT);
subplot(4,1,2)
plot(f(1:L/5),abs(Y3(1:L/5)));
plot(t,ytotal); % plot the data
xlabel ('Time (seconds)'); %label the data
ylabel('Amplitude'); %
title('plot of y1+y2+y3')
ytotal =y1+y2+y3+y4;
Y4 = fft(ytotal,NFFT);
subplot(3,1,3)
plot(t,ytotal); % plot the data
xlabel ('Time (seconds)'); %label the data
ylabel('Amplitude'); %
title('plot of y1+y2+y3+y4')
%figure
subplot(3,1,1)
plot(f(1:L/5),abs(Y2(1:L/5)));
ylabel('ABS Amp'); %
subplot(3,1,2)
plot(f(1:L/5),abs(Y3(1:L/5)));
ylabel('ABS Amp'); %
subplot(3,1,3)
plot(f(1:L/5),abs(Y4(1:L/5)));
xlabel ('Frequency (Hz)'); %label the data
ylabel('ABS Amp');
%}