基于Wi-Fi CSI的摔倒检测(四):CSI数据处理-PCA降维(下)

本篇文章,主要是为上篇文章作补充,给出完整代码即效果。

clear all clc csi_trace = read_bf_file(sample_data/lie1.dat); pac_num=size(csi_trace,1); subcarrier=zeros(1,990); Hall=zeros(990,30); Z=zeros(990,30); Zk=zeros(990,1); for j=1:30 for i=1:990; csi_entry=csi_trace{i}; csi=get_scaled_csi(csi_entry); csi1=squeeze(csi(1,:,:)).;% 30*3 complex csiabs=db(abs(csi1)); csiabs=csiabs(:,2); csi1=csi1(:,2); subcarrier(i)=csiabs(j); if(subcarrier(i)>=35) subcarrier(i)=35; else if(subcarrier(i)<=1) subcarrier(i)=1; end end end yd=wden(subcarrier,heursure,s,one,10,sym3); vs=movvar(yd,50) figure(1) subplot(2,1,1); plot(subcarrier); title(beforeDWT); subplot(2,1,2); plot(yd); title(afterDWT); figure(9) plot(vs); xlabel(time(s)); ylabel(variance); title(movvar_Origin); hold on Hall(:,j)=yd.; end %uncentralize for k=1:30 for i=1:990 Zk(i)=Hall(i,k)-mean(Hall(:,k)); end Z(:,k)=Zk; end %Z covariance C=cov(Z); % Eigenvector e, eigenvalue R [E,R]=eig(C); R=ones(1,30)*R;%The eigenvalues generated by the eig function are transformed into row vectors TZ_ER=[R;E]; TZ_ER=TZ_ER; %The eigenvectors are arranged in descending order according to the size of R TZ_ER=sortrows(TZ_ER,1,descend); R=TZ_ER(:,1);%Separating eigenvalues E=TZ_ER(:,2:end);%Separating eigenvectors Pca=zeros(30,1); E=E Pca=E(:,1);%chose the 1st pinciple component Y=Hall*Pca; res=sum(R(1:2))/sum(R); apv=movvar(Y,50) figure(2) plot(apv,k,linewidth,3); xlabel(time(s)); ylabel(variance); title(movvar_PCA); figure(15) plot (Y,linewidth,3); hold on title(afterPCA); fprintf(consists the percent\n,res*100); for i=1:30 plot(Hall(:,i)); end Butterworth hfc = 300; lfc = 0; fs = 1000; order = 10; [b,a] = butter(order, hfc/(fs/2)); figure(5) freqz(b,a) noisy_sig = D{7}; dataIn = randn(1000,1); dataOut = filter(b,a,Y); figure(6) subplot(2,1,1) plot(Y) hold on title(original); subplot(2,1,2) plot(dataOut); hold on title(afterbutterworth); Y=dataOut; FFT F=fft(Y,1024); figure(9) plot(abs(F)); axis([0 1800 0 1500]); STFT fs = 1000;% window = 512; noverlap = window/2; nfft=1024; f_len = window/2 + 1; f = linspace(0, 150e3, f_len); % s= spectrogram(Y, window, noverlap); % figure(1); % imagesc(20*log10((abs(s))));xlabel(Samples); ylabel(Freqency); % colorbar; [s, f, t, p] = spectrogram(Y, window, nfft, f, fs); figure(8); imagesc(t, f, p);xlabel(Samples); ylabel(Freqency); colorbar; [s, f, t] = spectrogram(Y, 512,256,f, fs); figure; imagesc(t, f, 20*log10((abs(s))));xlabel(Samples); ylabel(Freqency); colorbar; figure(16) subplot(2,1,1) spectrogram(Y,128,127,128,fs,yaxis); title(STFT); hold on [s,f,t,ps]=spectrogram(Y,64,63,64,fs,yaxis); m=4:33 n=1:927 pmax=max(ps(m,n),[],1); subplot(2,1,2) % % figure(17) plot(pmax,linewidth,3,MarkerEdgeColor,k,MarkerFaceColor,g,MarkerSize,10); hold on title(power curve);
<

整段代码效果如下图:

免责声明:文章内容来自互联网,本站不对其真实性负责,也不承担任何法律责任,如有侵权等情况,请与本站联系删除。
转载请注明出处:基于Wi-Fi CSI的摔倒检测(四):CSI数据处理-PCA降维(下) https://www.yhzz.com.cn/a/17225.html

上一篇 2023-05-19 22:21:22
下一篇 2023-05-19 22:59:26

相关推荐

联系云恒

在线留言: 我要留言
客服热线:400-600-0310
工作时间:周一至周六,08:30-17:30,节假日休息。