Expected a string scalar or character vector for the parameter name
13 次查看(过去 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!