-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathenvelope1.m
89 lines (79 loc) · 2.64 KB
/
envelope1.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
function y=envelope1(signal,Fs)
%y=envelope(Signal,Fs) computes the Envelope of the input Signal with a
%Sampling Frequency 'Fs' and gives the envelope signal by hilbert transform
%method as the output y.
%The function computes the envelope of the signal by two different methods.
%
%First Method: By USing Low Pass Filter. THe Signal is Squared, Passed
%through LPF and then taken square root.
%Second Method: Using Hilbert Transform. Hilbert Transform is taken using
%the inbuilt function in Matlab
%
%The Function Displays the FFT of the original signal and also the FFT of
%the envelope signal by both the methods
%
%The function basically is for computing Envelope Signal for Condition
%Monitoring of rotating equipments by vibration based bearing
%fault diagnosis.
%
%Example:
% load('s4.mat');
% signal=s4;
% Fs=12000;
% envelope(signal,Fs);
%
%The File 's4.mat' is the vibration signal recorded from a OR faulty
%bearing with a sampling frequency of 12000Hz. The Fault frequency is 161Hz
%and is brought out in envelope signal which was hidden in the original
%FFT.
%
%Dont forget to rate or comment on the matlab central site
%http://www.mathworks.in/matlabcentral/fileexchange/authors/258518
%
%Author:Santhana Raj.A
%https://sites.google.com/site/santhanarajarunachalam/
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
clc;
% close all;
%Normal FFT
y=signal;
%
% figure();
% N=2*2048;
% % N=length(signal)-1;
% N=800;
% T=N/Fs;
% sig_f=abs(fft(y(1:N)',N));
% sig_n=sig_f/(norm(sig_f));
% freq_s=(0:N-1)/T;
% plot(freq_s(2:250),sig_n(2:250));title('FFT of Original Signal');
%Envelope Detection based on Low pass filter and then FFT
[a,b]=butter(3,0.4);%butterworth Filter of 2 poles and Wn=0.1
%sig_abs=abs(signal); % Can be used instead of squaring, then filtering and
%then taking square root
signal=signal-mean(signal);
sig_sq=2*signal.*signal;% squaring for rectifing
% sig_sq=2*abs(signal);
%gain of 2 for maintianing the same energy in the output
y_sq = filtfilt(a,b,sig_sq); %applying LPF
y=sqrt(y_sq);%taking Square root
y=real(y);
%advantages of taking square and then Square root rather than abs, brings
%out some hidden information more efficiently
% figure();
% N=2*2048;T=N/Fs;
% sig_f=abs(fft(y(1:N)',N));
% sig_n=sig_f/(norm(sig_f));
% freq_s=(0:N-1)/T;
% plot(freq_s(2:250),sig_n(2:250));title('Envelope Detection: LPF Method');
%
% %Envelope Detection based on Hilbert Transform and then FFT
% analy=hilbert(signal);
% y=abs(analy);
% figure();
% N=2*2048;T=N/Fs;
% sig_f=abs(fft(y(1:N)',N));
% sig_n=sig_f/(norm(sig_f));
% freq_s=(0:N-1)/T;
% plot(freq_s(2:250),sig_n(2:250));title('Envelope Detection : Hilbert Transform')
end