Help plotting frequency versus voltage

5 Ansichten (letzte 30 Tage)
Brian Hoblin
Brian Hoblin am 20 Feb. 2017
Kommentiert: Star Strider am 21 Feb. 2017
I've been searching around for longer than I'd like to admit trying to figure out how to make a plot of frequency vs voltage. I have a series RLC circuit in which the max voltage was taken for 5 different resistances. I need to mark on both sides of the curve at 0.707 times the max voltage. I have all of these voltage values along with their corresponding frequencies but I have no idea how to create a graph in MATLAB that does this. I found this code that comes close to what I want to do but every time I try to get rid of the 6dB marker I just get errors or a blank graph.
if true
% code
end
fyy = linspace(0, 50, 250); % Create Data
Pyy = 0.5*exp(-(fyy-15).^2) + 0.3*exp(-(fyy-40).^2); % Create Data
[pk,loc] = findpeaks(Pyy,'Npeaks',1,'SortStr','descend');
db3c = 10^(-3/10); % Relative Magnitude At -3dB
db6c = 10^(-6/10); % Relative Magnitude At -6dB
ofst = 10;
for k1 = 1:length(pk)
varmtx = [Pyy(loc(k1)-ofst:loc(k1)); fyy(loc(k1)-ofst:loc(k1)); Pyy(loc(k1):loc(k1)+ofst); fyy(loc(k1):loc(k1)+ofst)];
dBpts(k1,1:2) = interp1(varmtx(1,:), varmtx(2,:), pk(k1)*[db6c db3c], 'linear','extrap');
dBpts(k1,3:4) = interp1(varmtx(3,:), varmtx(4,:), pk(k1)*[db6c db3c], 'linear','extrap');
end
if true
% code
end
figure(1)
plot(fyy, Pyy)
hold on
for k1 = 1:length(pk)
plot(dBpts(k1,:), pk(k1)*[db6c db3c db6c db3c], 'r+')
end
hold off
grid
for k1 = 1:length(pk)
fprintf(1, '\n\t-6dB frequencies = %.3f, %.3f\n', dBpts(k1,[1 3]))
fprintf(1, '\n\t-3dB frequencies = %.3f, %.3f\n', dBpts(k1,[2 4]))
end
Could someone please help me with this? It's supposed to look like a bell curve with the mean being the resonant frequency, and the frequencies that match up with the -3dB voltage would indicate the bandwidth.

Akzeptierte Antwort

Star Strider
Star Strider am 20 Feb. 2017
If you want to ‘get rid’ of the -6 dB marker, one easy way to do it without disrupting the rest of your code is to define it as ‘NaN’:
[pk,loc] = findpeaks(Pyy,'Npeaks',1,'SortStr','descend')
db3c = 10^(-3/10); % Relative Magnitude At -3dB
db6c = 10^(-6/10); % Relative Magnitude At -6dB
db6c = NaN; % <— INSERT THIS ASSIGNMENT HERE
That worked when I used it with your code.
  2 Kommentare
Brian Hoblin
Brian Hoblin am 20 Feb. 2017
Thanks, that did get rid of that. Where in the code do I need to edit to get the -3db frequencies to equal 764 and 3609? I changed Line 2 to
if true
% code
Pyy = 0.693*exp(-(fyy-15).^2);
end
because my measurement peaked at 0.693V but as soon as I mess with the other parameters I gets errors. I need the curve to be centered at 1721 Hz and the -3db markers to be located at (764,0.490) and (3609,0.490). How would I do that?
Star Strider
Star Strider am 21 Feb. 2017
My pleasure.
I have no idea.
None of your peaks are anywhere near those frequencies. You need to look through your initial calculations to see what the problem is.

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu MATLAB finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by