How to plot the frequency spectrum of a signal on Matlab?
Mostra commenti meno recenti
Hello everybody I have already developed a small code with a lot of help from Mathworks and the help function (in Matlab), and from some forums but I need someone to help me with my code. It's pretty much working but the spectrum's amplitude is not going according to theory. It should be half of the carrier's amplitude which in my case should be 25 volts, but Matlab's plot gives 22.51 volts which is not correct also on the sidebands I am getting 8.476 volts and it should be a quarter of the carrier's amplitude which in my case is 12.5 volts.
Here is my code:
clear all;clc
Fs = 200; % Sampling frequency Fs >> 2fmax & fmax = 50 Hz
t = 0:1/Fs:7501; % length (x) = 7501
x = 50*(1+0.75*sin(2*pi*t)).*cos(100*pi*t); % AM Signal
xdft = (1/length(x)).*fft(x);
freq = -100:(Fs/length(x)):100-(Fs/length(x)); %Frequency Vector
y = abs(fftshift(xdft));
figure(1); % Plot signals in both time and frequency domain
subplot(211);plot(t,x);grid on;title 'Amplitude Modulated Signal';
axis([0 5 -100 100]);xlabel 'Time (sec)';ylabel 'Amplitude (volts)';
subplot(212);plot(freq,y);grid on;title 'AM Signal Spectrum';
axis([-60 60 0 25]);xlabel 'Frequency (Hz)';ylabel 'Amplitude (volts)';
2 Commenti
Azzi Abdelmalek
il 4 Nov 2012
What is the problem with your code?
Gabriel Borrero
il 4 Nov 2012
Risposta accettata
Più risposte (1)
Azzi Abdelmalek
il 4 Nov 2012
Modificato: Azzi Abdelmalek
il 4 Nov 2012
The frequency of your signal is F=1 Hz, Then why t = 0:1/Fs:7501
I suggest
t = 0:1/Fs:1-1/Fs
8 Commenti
Gabriel Borrero
il 4 Nov 2012
Azzi Abdelmalek
il 4 Nov 2012
what do you mean?
Gabriel Borrero
il 4 Nov 2012
Azzi Abdelmalek
il 5 Nov 2012
Modificato: Azzi Abdelmalek
il 5 Nov 2012
Don't use plot for the frequency response use instead
stem(freq,y)
the plot just joined the three impulse
Gabriel Borrero
il 5 Nov 2012
Modificato: Gabriel Borrero
il 5 Nov 2012
Azzi Abdelmalek
il 5 Nov 2012
Modificato: Azzi Abdelmalek
il 5 Nov 2012
I know, I have your code. But what is the problem now? The amplitudes are ~=10 and not 12.5, you can't get 12.5
Azzi Abdelmalek
il 5 Nov 2012
Modificato: Azzi Abdelmalek
il 5 Nov 2012
why should they be 12.5? I have also, used my code and get the same result then you
Gabriel Borrero
il 5 Nov 2012
Categorie
Scopri di più su Spectral Measurements in Centro assistenza e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!