Help plotting frequency versus voltage
7 ビュー (過去 30 日間)
古いコメントを表示
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.
0 件のコメント
採用された回答
Star Strider
2017 年 2 月 20 日
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 件のコメント
Star Strider
2017 年 2 月 21 日
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.
その他の回答 (0 件)
参考
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!