当前位置:网站首页>Power Spectral Density Estimates Using FFT---MATLAB
Power Spectral Density Estimates Using FFT---MATLAB
2022-07-02 09:41:00 【小宇2022】
% Power Spectral Density Estimates Using FFT
% pr8_2_1
clear all; clc; close all;
randn('state',0); % 随机数初始化
Fs = 1000; % 采样频率
t = 0:1/Fs:1-1/Fs; % 时间刻度
f1=50; f2=120; % 两个正弦分量频率
x=cos(2*pi*f1*t)+3*cos(2*pi*f2*t)+randn(size(t)); % 信号
% 使用FFT
N = length(x); % x长度
xdft = fft(x); % FFT
xdft = xdft(1:N/2+1); % 取正频率
psdx = (1/(Fs*N)) * abs(xdft).^2; % 计算功率谱密度
psdx(2:end-1) = 2*psdx(2:end-1); % 乘2(2:end-1)
freq = 0:Fs/length(x):Fs/2; % 频率刻度
subplot 211
plot(freq,10*log10(psdx),'k') % 取对数作图
grid on; xlim([0 Fs/2]);
title('用FFT的周期图')
xlabel('频率/Hz')
ylabel('功率谱密度/(dB/Hz)')
% 调用periodogram函数
[Pxx,f]=periodogram(x,rectwin(length(x)),N,Fs);
subplot 212
plot(freq,10*log10(Pxx),'k'); % 取对数作图
grid on; xlim([0 Fs/2]);
title('调用periodogram函数的周期图')
xlabel('频率/Hz')
ylabel('功率谱密度/(dB/Hz)')
mxerr = max(psdx'-Pxx) % 求两种方法的最大差值
set(gcf,'color','w');
边栏推荐
猜你喜欢
map集合赋值到数据库
ctf 记录
RPA advanced (II) uipath application practice
亚马逊云科技 Community Builder 申请窗口开启
Redis exceeds the maximum memory error oom command not allowed when used memory & gt; ' maxmemory'
揭露数据不一致的利器 —— 实时核对系统
Tiktok overseas tiktok: finalizing the final data security agreement with Biden government
HOW TO CREATE AN INTERACTIVE CORRELATION MATRIX HEATMAP IN R
Cluster Analysis in R Simplified and Enhanced
2022年4月17日五心红娘团队收获双份喜报
随机推荐
Writing contract test cases based on hardhat
ASTParser 解析含有emum 枚举方法的类文件的踩坑记
ros缺少xacro的包
mmrotate旋转目标检测框架使用记录
mysql链表数据存储查询排序问题
liftOver进行基因组坐标转换
PHP query distance according to longitude and latitude
基于Hardhat编写合约测试用例
ren域名有价值吗?值不值得投资?ren域名的应用范围有哪些?
Cluster Analysis in R Simplified and Enhanced
TDSQL|就业难?腾讯云数据库微认证来帮你
JS——每次调用从数组里面随机取一个数,且不能与上一次为同一个
How to Visualize Missing Data in R using a Heatmap
Importerror: impossible d'importer le nom « graph» de « graphviz»
R HISTOGRAM EXAMPLE QUICK REFERENCE
抖音海外版TikTok:正与拜登政府敲定最终数据安全协议
map集合赋值到数据库
MySQL comparison operator in problem solving
Tdsql | difficult employment? Tencent cloud database micro authentication to help you
启牛商学院给的股票账户安全吗?能开户吗?