matlab 输入参数的数目不足
function[time,fre,tfr]=STFT(time1,time2)formatlong;fileID=fopen('RXC19A.txt','r');%读取...
function [time,fre,tfr] = STFT(time1,time2)
format long;
fileID=fopen('RXC19A.txt','r');
%读取前11行,计数数据的平均时间间隔
C0=cell2mat(textscan(fileID,'%.16f%.9f',11));
data_time0=C0(:,1);
data_value0=C0(:,2);
%计算输入时间区间在文件中所对应的行数
period=(data_time0(11)-data_time0(1))/10;
tim_num1=round((time1-data_time0(1))/period)+1;
tim_num2=round((time2-data_time0(1))/period)+1;
%读取该区间数据
C=cell2mat(textscan(fileID,'%.19f%.11f',tim_num2-tim_num1+1,'HeaderLines',tim_num1-1));
t=C(:,1);
sig_value=C(:,2);
fclose(fileID);
%将数据每5个点抽取一个
temp=fix(length(t)/5)*5;
sig_value=sig_value(1:5:temp)';
t=t(1:5:temp)';
rx=sig_value;
samp=t(2)-t(1);
rx0=rx;
rx=detrend(rx); rx=detrend(rx,'constant'); %去趋势?
n=length(rx); %FFT变换的长度
Fs=1/samp; %采样频率
%$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
%短时傅里叶变换
%rx:输入信号;2048:将rx分为长度为2048的若干段,每段使用Hamming加窗;1024:各段之间重叠的采样点数;n:计算FFT的点数;Fs:采样频率
%y:短时傅里叶变换结果,为(n/2)*k矩阵,时间沿列增加,频率沿行增加;fre为频率向量,长度为n;time为时刻向量,长度为k;power为能量谱密度
'frequency analysis start';
[y,fre,time,power]=spectrogram(rx,2048,1024,n,Fs,'yaxis'); % 256 200
'frequency analysis end';
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
fre=fre/1000; time=time+t(1); tfr=power*1000000000;
% tfr=tfr./abs(tfr).*log10(abs(tfr));
[n,m]=size(tfr);
% return
for j=1:m;
for i=1:n
if tfr(i,j)>=1
tfr(i,j)=log10(tfr(i,j));
elseif tfr(i,j)<=-1
tfr(i,j)=-log10(-tfr(i,j));
else
tfr(i,j)=0;
end
end
end
'finish loop';
%************************************************************************** 展开
format long;
fileID=fopen('RXC19A.txt','r');
%读取前11行,计数数据的平均时间间隔
C0=cell2mat(textscan(fileID,'%.16f%.9f',11));
data_time0=C0(:,1);
data_value0=C0(:,2);
%计算输入时间区间在文件中所对应的行数
period=(data_time0(11)-data_time0(1))/10;
tim_num1=round((time1-data_time0(1))/period)+1;
tim_num2=round((time2-data_time0(1))/period)+1;
%读取该区间数据
C=cell2mat(textscan(fileID,'%.19f%.11f',tim_num2-tim_num1+1,'HeaderLines',tim_num1-1));
t=C(:,1);
sig_value=C(:,2);
fclose(fileID);
%将数据每5个点抽取一个
temp=fix(length(t)/5)*5;
sig_value=sig_value(1:5:temp)';
t=t(1:5:temp)';
rx=sig_value;
samp=t(2)-t(1);
rx0=rx;
rx=detrend(rx); rx=detrend(rx,'constant'); %去趋势?
n=length(rx); %FFT变换的长度
Fs=1/samp; %采样频率
%$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
%短时傅里叶变换
%rx:输入信号;2048:将rx分为长度为2048的若干段,每段使用Hamming加窗;1024:各段之间重叠的采样点数;n:计算FFT的点数;Fs:采样频率
%y:短时傅里叶变换结果,为(n/2)*k矩阵,时间沿列增加,频率沿行增加;fre为频率向量,长度为n;time为时刻向量,长度为k;power为能量谱密度
'frequency analysis start';
[y,fre,time,power]=spectrogram(rx,2048,1024,n,Fs,'yaxis'); % 256 200
'frequency analysis end';
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
fre=fre/1000; time=time+t(1); tfr=power*1000000000;
% tfr=tfr./abs(tfr).*log10(abs(tfr));
[n,m]=size(tfr);
% return
for j=1:m;
for i=1:n
if tfr(i,j)>=1
tfr(i,j)=log10(tfr(i,j));
elseif tfr(i,j)<=-1
tfr(i,j)=-log10(-tfr(i,j));
else
tfr(i,j)=0;
end
end
end
'finish loop';
%************************************************************************** 展开
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询