%%%%%%%%%%%%load原始数据%%%%%%%%%%%
clear all; close all
load('D:\Program\Xiaozhou\Flat\20160408_10_incldpeakq.mat')
Sensors20160408190205(:,20)=[];Sensors20160408190205(:,15)=[];Sensors20160408190205(:,15)=[];
Sensors20160408190531(:,20)=[];Sensors20160408190531(:,15)=[];Sensors20160408190531(:,15)=[];
Sensors20160408190921(:,20)=[];Sensors20160408190921(:,15)=[];Sensors20160408190921(:,15)=[];
Sensors20160408191341(:,20)=[];Sensors20160408191341(:,15)=[];Sensors20160408191341(:,15)=[];
Fs=5000; xt1=Sensors20160408190205(:,20);
%%%%%%%%%%%%傅里叶变换%%%%%%%%%%%
N=length(xt1); %数据长度
n=0:N-1; t1=n/Fs; %数据刻度
f=n*Fs/N; %频谱刻度
f0=Fs/N; %频率分辨率
xdft = fft(xt1); %傅里叶变换
xdft2 = xdft(1:length(xt1)/2+1); %频谱一半
xdft2 = 1/length(xt1).*xdft2; %归一化
xdft2(2:end-1) = 2*xdft2(2:end-1); %单边频谱
freq = 0:Fs/length(xt1):Fs/2; %单边频谱刻度
% figure (1)
% plot(freq,abs(xdft2),'b'); % 10Hz对应855个点
% hold on
%%%%%%%%%%%%设定截止频率--低通滤波%%%%%%%%%%%
fstop=10; %设定截断频率
fspnumb=round(fstop/f0);
xdft2(fspnumb:length(xdft2))=0;
%plot(freq,abs(xdft2),'r'); % 10Hz对应855个点
%%%%%%%%%%%%逆傅里叶变换%%%%%%%%%%%
xdft3=xdft2;
back=ifft(xdft3); %逆傅里叶变换
error=xt1-back; %误差
figure (11)
xstat=56.8; %显示开始时间段
xstop=xstat+0.5; %显示结束时间段
plot(t1,xt1,'b')
hold on
plot(t1,back,'r')
xlim([xstat xstop]);grid on
figure (12)
plot(t1,error)
xlim([xstat xstop]);grid on
% xdft3(2:end-1)=xdft2(2:end-1)./2;
% xdft3=xdft3.*length(xt1);
% for j=length(xt1)/2+2:length(xt1)
% xdft3(j)=conj(xdft3(length(xt1)-j+2));
% end
% figure (6)
% error2=xdft3-xdft; %原来的fft图与恢复后的fft图的误差
% subplot(4,1,1);plot(real(xdft));title('最初的fft图实部'); xlim([0,50])
% subplot(4,1,2);plot(real(xdft3));title('恢复后的fft图实部');xlim([0,50])
% subplot(4,1,3);plot(imag(xdft));title('最初的fft图虚部');xlim([0,50])
% subplot(4,1,4);plot(imag(xdft3));title('恢复后的fft图虚部');xlim([0,50])
评论0