MATLAB功率谱估计

close all;
clc;
clear all;
fs = 1024;
len = 1024;
t = 0:1/fs:(len-1)/fs;
x = 5.3 * sin(2*pi*16*t);
ffty = fft(x, len);
ffty = abs(ffty) / len;
f = 0:fs/len:fs/2;
plot(f, ffty(1:len/2+1))
title('FFT')
figure
py = ffty .^ 2;
py = py * 2;
py = py ./ (fs/len);
plot(f, py(1:len/2+1))
title('PSD')

figure
[pxx, fxx] = periodogram(x, [], [],  fs);
plot(fxx, pxx)
title('periodogram')

figure
cxn=xcorr(x);%计算序列的自相关函数
cxn=cxn(len:end)+[0 cxn(1:len-1)];
CXk=fft(cxn,len);
Pxx=abs(CXk) * 2 / (len * fs);
plot_Pxx=10*log10(Pxx); 
plot(f, plot_Pxx(1:len/2+1))
title('xcorr')




互功率谱估计

clear;
clc;

fs = 1024;
len = 1024;
t = 0:1/fs:(len-1)/fs;
x = 3.7 * sin(2*pi*16*t);
y = 1.9 * sin(2*pi*32*t);

w = blackman(1024, 'periodic');

[p, f] = cpsd(x, y, w, 0, 1024, fs);
plot(f, abs(p))
title('cpsd')
max(abs(p))

z = xcorr(x, y);
cnx = z(len:end) + [0 z(1:len-1)];
w = w';
x1 = cnx .* w;
cxk1 = fft(x1, 1024);
p1=abs(cxk1) * 2 / (1024 * fs);

w1 = w .* w;
u = sum(w1) / 1024;
%p = p1/u;
p = p1;

f = 0:fs/1024:fs/2;
figure
plot(f, p(1:1024/2+1))
title('xcorr')
max(p)

复倒谱

Fs = 100;
t = 0:1/Fs:1.27;
s1 = sin(2*pi*45*t);
s2 = s1 + 0.5*[zeros(1,20) s1(1:108)];
c = cceps(s2);
plot(t,c)
xlabel('Time (s)')
title('Complex cepstrum')

h = fft(s2);
x = angle(h);
n = length(x);
y = unwrap(x);
nh = fix((n+1)/2);

idx = nh+1; 
if length(y) == 1
  idx = 1;
end
nd = round(y(idx)/pi);
y(:) = y(:)' - pi*nd*(0:(n-1))/nh;


logh = log(abs(h)) + sqrt(-1)*y;
y = real(ifft(logh));
figure
plot(t, y);
title('fft ceps')


  • 4
    点赞
  • 11
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值