Effacer les filtres
Effacer les filtres

I am getting an empty figure for a given code

2 vues (au cours des 30 derniers jours)
Roudy Hanna
Roudy Hanna le 20 Juin 2020
Commenté : Roudy Hanna le 21 Juin 2020
Hello, I have been given the following code and the data as well. However when i run it, the figure is empty. I cant find the problem and there is no error. (maybe the problem is with the findpeaks function)
Can someone help me?
Thank you !!
load modulation_125911_0dBAtt_1kOhm_100kOhmPort6.mat
set(0, 'DefaultAxesFontSize',14)
set(0, 'defaultLineLineWidth', 1.5)
R = data{1}+1i*data{2};
Rs = squeeze(R);
phi = scan.loops(1).rng;
phi = linspace(phi(1), phi(2), scan.loops(1).npoints);
freq = scan.loops(2).rng;
freq = linspace(freq(1), freq(2), scan.loops(2).npoints);
ref1x = [1, 402];
ref2x = [1, 402]; % just so i dont get an error... should be adjusted when i see the plot!
w = .5*tanh((freq-3e9)/5e7)+.5;
phase = exp(1i*(freq-freq(1))*-7e-10);
ref = w.*mean(data{1}(:, ref2x(1):ref2x(2))') ...
+ (1-w).*mean(data{1}(:, ref1x(1):ref1x(2))') ...
+1i * ( w.*mean(data{2}(:, ref2x(1):ref2x(2))') ...
+ (1-w).*mean(data{2}(:, ref1x(1):ref1x(2))'));
offset = 0;
R = data{1}+1i*data{2};
Rcorr = (R.*repmat(phase, length(phi), 1)' - offset) ...
./repmat(ref.*phase - offset, length(phi), 1)';
% Load flux/frequency data
phi = scan.loops(1).rng;
phi = linspace(phi(1), phi(2), scan.loops(1).npoints);
ph = phi(1:end-1);
freq = scan.loops(2).rng;
freq = linspace(freq(1), freq(2), scan.loops(2).npoints)./1e9;
% Calculate crude estimate for mA to Phi_0 conversion
%[~, ind] = max(diff(Rs, 1, 2));%
%[~, ind] = min(Rcorr);%
%osc = freq(ind);
%[~, ind] = min(osc(lB:uB));
Rdiff = diff(Rs,1,2);
osc = [];
phi_red = [];
for i=1:length(phi)-1
[a, locs] = findpeaks(abs(Rdiff(:, i)), 'MinPeakProminence', 0.07);
if(~isempty(locs))
if(length(locs) > 1)
[~, locs] = max(abs(Rdiff(locs, i)));
end
% cut away a lower frequecies
if(freq(locs) > 5.8)
osc = vertcat(osc, freq(locs));
phi_red = vertcat(phi_red, phi(i));
end
end
end
osc = smooth(osc)';
% osc = vertcat(osc(50:160), osc(597:706));
figure(1);
plot(phi_red, osc,'.');
drawnow;

Réponse acceptée

Mara
Mara le 20 Juin 2020
Hello,
Your variable phi_red is empty. Because your variable loc is empty, it does not run the if(~isempty(locs) command and replace your variable that you previously defined as phi_red = [ ];
The problem seems to be the specification 'MinPeakProminence', 0.07, with this, no 'relevant' peaks are found.
  11 commentaires
Rik
Rik le 20 Juin 2020
It is better to work with functions, which will automatically keep your workspace clear, and will even warn you about variables you're not using (which might point you to a typo).
Roudy Hanna
Roudy Hanna le 21 Juin 2020
Deal, I will make sure to define it as a function then!!
Many thanks!!

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Signal Generation, Manipulation, and Analysis dans Help Center et File Exchange

Produits


Version

R2019a

Community Treasure Hunt

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

Start Hunting!

Translated by