Calculate and plot linear amplitude versus linear frequency.
9 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
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);
1 commentaire
Réponse acceptée
Voss
le 16 Fév 2023
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 commentaires
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur 2-D and 3-D Plots dans Help Center et File Exchange
Produits
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!