Create a plot of a signal

4 vues (au cours des 30 derniers jours)
Miguel Albuquerque
Miguel Albuquerque le 5 Juil 2022
Modifié(e) : Ishaan Mehta le 12 Juil 2022
Hey guys thanks in advance,
Basically I have this code, that for two signals( reference and surveillance) with 30 million samples each one, correlates them in doppler and delay.
But this correlation is very heavy, so I want to correlate a thousand samples individually , spaced between 3000 samples.
This means first I want to correlate reference_signal(1:1000) and surveillance_signal(1:1000), and save the plot. Next iteration, reference_signal(4000:5000) and surveillance_signal(4000:5000), and save the plot, and so on till the end of the samples.
Is there a way of doing this in MATLAB with a good matlab way?
nRef = numel(Reference_signal)/Fs;
nSurv = numel(Surveillance_signal)/Fs;
pulse_size = 500000;
for k = 1:nRef
Reference_signal_samples =Reference_signal((k-1)*pulse_size+(1:pulse_size));
for kk =1:nSurv
Surveillance_signal_samples=Surveillance_signal((kk-1)*pulse_size+(1:pulse_size));
[afmag3,delay3,doppler3] = ambgfun(Reference_signal_samples,Surveillance_signal_samples,Fs,[250000 250000]);
afmag3(afmag3>1 )= 1;
end
end
figure;
subplot(3,2,3)
surf(delay3,doppler3,afmag3,'LineStyle','-.');
shading interp;
axis([-0.5e-5 0.5e-5 -10000 10000]);
grid on;
view([140,35]);
colorbar;
xlabel('Doppler (Hz)');
ylabel('Ambiguity Function Magnitude');
title('Ambiguity Function Sref');

Réponse acceptée

Ishaan Mehta
Ishaan Mehta le 6 Juil 2022
Modifié(e) : Ishaan Mehta le 12 Juil 2022
Hey Miguel
I understand that you want to process a long array in batches while leaving out a fixed number of elements in between, and save the results of each iteration.
You can use MATLAB's reshape function to reshape the array into a form appropriate for your batching and spacing requirements, and use the saveas function to save the plot results if needed.
Below is a code snippet for your reference.
% dummy data for demo
Reference_signal_samples = (1:30000000) .* 1;
Surveillance_signal_samples = (1:30000000) + 0.1;
% reshaping according to the needed size and spacing
reference_reshaped = reshape(Reference_signal_samples, 1000, 4, []);
surveillance_reshaped = reshape(Surveillance_signal_samples, 1000, 4, []);
% printing some values for demo
reference_reshaped(:,1,1)
ans = 1000×1
1 2 3 4 5 6 7 8 9 10
reference_reshaped(:,1,2)
ans = 1000×1
4001 4002 4003 4004 4005 4006 4007 4008 4009 4010
reference_reshaped(:,1,3)
ans = 1000×1
8001 8002 8003 8004 8005 8006 8007 8008 8009 8010
% looping through the entire array
sz = size(reference_reshaped)
sz = 1×3
1000 4 7500
for i = 1:sz(3)
% in every iteration, these variables will have 1000 samples
% skipping 3000 samples after the last iteration
r = reference_reshaped(:,1,i);
s = surveillance_reshaped(:,1,i);
% use r and s to do further processing and plotting
end
Hope it helps
Ishaan Mehta
  2 commentaires
Miguel Albuquerque
Miguel Albuquerque le 6 Juil 2022
Modifié(e) : Miguel Albuquerque le 6 Juil 2022
It is very helpful, I have only two doubts.
When I run the for cycle, Am I running the entire samples of the signals, or I must change something?
I ran it, and I got this reference_reshape= 1000*4*75000 and sZ=[1000,4,75000], What does this mean?
Thank you a lot
Ishaan Mehta
Ishaan Mehta le 12 Juil 2022
Modifié(e) : Ishaan Mehta le 12 Juil 2022
Hey Miguel
The for loop will process entire 30 million samples as per your requirements.
For 30 million samples, the loop will have 7500 iterations, one for each time you want to calculate correlation.
Since for each iteration, we use 1000 elements, and then skip the next 3000 elements, we are effectively processng 4000 elements per cycle.
Total cycles = 30 million / 4000 = 7500.
I have also updated the sample code in my answer to print the value of sz.
Hope this helps
Ishaan

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Logical dans Help Center et File Exchange

Tags

Produits


Version

R2021b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by