Expected a string scalar or character vector for the parameter name
조회 수: 5 (최근 30일)
이전 댓글 표시
% Set parameters
f_c = 0.002; % Hz, sinusoidal signal frequency
theta_range = [-pi, pi]; % radians, phase range
T = 1000; % seconds, signal duration
A = sqrt(2); % amplitude for unit average energy
No = 1; % power spectral density of noise
M = 500; % number of realizations for averaging
% Generate time vector
t = linspace(0, T, 10001);
% Autocorrelation function initialization
R_x_tau = zeros(1, length(t));
% Loop for M realizations
for i = 1:M
% Generate random phase
theta = theta_range(randi(2))*pi;
% Generate sinusoidal signal
x_t = A*cos(2*pi*f_c*t + theta);
% Generate white Gaussian noise
noise = randn(size(t)) * sqrt(No/2);
% Generate signal with noise
x_t_noise = x_t + noise;
end
% Loop for different tau values
for tau = 1:length(t)
% Calculate product for current tau
product_tau = x_t_noise(tau + 1:end) .* x_t_noise(1:end-tau);
% Calculate and accumulate average product
R_x_tau(tau) = R_x_tau(tau) + 1/M * mean(product_tau);
end
% Calculate theoretical autocorrelation function
R_x_theo = 2*A^2*cos(2*pi*f_c*t) + 2*No*delta(t);%%%%%%%%%%%%%%%%%%%%ERROR
% Plot results
figure;
subplot(211);
plot(t, x_t_noise);
xlabel('Time (s)');
ylabel('Signal with Noise');
title('Sinusoidal Signal with White Gaussian Noise');
subplot(212);
plot(t, R_x_tau);
hold on;
plot(t, R_x_theo);
legend('Estimated Autocorrelation', 'Theoretical Autocorrelation');
xlabel('Time (s)');
ylabel('Autocorrelation Function');
title('Autocorrelation Function of Signal with Noise');
댓글 수: 3
답변 (1개)
Brahmadev
2023년 12월 27일
I understand that you would like to calculate the autocorrelation using the Dirac Delta function, you can use the 'dirac' function. Please refer to the documentation below for more information.
Hope this helps in resolving your query!
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Measurements and Feature Extraction에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!