moonnightingale
Full Member level 6
I got this code for fft but it is giving very high peak at 500.
If u take actaul fourier of COS peak is low. Plz help me to remove this problem.
I will be highly grateful for this.
Actually i want to represent the signal in frequency domain. somebody told me FFT can be used for this in MAtlab. Is there other way of doing so.
%Define number of samples to take
number_of_samples = 2^10;
cosineFreq = 10; %Hz
%Define signal
t = linspace(0, 10, number_of_samples);
signal = cos(2*pi*cosineFreq*t);
%Plot to illustrate that it is a sine wave
plot(t, signal);
title('Time-Domain signal');
%Take fourier transform
fftSignal = fft(signal);
%apply fftshift to put it in the form we are used to (see documentation)
fftSignal = fftshift(fftSignal)
%Next, calculate the frequency axis, which is defined by the sampling rate
T = t(2)-t(1);
fs = 1/T;
f = fs/2*linspace(-1,1,number_of_samples);
%Since the signal is complex, we need to plot the magnitude to get it to
%look right, so we use abs (absolute value)
figure
plot(f, abs(fftSignal));
title('magnitude FFT of cosine');
xlabel('Frequency (Hz)');
ylabel('magnitude');
If u take actaul fourier of COS peak is low. Plz help me to remove this problem.
I will be highly grateful for this.
Actually i want to represent the signal in frequency domain. somebody told me FFT can be used for this in MAtlab. Is there other way of doing so.
%Define number of samples to take
number_of_samples = 2^10;
cosineFreq = 10; %Hz
%Define signal
t = linspace(0, 10, number_of_samples);
signal = cos(2*pi*cosineFreq*t);
%Plot to illustrate that it is a sine wave
plot(t, signal);
title('Time-Domain signal');
%Take fourier transform
fftSignal = fft(signal);
%apply fftshift to put it in the form we are used to (see documentation)
fftSignal = fftshift(fftSignal)
%Next, calculate the frequency axis, which is defined by the sampling rate
T = t(2)-t(1);
fs = 1/T;
f = fs/2*linspace(-1,1,number_of_samples);
%Since the signal is complex, we need to plot the magnitude to get it to
%look right, so we use abs (absolute value)
figure
plot(f, abs(fftSignal));
title('magnitude FFT of cosine');
xlabel('Frequency (Hz)');
ylabel('magnitude');