Calculate and plot linear amplitude versus linear frequency.
24 次查看(过去 30 天)
显示 更早的评论
The only thing I need from this question is to make a plot of linear amplitude vs linear frequency and how to make my plots so that their ranges are between 10 and 400 Hz.
Here is the question:
The file filter1.mat contains the spectrum of a fourth-order lowpass filter as variable x in dB. The file also contains the corresponding frequencies of x in variable freq. Plot the spectrum of this filter both as dB versus log frequency and as linear amplitude versus linear frequency. The frequency axis should range between 10 and 400 Hz in both plots. Hint: Use Equation 2.23.
(2.23) SNRlinear = 10^(dB/20)
clear all;
close all;
clc;
load filter1.mat;
logf = log(freq); % Calculate natural log of frequency
subplot(2,1,1);
plot(x,freq); % Plot spectrum of 4th order lowpass filter
subplot(2,1,2);
plot(x,logf); % Plot x in dB vs natural log of frequency
subplot(2,2,1);
采纳的回答
Voss
2023-2-16
One thing is that you're calling plot with the inputs reversed. The syntax is plot(x,y); in this case, frequency (the variable freq or logf) is x, and amplitude (the variable x, etc.) is y, so it would be plot(freq,x), etc. (No doubt your professor's naming the amplitude "x" contributed to the confusion.)
To set the frequency range of the plots, use xlim.
clear all;
close all;
clc;
load filter1.mat;
logf = log(freq); % Calculate natural log of frequency
linx = 10.^(x/20); % Calculate linear amplitude (Equation 2.23)
subplot(2,1,1);
plot(logf,x); % Plot x in dB vs natural log of frequency
xlim(log([10 400])) % set frequency axis range 10 to 400 Hz
xlabel('log(Frequency)')
ylabel('Amplitude, dB')
title('dB Amplitude vs log(Frequency)')
subplot(2,1,2);
plot(freq,linx); % Plot x (linear) vs frequency (linear)
xlim([10 400]) % set frequency axis range 10 to 400 Hz
xlabel('Frequency')
ylabel('Amplitude')
title('Linear Amplitude vs Frequency')
I would probably use log10 instead of log in both places where log is used, but I don't know that that's required. The question seems ambiguous about that.
0 个评论
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Fourier Analysis and Filtering 的更多信息
产品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!