Plotting amplitude spectrum of a signal
212 次查看(过去 30 天)
显示 更早的评论
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 个评论
回答(3 个)
Ameer Hamza
2020-4-23
编辑:Ameer Hamza
2020-4-23
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 个评论
Sady
2023-10-25
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 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Spectral Measurements 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!