版权声明:转载请说明Zhonglihao原创 https://blog.csdn.net/xeonmm1/article/details/85726507
clc;clear all;close all;
n = 2000;
fs = 150; %采样频率
x = 1:1:n; % 数据点
data = sin((x/fs)*2*pi); % 频率为1Hz的正弦波
% 谱缓存 2倍采样率谱 对应谱最大周期为1/0.5Hz = 2s
spec_arr = zeros(300,n);
% 数据缓存
data_arr = zeros(301,1);
% DSP下,每次读入一个新的数据
for i = 1:1:n
data_arr(1:300) = data_arr(2:301);
data_arr(301) = data(i);
% 数据量足够做谱的话
if(i>300)
for j = 300:-1:1
spec_arr(j,i) = data_arr(301)*data_arr(j);
end
end
end
figure(1);
plot(data);
figure(2);
surf(spec_arr);