- Technical Services and Consulting
- Embedded Systems | Firmware Developement | Simulations
- Electrical and Electronics Engineering
Plotting multiple plots on the same graph
5 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
So I am trying to plot this noisy data, and the output from each individula filter on the same graph. The filters are in cascade so the output to one is the input to the other. The first figure works, but the second one I can't seem to fix. I added hold on/off which didnt help and don't know what to try next. Thank you for your time!
fs = 20e3;
numFilts = 32;
filter_number = 16;
t = linspace(0,2*pi,200);
input = sin(t) + 0.25*rand(size(t));
%
figure
hold on
for ii = 1:filter_number
output = gammatone(input, CenterFreqs(ii), fs);
plot(output)
LEGs{ii} = ['Filter # ' num2str(ii)]; %assign legend name to each
legend(LEGs{:})
legend('Show')
end
figure %This one!!
plot(t, input, 'k-', 'LineWidth', 2, 'DisplayName', 'Data')
plot(t,output(ii,:), 'LineWidth', 1.25)
title('Signal after Filters up to Filter', num2str(filter_number));
xlabel('t')
ylabel('x(t) & x_{filtered} (t)')
0 commentaires
Réponses (1)
Hassaan
le 4 Fév 2024
Modifié(e) : Hassaan
le 4 Fév 2024
@S Try this and let me know:
fs = 20e3;
numFilts = 32;
filter_number = 16;
t = linspace(0, 2*pi, 200);
input = sin(t) + 0.25*rand(size(t));
% Define the center frequencies for the filters (example: linearly spaced)
lowFreq = 200; % lowest center frequency
highFreq = fs/2; % highest center frequency (Nyquist frequency)
CenterFreqs = linspace(lowFreq, highFreq, numFilts);
% Initialize the cumulative output variable
cumulative_output = input;
figure
hold on
% Apply the filters in cascade and plot the outputs
for ii = 1:filter_number
output = gammatone(cumulative_output, CenterFreqs(ii), fs);
cumulative_output = output; % Update the cumulative output
plot(t, output, 'LineWidth', 1.25)
LEGs{ii} = ['Filter # ' num2str(ii)]; % Assign legend name to each
end
% Add the original data to the plot
plot(t, input, 'k-', 'LineWidth', 2, 'DisplayName', 'Original Data')
legend(LEGs{:}, 'Original Data') % Add the original data to the legend
hold off
title(['Signal after Filters up to Filter ' num2str(filter_number)]);
xlabel('t')
ylabel('x(t) & x_{filtered} (t)')
The gammatone function you're using should be correctly defined or available in your MATLAB path for the script to work.
-----------------------------------------------------------------------------------------------------------------------------------------------------
If you find the solution helpful and it resolves your issue, it would be greatly appreciated if you could accept the answer. Also, leaving an upvote and a comment are also wonderful ways to provide feedback.
It's important to note that the advice and code are based on limited information and meant for educational purposes. Users should verify and adapt the code to their specific needs, ensuring compatibility and adherence to ethical standards.
Professional Interests
Feel free to contact me.
6 commentaires
Voir également
Catégories
En savoir plus sur 2-D and 3-D Plots dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!