|
楼主 |
发表于 2008-6-12 17:31
|
显示全部楼层
白噪声卷积MATLAB脚本
clc
clear all
close all
lg = inline('10*log10(abs(squeeze(x)))','x');
%% 生成伪随机信号
N = 1024; %数据点数
X = ones(N,1)*10^(-10);
X(51:200) = ones(150,1);
RandPhas = exp(j*(rand(N,1)*2*pi)); %随机相位
X = X.*RandPhas;
X(N/2+2:end) = conj(X(N/2:-1:2)); %频谱作“共轭对称”处理
x = ifft(X,'symmetric')*N; %伪随机信号生成
figure(1)
subplot(2,1,1)
plot(lg(X))
title('伪随机信号')
ylabel('Amp dB');
axis tight
subplot(2,1,2)
plot(x)
axis tight
%% 生成白噪声
N1 = 100*N;
WN = ones(N1,1);
RandPhas = exp(j*(rand(N1,1)*2*pi));
WN = WN.*RandPhas;
WN(N1/2+2:end) = conj(WN(N1/2:-1:2));
wn = ifft(WN,'symmetric')*N1;
%wn = wn-mean(wn);
figure(2)
subplot(2,1,1)
plot(lg(WN))
title('白噪声')
ylabel('Amp dB');
axis tight
subplot(2,1,2)
plot(wn)
axis tight
x_conv = conv(x,wn);
len = length(x_conv);
ave = floor(len/N);
X_CONV = zeros(N,1);
for i = 1:ave
tmp = x_conv((i-1)*N+(1:N));
TMP = fft(tmp)/N;
X_CONV = X_CONV+abs(TMP);
end
X_CONV = X_CONV/ave;
figure(3)
plot(lg(X_CONV));
title('卷积信号的频谱')
ylabel('Amp dB');
axis tight |
|