clc
clear all
file_choice = input('');
%读取外部文件
if(file_choice==1)
[filename, pathname] = uigetfile('*.*');
filename = fullfile(pathname, filename);
fid = fopen(filename,'r');
channel = fscanf(fid,'%g ',[1 inf]);
else
channel = input(' Enter the matrix name: ');
end
motor_parameter.sample_fre=5000;
motor_parameter.analysis_num=length(channel);
t=0:1/motor_parameter.sample_fre:motor_parameter.analysis_num/motor_parameter.sample_fre;
y=fft(channel); %傅立叶变换
%fft及时间曲线绘图
motor_parameter.analysis_num=length(channel); %信号的分析点数
t=0:1/motor_parameter.sample_fre:motor_parameter.analysis_num/motor_parameter.sample_fre;
f=motor_parameter.sample_fre*(0:motor_parameter.analysis_num-1)/motor_parameter.analysis_num;
subplot(2,2,1)
plot(t(1:motor_parameter.analysis_num),channel(1:motor_parameter.analysis_num)) %绘制时域波形
subplot(2,2,2)
plot(f(1:motor_parameter.analysis_num/2),2*abs(y(1:motor_parameter.analysis_num/2))/motor_parameter.analysis_num) %绘制幅频波形 |