%以下程序是对一段采样信号进行FFT分析,得到信号的频率成分:
%从“toworkspace”模块得到的数据在out数据中,需要用“data1=out.output”指令读取出来。读取后data1中也可能有多个数据,需要用data1.time\data1.data来使用。
%
fs=40e3; %fs:采样频率,Upccwave(:,1)为时间;Upccwave(:,2)为信号波形
figure(7);subplot(2,2,1);plot(input.time,input.data);%画出时域波形
figure(7);subplot(2,2,3);plot(output.time,output.data);%画出时域波形
title(‘时域原始信号’);
xlabel(‘时间t’);grid on;
number=0.01fs;%确定做多少点的FFT,这里是number点
yin=fft(input.data,number)./(number/2);%由于FFT的特性,输出数列幅值与原始信号频率分量幅值之间存在放大了(number/2)倍的关系;
%基波是放大number倍;这里是为了还原
yout=fft(output.data,number)./(number/2);
n=0:length(yin)-1;
f=fsn/length(yin); %设置频率轴坐标
figure(7);subplot(2,2,2);bar(f,abs(yin));%axis([0,300,0,10e2]);%频域内的频谱信号
figure(7);subplot(2,2,4);bar(f,abs(yout));%axis([0,300,0,10e2]);%频域内的频谱信号
title(‘频域频谱信号’);
xlabel(‘频率Hz’);grid on;
数据导出方法