function [frequency_time,amplitude,start_time,end_time] = lab1_p4(x,fs)
% Divide the entire time interval into several time frames
frame_length = 1; % This part only requires 1 sec as time section
frame_size = frame_length * fs; % Size of each frame (number of samples inside one frame). NOTE: fs is also the number of sample per period(frame)
number_of_frame = length(x)/frame_size; % X has length(x) samples
total_signal_time = length(x)/fs;
frame_time = total_signal_time/number_of_frame;
frequency_array = [0]; % An array that contains all the frequencies appear in each frame. If frequencies do not appear, zeros will be added.
amplitude_array = [0]; % An array that contains all the amplitudes appear in each frame. If corresponding frequencies do not appear, zeros will be added.
start_array = [0]; % An array that contains all the start time for different signals
end_array = [0]; % An array that contains all the end time for different signals. Initially, it contains zeros only
array_counter = 0; % A counter for array index
end_isdone = [zeros(1,fs)]; % Check if the endtime storage is done
% Analyse signal section by section
for i = 1:number_of_frame % i = ith frame
start_sample = (i - 1) * frame_size + 1; % Matlab starts from index 1
end_sample = i * frame_size; % End at each frame_size
subx = x(start_sample:end_sample); % Analysis of signal from start_sample to end_sample
[frequency_frame,amplitude_frame] = lab1_p3(subx,fs); % Analyse one frame at one time
% frequency_frame will contain all the frequencies appear in each frame
% amplitude_frame will contain all the amplitudes appear in each frame
for frame_index = 1:length(frequency_frame); % Dummy variable for checking if the value is already inside frequency_array[]
if ( sum(find( frequency_array == frequency_frame(frame_index))) == 0 ) % If frequency_frame(frame_index) is not found inside the frequency_array. Try to find frequency_frame(frame_index) in frequency_array
array_counter = array_counter + 1;
frequency_array(array_counter) = frequency_frame(frame_index); % Store the unfound value into the frequency_array
% Assume different frequencies have different amplitudes
amplitude_array(array_counter) = amplitude_frame(frame_index); % If frequency is not found, then amplitude cannot be found, so put that value into the amplitude_array
start_array(array_counter) = (i - 1) * frame_time;
end
end
for endtime_index = 1:length(frequency_array)
if (sum(find( frequency_frame == frequency_array(endtime_index))) == 0 && end_isdone(endtime_index) ~= 1) % If frequency_array(endtime_index) is not found in frequency_frame and it is not manipulated before, then the signal with this frequency is terminated. Try to find frequency_array(endtime_index) in frequency_frame, if it is not found, then it stops
end_array(endtime_index) = (i - 1) * frame_time; % Store endtime to corresponding index
end_isdone(endtime_index) = 1;
end
end
end
frequency_time = frequency_array;
amplitude = amplitude_array;
start_time = start_array;
end_array = [end_array zeros(1,length(frequency_array)-length(end_array))]; % Adding zeros in case of some of the signals still running
for endtime_end = 1:length(frequency_array) % If any signals do not stop, force them to stop at the end, i.e. total_signal_time
if( end_array(endtime_end) == 0 )
end_array(endtime_end) = total_signal_time;
end
end
end_time = end_array;
end
matlab_pinpu.zip_matlab;频谱分析;带通滤波
版权申诉
169 浏览量
2022-07-14
05:10:54
上传
评论
收藏 4KB ZIP 举报
林当时
- 粉丝: 100
- 资源: 1万+
最新资源
- 部署yolov8的tensorrt模型支持检测分割姿态估计的C++源码+部署步骤.zip
- 以简单、易用、高性能为目标、开源的时序数据库,支持Linux及Windows, Time Series Database.zip
- python-leetcode面试题解之第198题打家劫舍-题解.zip
- python-leetcode面试题解之第191题位1的个数-题解.zip
- python-leetcode面试题解之第186题反转字符串中的单词II-题解.zip
- 一个基于python的web后端高性能开发框架,下载可用
- python-leetcode面试题解之第179题最大数-题解.zip
- python-leetcode面试题解之第170题两数之和III数据结构设计-题解.zip
- python-leetcode面试题解之第168题Excel表列名称-题解.zip
- python-leetcode面试题解之第167题两数之和II输入有序数组-题解.zip
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
评论0