欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

正弦信号频谱分析实验

程序员文章站 2022-07-03 08:47:31
...

正弦信号频谱分析实验

实验目标

1.设定采样率fs,生成正弦波,频率为f0,量化比特数为Q,幅度为A,采集N点正弦波,用W窗对采样帧加窗,然后进行N点的FFT分析,观察对数尺度下的幅度谱S。
通过配置信号的幅频特征参数以及分析参数,然后观察两正弦信号合成后信号的加窗幅度谱。这些参数包括
【1】两正弦波的幅度A、频率f0
【2】信号的量化比特数Q(通常为8-16)
【3】信号采样率fs
【4】凯泽窗的beta值,注意,beta=0时,等价位矩形窗,beta越大,主瓣越宽,旁瓣越低。
【5】信号的采样长度N,亦即DFT谱分析的长度
参考实验:
采样率fs=512E3,频率f0=20.0E3,量化比特数Q=12,幅度A=10;N=512,W窗为kaiser窗

%///////////////////////////////////////////////////////////
% DFT analyse of sampled sine signal
%///////////////////////////////////////////////////////////
close all;
clear;
clc;
% generate 2 sampled sine signals with different frequency(生成2个不同频率的采样正弦信号)
freq_x1         = 20.0E3        ;  % frequency of signal x1
amp_x1          = 10            ;  % amptitude of signal x1
freq_x2         = 30.0E3        ;  % frequency of signal x2
amp_x2          = 10            ;  % amptitude of signal x2
data_len        = 512           ;  % signal data length
fs              = 512E3         ;  % sample rate(采样率)
quant_bits      = 12            ;  % signal quant bits(信号量化比特数)
kaiser_beta     = 8             ;  % beta of kaiser win

idx_n           = [0:data_len-1];  % n index
idx_n           = idx_n .'      ;  % we need column vector(列向量)
idx_t           = idx_n/fs      ;  % time index
idx_phase_x1    = 2*pi*idx_n*freq_x1/fs;  % x1 phase  index(x1相位指数)
idx_phase_x2    = 2*pi*idx_n*freq_x2/fs;  % x2 phase  index
x1              = amp_x1*sin(idx_phase_x1);
x2              = amp_x2*sin(idx_phase_x2);
% signal x is consisted of x1 and x2;
x = x1 + x2;
max_abs_x = max(abs(x));    %   abs-求数值的绝对值与复数的幅值  %  normalize x to (-1,1)
x = x / max_abs_x;           % quant signal, the range is (-max_q, +max_q)
max_q = 2^(quant_bits-1);
x_quant = fix(x * max_q);   % plot them, use time label
figure;
set(gca,'fontsize',16);     % get window function data(获取窗口函数数据)(set-设置对象属性)
win = kaiser(data_len, kaiser_beta);    % windowing the data
win_x       =  win .* x;
win_x_quant =  win .* x_quant;

h_t1 = subplot(4,1,1);plot(idx_t, x1   );grid on;
h_t2 = subplot(4,1,2);plot(idx_t, x2   );grid on;
h_t3 = subplot(4,1,3);plot(idx_t, x    );grid on;
h_t4 = subplot(4,1,4);plot(idx_t, win_x);grid on;
title(h_t1, 'x1'        , 'fontsize', 14);
title(h_t2, 'x2'        , 'fontsize', 14);
title(h_t3, 'x=x1+x2'   , 'fontsize', 14);
title(h_t4, 'windowed x', 'fontsize', 14);

% perform fft(fft变换)
x_q_fft         =  fft(win_x_quant)    ;    % get frequency index(指数)
idx_freq        = -fs/2 + idx_n .* (fs / data_len);
% shift zero frequency to the data center(将0频移动到数据中心位置)
x_q_fft         =  fftshift(x_q_fft);
% map to amptitude dB scale
x_q_fft_abs     =  abs(x_q_fft);
x_q_fft_abs_dB  =  20*log10(x_q_fft_abs + 1E-8);
% normalize the spectrum from 0 dB;(从0db开始归一化频谱)
max_dB = max(x_q_fft_abs_dB);
norm_spectrum   =  x_q_fft_abs_dB - max_dB;
figure; plot(idx_freq, norm_spectrum);grid on;
title('Normlized Spectrum ', 'fontsize', 14);

实验结果如下:
正弦信号频谱分析实验
频谱S正弦信号频谱分析实验
【2】对以上过程的参数, fs, f0, Q, A, N, W 进行修改,观察S的变化

相关标签: 信号处理