Expected a string scalar or character vector for the parameter name
13 views (last 30 days)
Show older comments
% 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 Comments
Answers (1)
Brahmadev
on 27 Dec 2023
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 Comments
See Also
Categories
Find more on Measurements and Feature Extraction in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!