基于Wi-Fi CSI的摔倒检测(四):CSI数据处理-PCA降维(下)
12001
技术凯 2021-01-08 03:03:13

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

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');

整段代码效果如下图:





声明:本文内容由易百纳平台入驻作者撰写,文章观点仅代表作者本人,不代表易百纳立场。如有内容侵权或者其他问题,请联系本站进行删除。
红包 85 13 评论 打赏
评论
2个
时间排序
内容存在敏感词
手气红包
    0 条记录 第 0 /
    相关专栏
    置顶时间设置
    结束时间
    删除原因
    • 广告/SPAM
    • 恶意灌水
    • 违规内容
    • 文不对题
    • 重复发帖
    打赏作者
    易百纳技术社区
    技术凯
    您的支持将鼓励我继续创作!
    打赏金额:
    ¥1 易百纳技术社区
    ¥5 易百纳技术社区
    ¥10 易百纳技术社区
    ¥50 易百纳技术社区
    ¥100 易百纳技术社区
    支付方式:
    微信支付
    支付宝支付
    易百纳技术社区 微信支付
    易百纳技术社区
    打赏成功!

    感谢您的打赏,如若您也想被打赏,可前往 发表专栏 哦~

    举报反馈

    举报类型

    • 内容涉黄/赌/毒
    • 内容侵权/抄袭
    • 政治相关
    • 涉嫌广告
    • 侮辱谩骂
    • 其他

    详细说明

    审核成功

    发布时间设置
    发布时间:
    是否关联周任务-专栏模块

    审核失败

    失败原因
    备注
    Loading...
    易百纳技术社区
    确定要删除此文章、专栏、评论吗?
    确定
    取消
    易百纳技术社区
    每周任务
      去完成
      活动规则
      易百纳技术社区
      升级提醒
      升级

      恭喜您的社区称号由 升级为 “社区游民”

      同时为了感谢您对社区的支持,我们将送出xxx礼品一份, 记得领取哦~

      升级提醒
      易百纳技术社区

      惊喜礼包

      拼手气红包 红包规则
      祝福语
      恭喜发财,大吉大利!
      红包金额
      红包最小金额不能低于5元
      红包数量
      红包数量范围10~50个
      余额支付
      当前余额:
      可前往问答、专栏板块获取收益 去获取
      取 消 确 定

      小包子的红包

      恭喜发财,大吉大利

      已领取20/40,共1.6元 红包规则

        avatar