我有一个非常大的局部场电位(原始电压)数据集,我已对其进行预处理以消除噪声和异常值。我安排了数据,以便每行代表30秒的样本。我已经生成了如下的功率谱:
Fs = 1024
LFP = 1075x30720 double
pxx = 1075x4097 double
for k = 1:1075;
pxx(kk,:) = pwelch(LFP(k,:));
end
目标:生成热图,以便pxx的每一行都是生成的热图上的一列,所以我应该在x轴上有1075个分档,并且我希望将Y轴限制为0到120之间的频率赫兹。我尝试过使用imagesc但遇到困难,谢谢。
答案 0 :(得分:0)
要绘制结果,您需要做一些事情:
pxx
以使pxx
的行显示为生成图像的列; flipud
的顶部,imagesc
翻转数据; imagesc
或pcolor
; caxis
显示的动态值范围,以便在色彩映射中获得相当大的值; colormap(hot)
等色彩映射。这可以通过以下方式完成:
% 1) Compute maximum frequency index
Fmax = 120; % Hz
M = 1 + round(Fmax/(0.5*Fs/(size(pxx,2)-1)));
% select displayed section
pxx_select = pxx(:,1:M);
% 2) transpose matrix
pxx_reshape = transpose(pxx_select);
% 3) flip data upside down for imagesc
pxx_reshape = flipud(pxx_reshape);
% 4) convert to decibel scale
pxx_dB = 10*log10(pxx_reshape);
% 5) generate plot
figure(1);
imagesc(pxx_dB);
% 6) choose dynamic range
% assign e.g. 80dB below peak power to the first value in the colormap
% and the peak power to the last value in the colormap
caxis([max(max(pxx_dB))-80 max(max(pxx_dB))]);
% 7) select colormap
colormap(hot);
或者,如果您想控制显示的轴:
% 1) Compute maximum frequency index
Fmax = 120; % Hz
M = 1 + round(Fmax/(0.5*Fs/(size(pxx,2)-1)));
% select displayed section
pxx_select = pxx(:,1:M);
% 2) transpose matrix
pxx_reshape = transpose(pxx_select);
% 3) flipud not needed with pcolor, instead set t & f axis:
t = (size(LPF,2)/Fs)*[0:size(LPF,1)];
f = [0:M]*Fmax/(M-1);
% 4) convert to decibel scale
pxx_dB = 10*log10(pxx_reshape);
% 5) generate plot
figure(2);
% Note: extend by one row & column since pcolor does not show the last row/col
P2 = [pxx_dB pxx_dB(:,end); pxx_dB(end,:) pxx_dB(end,end)];
pcolor(t,f,P2); shading flat;
% 6) choose dynamic range
% assign e.g. 80dB below peak power to the first value in the colormap
% and the peak power to the last value in the colormap
caxis([max(max(pxx_dB))-80 max(max(pxx_dB))]);
% 7) select colormap
colormap(hot);
xlabel("time (s)");
ylabel("frequency (Hz)");
如图所示,您将获得类似于
的图表用于生成一个简单的缓慢变频音:
T = size(LPF,1)-1;
phi = 0;
n = [0:size(LPF,2)-1];
for k=1:size(LPF,1)
f = 0.5*(fmin+fmax) + 0.5*(fmax-fmin)*sin(2*pi*k/T);
LPF(k,:) = sin(2*pi*f*n/Fs + phi);
phi = mod(phi + 2*pi*f*size(LPF,2)/Fs, 2*pi);
end