规范化||使向量具有相同大小,以保留PSD数据

时间:2019-04-05 20:43:16

标签: matlab vector signals

上下文: MATLAB中的PSD=periodogram(y)给出了声源信号的PSD(功率谱密度)估计。我想在PSD的3个不同x范围内找到局部最大值。

如何制作将1:1映射到PSD -y值向量的向量? enter image description here MATLAB生成的x值是Hz-频率值,所以我不想更改其本身的值,而是创建一个从x=0:3500开始的矢量,但其元素数与PS​​D矢量相同, PSD= 32769*1 double

在保留相同数据的情况下该如何做?

PSD图。通过plot(PSD)<-x由MATLAB生成的值获取

 %% formantdaddy will try to do all the steps of the process
% 1. grab sound from folder
% 2. get PSD = Power Spectral Density
% 3. look for local maxima within prefined ranges 
    % 200 - 800 Hz
    % 800 - 1800 Hz
    % 1800 - 3500 Hz
%store data into a struct

clear all;
close all;
clc;
%% audioread .wav file
[y Fs]= audioread('100-daddy1.wav');
%% y=source signal
sourceFig=figure(1);
plot(y);
xlabel('milliseconds'); ylabel('amplitude'); title('spectrogram = voice source signal');

%% PSD - Power Spectral Density <-- peaks here should give formants
filterfcn=figure(2);
PSD=periodogram(y); %calculate the power spectral density of the source signal
plot(PSD);
ylabel('magnitude || intensity of signal'); xlabel('frequency in Hz'); title('PSD of Source');
xlim([0, .35*10^4]);
%% F1 range  
subset1=zeros(1, 601); %create a vector to store PSD values within the range of interest
for x=200:800;
    subset1(x)=PSD(x);% input in the values of interest
end

for x=200:800;
    Y_max=max(subset1);
    F1=x;
end
disp(F1);
disp(Y_max);
% find the max value within the range
%PROBLEM: wanted to find the x value which corresponded to the max y <-- but this actually is the max y value
%PROBLEM: x vector not the same size as PSD values within the range, so many points not considered. 

%% F2 range
subset2=zeros(1, 1001);
for x=800:1800;
    subset2(x)=PSD(x);
end

for x=800:1800;
    Y2_max=max(subset2);
    F2=x;
end
disp(F2);
disp(Y2_max);
%% F3 range
subset3=zeros(1, 1701);
for x=1800:3500;
    subset3(x)=PSD(x);
end
for x=1800:3500;
    Y3_max=max(subset2);
    F3=x;
end
disp(F3);
disp(Y3_max);
%% store values into a struct
Ftable=struct("FileName", "100-daddy1.wav", "F1_Hz", F1, "F2_Hz", F2, "F3_Hz", F3);

0 个答案:

没有答案