利用 FFT 运算恢复原来的信号,PSD和原来信号之间的关系

说明:利用FFT运算实现信号的重构

https://ww2.mathworks.cn/help/signal/ug/practical-introduction-to-frequency-domain-analysis.html
%% 周期图求法的原理解析
rng default
Fs = 1000;
t = 0:1/Fs:1-1/Fs;
x = cos(2*pi*100*t) + randn(size(t));
N = length(x);
xdft = fft(x);
xdft = xdft(1:N/2+1);
psdx = (1/(Fs*N)) * abs(xdft).^2;
psdx(2:end-1) = 2*psdx(2:end-1);
freq = 0:Fs/length(x):Fs/2;

plot(freq,10*log10(psdx),'*')
grid on
title('Periodogram Using FFT')
xlabel('Frequency (Hz)')
ylabel('Power/Frequency (dB/Hz)')
%
% figure
hold on
[p f]=periodogram(x,rectwin(length(x)),length(x),Fs)
plot(f,10*log10(p),'ro')



return

一、 信号建模

% Use Fourier transforms to find the frequency components of a signal buried in noise.

% Specify the parameters of a signal with a sampling frequency of 1 kHz and a signal duration of 1.5 seconds.

Fs = 1000;            % Sampling frequency                    
T = 1/Fs;             % Sampling period       
L = 1500;             % Length of signal
t = (0:L-1)*T;        % Time vector
Form a signal containing a 50 Hz sinusoid of amplitude 0.7 and a 120 Hz sinusoid of amplitude 1.

S = 0.7*sin(2*pi*50*t) + sin(2*pi*120*t);
% Corrupt the signal with zero-mean white noise with a variance of 4.

X = S + 2*randn(size(t));
% Plot the noisy signal in the time domain. It is difficult to identify the frequency components by looking at the signal X(t).

plot(1000*t(1:50),X(1:50))
title('Signal Corrupted with Zero-Mean Random Noise')
xlabel('t (milliseconds)')
ylabel('X(t)')

二、 利用FFT恢复信号


% Compute the Fourier transform of the signal.

Y = fft(X);
% Compute the two-sided spectrum P2. Then compute the single-sided spectrum P1 based on P2 and the even-valued signal length L.

P2 = abs(Y/L);
P1 = P2(1:L/2+1);% 取右半部分
P1(2:end-1) = 2*P1(2:end-1);% 除掉两头的乘2% Define the frequency domain f and plot the single-sided amplitude spectrum P1. The amplitudes are not exactly at 0.7 and 1, as expected, because of the added noise. On average, longer signals produce better frequency approximations.

f = Fs*(0:(L/2))/L; % 频率范围
plot(f,P1) 
title('Single-Sided Amplitude Spectrum of X(t)')
xlabel('f (Hz)')
ylabel('|P1(f)|')


% Now, take the Fourier transform of the original, uncorrupted signal and retrieve the exact amplitudes, 0.7 and 1.0.
% 无噪声干扰条件恢复原来信号
Y = fft(S);
P2 = abs(Y/L);
P1 = P2(1:L/2+1);
P1(2:end-1) = 2*P1(2:end-1);

plot(f,P1) 
title('Single-Sided Amplitude Spectrum of S(t)')
xlabel('f (Hz)')
ylabel('|P1(f)|')

获取信号的幅度和频率
信号的重构

信号的功率谱密度(周期图求PSD)

功率谱密度与幅度变换之间的关系
具体的步骤是:
信号S经过FFT变换,再除以N,取左半部分,即 1:N/2+1;
(1)对其进行取abs,
然后两端数值保持不变,对中间部分乘以2(因为对称性),即得到对应的幅频部分;
(2)对其进行取abs,并进行平方运算,再除以采样速率Fs,
然后两端数值保持不变,对中间部分乘以2(因为对称性),即得到对应的功率谱密度部分;
对应的频率范围为 f = Fs*(0:(L/2))/L; 即 freq = 0:Fs/length(S):Fs/2;
2.1 对2中对应的功率谱密度数值取对数,即为周期图Periodogram求PSD

%% ------------------------ %%

% 分析由原始信号 求出对应的幅度谱 功率谱 功率谱密度
% 验证自带的函数 periodogram 求功率谱 功率谱密度之间的关系
% fft 得出的未双边带的频谱 转换成对应的单边带频谱为: 
% P2 = abs(Y)/L; 幅度谱估计
% P2 = abs(Y).^2/L/L; 功率谱谱估计
% P2 = abs(Y).^2/L/Fs;  功率谱密度估计

% P1 = P2(1:L/2+1);
% P1(2:end-1) = 2*P1(2:end-1);
% f = (0:(L/2))*Fs/L;
%
%
clc;close all;clear;
% -- 分析实例
rng default
Fs = 1000;            % Sampling frequency                    
T = 1/Fs;             % Sampling period       
L = 1500;             % Length of signal
t = (0:L-1)'*T;        % Time vector

X= 0.7*sin(2*pi*50*t) + sin(2*pi*120*t);
% X = X+ 2*randn(size(t));
plot(1000*t(1:50),X(1:50))
title('Signal Corrupted with Zero-Mean Random Noise')
xlabel('t (milliseconds)')
ylabel('X(t)')
Y = fft(X);
% Compute the two-sided spectrum P2. Then compute the single-sided spectrum P1 based on P2 and the even-valued signal length L.


%% 求幅度谱
P2 = abs(Y)/L; 
P1 = P2(1:L/2+1);
P1(2:end-1) = 2*P1(2:end-1);
% Define the frequency domain f and plot the single-sided amplitude spectrum P1. The amplitudes are not exactly at 0.7 and 1, as expected, because of the added noise. On average, longer signals produce better frequency approximations.

f = (0:(L/2))*Fs/L;
figure(2)
plot(f,P1) 
title('Single-Sided Amplitude Spectrum of X(t)')
xlabel('f (Hz)')
ylabel('|P1(f)|')
%% 求功率谱
P2 = abs(Y).^2/L/L; 
P1 = P2(1:L/2+1);
P1(2:end-1) = 2*P1(2:end-1);
% Define the frequency domain f and plot the single-sided amplitude spectrum P1. The amplitudes are not exactly at 0.7 and 1, as expected, because of the added noise. On average, longer signals produce better frequency approximations.

f = (0:(L/2))*Fs/L;
figure(3)
% plot(f,P1) 
plot(f,10*log10(P1)) 

title('功率谱')
xlabel('f (Hz)')
ylabel('功率')
figure(31)
[a b]=periodogram(X,[],L,Fs,'power');
plot(b,10*log10(a)) 
figure(gcf)
%% 求功率谱密度
P2 = abs(Y).^2/L/Fs; 
P1 = P2(1:L/2+1);
P1(2:end-1) = 2*P1(2:end-1);

f = (0:(L/2))*Fs/L;
figure(4)
plot(f,P1) 
title('功率谱密度')
xlabel('f (Hz)')
figure(5)
plot(f,10*log10(P1)) 
title('功率谱密度')
xlabel('f(Hz)')
figure(51)
periodogram(X,[],L,Fs);figure(gcf)
% 验证双边带功率谱密度
figure(52)
periodogram(X,[],L,Fs,'twosided');figure(gcf)
figure(53)
periodogram(X,[],L,Fs,'centered');figure(gcf)

%% dsp 
scope = dsp.SpectrumAnalyzer('SampleRate',Fs);
% scope.ViewType = 'Spectrogram';
% scope.RBWSource = 'Property';
% scope.RBW = 500;
% scope.TimeSpanSource = 'Property';
% scope.TimeSpan = 2;
% scope.PlotAsTwoSidedSpectrum = false;
scope.PlotAsTwoSidedSpectrum = true;
% X=X';
for idx = 1:50
  y = X+ 0.05*randn(size(X));
  scope(y);
end

release(scope)


(1) 单边带功率谱密度

在这里插入图片描述

(2)双边带功率谱密度

在这里插入图片描述

(3)双边带功率谱密度(平移中心)

在这里插入图片描述
在这里插入图片描述

补充:

在这里插入图片描述

在这里插入图片描述

数字角频率和模拟角频率之间的关系
在这里插入图片描述
在这里插入图片描述

  1. T不变 τ减小时:普线间距不变,但每两个零点间距离增大。在这里插入图片描述
  2. τ一定 T增大: 频谱变密,幅度减小。
    由此可推出,周期无限长时,信号变为非周期信号,谱线由离散谱变为连续谱。在这里插入图片描述
  • 2
    点赞
  • 30
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
MATLAB可以利用DFT(离散傅里叶变换)、DTFT(离散时间傅里叶变换)和FFT(快速傅里叶变换)来进行一维信号频谱分析。 DFT是一种将连续信号转换为离散信号的方法,它将信号从时域转换到频域。在MATLAB中,可以使用fft函数来实现离散傅里叶变换。通过对待分析的一维信号应用fft函数,可以得到该信号的频谱表示。输出的频谱包含了信号的振幅和相位信息,并以复数形式表示。 DTFT是一种将离散信号转换为连续信号的方法,它将离散信号从时域转换到频域。在MATLAB中,可以使用fft函数的连续变量版本fftshift和ifftshift来实现离散时间傅里叶变换。利用fftshift和ifftshift函数可以实现信号的频谱平移和反平移操作,从而更好地观察频谱特征。 FFT是一种快速计算DFT的算法,能够大大提高计算效率。在MATLAB中,fft函数实际上就是基于FFT算法实现的。通过对一维信号应用fft函数,可以直接得到信号的频谱表示。fft函数的输出结果与DFT相同,包含信号的振幅和相位信息。 在MATLAB中,可以使用这些函数对一维信号进行频谱分析。首先,通过将信号输入到相应的函数中,可以得到信号的频谱表示。然后,可以使用plot函数绘制频谱图形,观察信号在频域中的特征和频率成分。对频谱结果进行进一步的处理和分析,可以帮助我们更好地理解信号的特性和行为。 总之,MATLAB中的DFT、DTFT和FFT函数是进行一维信号频谱分析的常用工具,通过将信号从时域转换到频域,我们可以更好地了解信号的频率特征和频率分量。
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值