Matlab功率谱图

时间:2016-04-19 07:45:28

标签: matlab signal-processing fft

我想在-2000到+ 2000 Hz的频率范围内绘制特定 .wav 声音文件的功率谱图。

尝试:

到目前为止,这是我的代码:

[s, Fs] = wavread('chord.wav');
Hs=spectrum.periodogram;
psd(Hs,s,'Fs',Fs)

我尝试使用周期图算法。但结果plot的范围为0到20,000 Hz。那么,如何修改代码以便将其绘制在-2000到+ 2000 Hz之间呢?

非常感谢任何帮助。

2 个答案:

答案 0 :(得分:0)

我修改了此支持page

中的一个示例
    Fs = 32e3;   
    t = 0:1/Fs:2.96;
    x = cos(2*pi*t*1.24e3)+ cos(2*pi*t*10e3)+ randn(size(t));
    nfft = 2^nextpow2(length(x));
    Pxx = abs(fft(x,nfft)).^2/length(x)/Fs;
    Hpsd = dspdata.psd(Pxx(1:length(Pxx)/2),'Fs',Fs);  
    plot(Hpsd)

enter image description here

figure
plot(Hpsd)
axis([9.8 10.2 -90 0])  %change axis range

enter image description here

答案 1 :(得分:0)

我编写了这段代码,用于对任何时间历史向量进行FFT,其中T是时间步长向量,S是相关位移或您希望绘制其光谱的任何给定量。 ps:STfile是我所有自由度的模型位移时间历史,我把它保存为.mat文件

    clc
clear

load STfile

% is your starting vector of time

data = S(:,12); % vector of data you want to resample 

N = length(T);

for ii=1:(N-1)
    DT(ii) = T(ii+1)-T(ii);
end

DTS = mean(DT);


data_TS = timeseries(data,T); % define the data as a timeseries 

new_T = T(1):DTS:T(end); % new vector of time with fixed dt=1/fs

data_res = resample(data_TS,new_T); % data resampled at constant fs

plot(data_res)

y=getdatasamples(data_res,1:N);

Fs=1./DTS;
NFFT = 2^nextpow2(N);
Y = fft(y,NFFT)/N; % the division by N is to scale the amplitude

freq = Fs/2*linspace(0,1,NFFT/2+1); % vector of frequencies for the plot
figure()
plot(freq,2*abs(Y(1:NFFT/2+1)),'r') % multiplicated by 2 to recover the energy related
% to the negative frequencies since in this way only half spectrum is plotted
xlabel('Frequency(rad/sec)')
xlim([0 0.05])

example result for this code(time history of heave velocity)