希爾伯特
最重要的就兩句
z=hilbert(x) am2=abs(z)
首先窖梁,不是第一句完成了希爾伯特變換就是包絡(luò)了,它只是完成了希爾伯特變換,相位偏移了90度大州,而且要使用abs()而不是imag(),下面代碼運(yùn)行就可以得到對(duì)應(yīng)的圖,但是前提是要把數(shù)據(jù)包添加到matlab的文件夾里
鏈接:http://pan.baidu.com/s/1kU9DuAF 密碼:gblw
垂谢,并且下列代碼的m文件要和數(shù)據(jù)包在同一路徑下
clc;
clear;
patterns = [];
targets = [];
Fs=50e6;%采樣率
%Abstract feature
for i=1:1
floder = ['IQ_sincos_f2.395000e+09_s5.000000e+07_Tx' num2str(i) '\data'];
fea_train =[];
for j=1:1
path = [floder '\IQ_sincos_f2.395000e+09_s5.000000e+07_Tx' num2str(i) '_' num2str(j) '.pcm'];
fileId = fopen(path,'r');
x = fread(fileId,500,'float32');
lengthofsignal=length(x);
T=1/Fs;
t=(0:lengthofsignal-1)*T; %對(duì)應(yīng)的時(shí)間序列
%繪制原始圖像
figure();
subplot(211)
plot(t,x,'b');
grid on
xlabel('時(shí)間');
ylabel('幅度')
hold on
z=hilbert(x);
am=abs(z);
plot(t,am,'r')
title('希爾伯特變換后使用abs函數(shù)');
legend('藍(lán)色是原始波形','紅色是abs求出的包絡(luò)')
%提取信號(hào)包絡(luò)并畫圖
subplot(212)
plot(t,x,'b');
grid on
xlabel('時(shí)間');
ylabel('幅度')
hold on
%提取信號(hào)包絡(luò)并畫圖,法二
z=hilbert(x);
yi = imag(z);
plot(t,yi,'g')
title('希爾伯特變換后使用imag函數(shù)');
legend('綠色是imag求出的')
end
end
其次厦画,使用希爾伯特可以得到包絡(luò),但是得到包絡(luò)的方法不止一只埂陆,還可以使用低通濾波,主程序如下:
clc;
clear;
patterns = [];
targets = [];
Fs=12000;%采樣率
%Abstract feature
for i=1:1 %只用了一個(gè)來測(cè)試苛白,如果要用多個(gè)改掉后面的1
floder = ['IQ_sincos_f2.395000e+09_s5.000000e+07_Tx' num2str(i) '\data'];
fea_train =[];
for j=1:1
path = [floder '\IQ_sincos_f2.395000e+09_s5.000000e+07_Tx' num2str(i) '_' num2str(j) '.pcm'];
fileId = fopen(path,'r');
x = fread(fileId,10240,'float32');
lengthofsignal=length(x);
T=1/Fs;
t=(0:lengthofsignal-1)*T; %對(duì)應(yīng)的時(shí)間序列
%繪制原始圖像
figure(1);
plot(t,x);
grid on
title(['TX',num2str(i),'原始圖像并采用希爾伯特求包絡(luò)']);
xlabel('Time');
ylabel('Amp')
hold on
z=hilbert(x);%做希爾伯特變換
%am1=sqrt(abs(x).^2+abs(z).^2);%使用此種函數(shù)處理后的包絡(luò)沒有用abs的好
am2=abs(z);
%plot(t,am1,'r')
plot(t,am2,'g')
axis([0 0.25 -1 1.5]); % 設(shè)置坐標(biāo)軸在指定的區(qū)間
figure(2)
plot(t,x);
hold on
re=envelope(x,Fs)
plot(t,re,'r--');title('低通濾波求包絡(luò)');
axis([0 0.25 -1 1.5]); % 設(shè)置坐標(biāo)軸在指定的區(qū)間
figure(3)
plot(t,am2,'g')
hold on
plot(t,re,'r--')
title('對(duì)比')
legend('綠色是希爾伯特求出的包絡(luò)','紅色是低通濾波求出的包絡(luò)')%文本標(biāo)注
end
end
其中調(diào)用的envelope.m文件
function y=envelope(signal,Fs)
%Envelope Detection based on Low pass filter and then FFT
[a,b]=butter(2,0.1);%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
sig_sq=2*signal.*signal;% squaring for rectifing
%gain of 2 for maintianing the same energy in the output
y_sq = filter(a,b,sig_sq); %applying LPF
y=sqrt(y_sq);%taking Square root
%advantages of taking square and then Square root rather than abs, brings
%out some hidden information more efficiently
N=3000;T=N/Fs;
sig_f=abs(fft(y(1:N)',N));
sig_n=sig_f/(norm(sig_f));
freq_s=(0:N-1)/T;
從圖上可以看出,采用低通濾波的包絡(luò)更為集中焚虱,更穩(wěn)定一些