0
$\begingroup$

This is the FFT I'm using. But two peaks (did not expect the one in the beginning) are occurring and the amplitude is not as specified (expecting a value of 2). Any help is much appreciated!

Amp = 2;
freqHz = 10000;
fsHz = freqHz*2+1;
dt = 1/fsHz;

sine = Amp*sin(2*pi*freqHz*(0:dt:1-dt));

transform = fft(sine,fsHz)/fsHz;
magTransform = abs(transform);

faxis = linspace(0,fsHz/2,fsHz);
plot(faxis,fftshift(magTransform));
xlabel('Frequency')

Output

$\endgroup$
  • $\begingroup$ Please clarify what your problem is: how many peaks did you expect (and why) vs how many you're getting; and what amplitude did you expect (and why) vs what you're actually getting. Do not add this information as a comment; rather, edit your question. $\endgroup$ – MBaz Jun 26 '18 at 17:09
  • $\begingroup$ Please see the picture I've uploaded $\endgroup$ – mldmnn Jun 26 '18 at 19:00
0
$\begingroup$

You need to use complex signal for that. Use this

Amp = 2; freqHz = 10000; fsHz = freqHz*2+1; dt = 1/fsHz; sine = Amp*exp(2i*pi*freqHz*(0:dt:1-dt)); transform = fft(sine,fsHz)/fsHz; magTransform = abs(transform); faxis = linspace(-fsHz/2,fsHz/2,fsHz); plot(faxis,fftshift(magTransform)); xlabel('Frequency')

$\endgroup$
0
$\begingroup$

The somehow symeetric aspect of the complex DFT might be misleading, so in the past I shared a simple Matlab function FFTR.m for real signals only, that might yield the result you'd expect ($2$ magnitude at peak frequency):

FFRT: FFT for real signals

as long as you don't try bordeline endeavours. That requires a little normalization and a special care at DC and Nyquist. The code could be:

% Signal definition
Amp = 2;
freqHz = 10000;
fsHz = freqHz*2+1;
dt = 1/fsHz;
sine = Amp*sin(2*pi*freqHz*(0:dt:1-dt));

% Graphic part
[fftR,fftAxe] = FFTR(sine',dt);
plot(fftAxe,fftR,'o-');
xlabel('Frequency')
ylabel('Magnitude')
$\endgroup$
  • 1
    $\begingroup$ Thanks! How can I achieve this with the built in function? $\endgroup$ – mldmnn Jun 26 '18 at 19:02
  • $\begingroup$ Just explore the FFT.m link I gave as a link, and steal the code :) $\endgroup$ – Laurent Duval Jun 26 '18 at 19:03
  • $\begingroup$ And if you like it, don't hesitate to upvote! $\endgroup$ – Laurent Duval Jun 30 '18 at 11:38
  • $\begingroup$ Unfortunately my rep is not sufficient :/ $\endgroup$ – mldmnn Jul 1 '18 at 11:44

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.