Hi @AK,
To filter the blue line output signal to match the yellow line, you can implement a low-pass filter (LPF) using MATLAB's built-in functions. Since you mentioned that the LPF did not yield the desired results, it may be beneficial to adjust the filter parameters or use a different filtering approach, such as a moving average filter.Here’s a simple example using a moving average filter:
% Simulation parameters
fs = 10; % Sampling frequency (Hz)
t = 0:1/fs:10; % Time vector (10 seconds)
f_yellow = 0.886; % Frequency of yellow line (Hz)
% Generate yellow line (expected signal)
yellow_line = sin(2 * pi * f_yellow * t);
% Generate blue line (actual signal with noise)
blue_line = yellow_line + 0.1 * randn(size(t)); % Adding noise
% Apply a moving average filter
windowSize = 5; % Size of the moving average window
filtered_blue_line = movmean(blue_line, windowSize);
Note: for more information on this function, please refer to
https://www.mathworks.com/help/matlab/ref/movmean.html
% Plotting the results
figure;
plot(t, yellow_line, 'y', 'LineWidth', 2); hold on;
plot(t, blue_line, 'b', 'LineWidth', 1);
plot(t, filtered_blue_line, 'r', 'LineWidth', 1);
legend('Yellow Line (Expected)', 'Blue Line (Actual)', 'Filtered Blue Line');
title('Signal Filtering Example');
xlabel('Time (s)');
ylabel('Amplitude');
grid on;
Please see attached plot.
So, in this example code provided, the moving average filter smooths the blue line, helping it to better align with the yellow line. Adjust the windowSize parameter to optimize the filtering effect based on your specific data characteristics. Let me know if you have any further questions.