Plotting amplitude spectrum of a signal
212 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
So I need to generate a segment of 95 Hz sine wave for the duration of 35 ms, with 3.5 kHz sampling rate and display it in 2 graphs, time domain and amplitude spectrum.
I am struggling with amplitude spectrum, I imagine function fft is required, but how should it be used in this case?
Thanks in advance!
Here is my code below for representation in time domain:
Fs = 3500; % samples per second
dt = 1/Fs; % seconds per sample
StopTime = 0.35; % seconds
t = (0:dt:StopTime-dt)'; % seconds
%%Sine wave:
Fc = 95; % hertz
x = cos(2*pi*Fc*t);
% Plot the signal versus time:
plot(t,x);
xlabel('Time(S)');
title('Signal versus Time');
0 Kommentare
Antworten (3)
Ameer Hamza
am 23 Apr. 2020
Bearbeitet: Ameer Hamza
am 23 Apr. 2020
Try the following code. Also see the first example on the documentation page of ff() for more details.
Fs = 3500; % samples per second
dt = 1/Fs; % seconds per sample
StopTime = 0.35; % seconds
t = (0:dt:StopTime-dt)'; % seconds
%%Sine wave:
Fc = 95; % hertz
x = cos(2*pi*Fc*t);
% Plot the signal versus time:
subplot(2,1,1);
plot(t,x);
xlabel('Time(S)');
title('Signal versus Time');
subplot(2,1,2);
f = Fs*linspace(0, 1/2, floor(numel(x)/2));
fr = fft(x);
fr = abs(fr)/numel(x);
fr = fr(1:floor(end/2));
fr(2:end-1) = 2*fr(2:end-1);
plot(f, fr);
xlabel('Time(S)');
title('Frequency Response');
2 Kommentare
Sady
am 25 Okt. 2023
Fs = 3500; % samples per second
dt = 1/Fs; % seconds per sample
StopTime = 0.35; % seconds
t = (0:dt:StopTime-dt)'; % seconds
%%Sine wave:
Fc = 95; % hertz
x = cos(2*pi*Fc*t);
% Plot the signal versus time:
subplot(2,1,1);
plot(t,x);
xlabel('Time(S)');
title('Signal versus Time');
subplot(2,1,2);
f = Fs*linspace(0, 1/2, floor(numel(x)/2));
fr = fft(x);
fr = abs(fr)/numel(x);
fr = fr(1:floor(end/2));
fr(2:end-1) = 2*fr(2:end-1);
plot(f, fr);
xlabel('Time(S)');
title('Frequency Response');
0 Kommentare
Siehe auch
Kategorien
Mehr zu Spectral Measurements 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!