Here's my code:
close all;clc;clear all;
f=fopen ('sum_021223.txt');
Adata=cell2mat(textscan(f, '%f %f %f %f %f'));
time=Adata(:,5);
data = Adata;
data(:,5:end) = 0;
final=size(data,1);
data(1,1)=data(2,1);
testsum=sum(data,2);
Fs = .5; % Sampling frequency
T = 1/Fs; % Sampling period
L = final; % Length of signal
t = (0:L-1)*T;
t=t';
Y=fft(testsum)
P2 = abs(Y/L);
P1 = P2(1:L/2+1);
P1(2:end-1) = 2*P1(2:end-1);
f = Fs*(0:(L/2))/L;
% P1(1,1)=P1(2,1);
plot(f,P1)
title("Single-Sided Amplitude Spectrum of X(t)")
xlabel("f (Hz)")
ylabel("|P1(f)|")
I believe I setup my code correct. I am sampling data once per 2 seconds. I have 30530 rows of data (About 17 hours worth)
However my FFT just looks like a bunch of noise, and I would expect some spikes around the smaller frequencies that would represent changes in air temperature and such over the day I took the data.
The input data on Dropbox.
I tried to set P1(1,1) to be equal to P1(2,1). This somewhat helped, but not really.
Your FFT looks corect, you have a very noisy data. You can maybe plot a power spectrum of that signal. You can distinguish different parts in the signal, here is function:
close all;clc;clear all;
f=fopen ('sum_021223.txt');
Adata=cell2mat(textscan(f, '%f %f %f %f %f'));
time=Adata(:,5);
data = Adata;
data(:,5:end) = 0;
final=size(data,1);
data(1,1)=data(2,1);
testsum=sum(data,2);
Fs = .5; % Sampling frequency
T = 1/Fs; % Sampling period
L = numel(testsum); % Length of signal
t = (0:L-1)*T;
t=t';
[f,y]=MyPower(testsum,Fs);
plot(f,y)
title("Single-Sided Amplitude Spectrum of X(t)")
xlabel("f (Hz)")
ylabel("|P1(f)|")
ylim([0,6e-3]);
function [f,y]=MyPower(y,freq)
tuReal = "seconds";
samples=numel(y);
period=1/freq;
time=linspace(0,samples*period,samples)';
signal=y;
Fs=freq;
% Compute effective sampling rate.
tNumeric = time2num(time,tuReal);
[Fs,irregular] = effectivefs(tNumeric);
Ts = 1/Fs;
% Resample non-uniform signals.
x = signal;
if irregular
x = resample(x,tNumeric,Fs,'linear');
end
% Set Welch spectrum parameters.
L = fix(length(x)/4.5);
noverlap = fix(L*50/100);
win = window(#hamming,L);
% Compute the power spectrum.
[ps,f] = pwelch(x,win,noverlap,[],Fs);
w = 2*pi*f;
% Convert frequency unit.
factor = funitconv('rad/TimeUnit', 'Hz', 'seconds');
w = factor*w;
Fs = 2*pi*factor*Fs;
% Remove frequencies above Nyquist frequency.
I = w<=(Fs/2+1e4*eps);
w = w(I);
ps = ps(I);
% Configure the computed spectrum.
ps = table(w, ps, 'VariableNames', ["Frequency", "SpectrumData"]);
ps.Properties.VariableUnits = ["Hz", ""];
ps = addprop(ps, {'SampleFrequency'}, {'table'});
ps.Properties.CustomProperties.SampleFrequency = Fs;
f=ps.Frequency;
y=ps.SpectrumData;
end
The amplitude of a FFT should be depending on the length of the signal.
To display the result in a independent way the Power Spectral Density or the Amplitude Spectral Density should be used. There are calculated as follows:
Amplitude FFT = Y
Signal Length = L
Power Spectral Density PSD = Y^2/L
Amplitude Spectral Density ASD = Y/sqrt(L)
https://www.sjsu.edu/people/burford.furman/docs/me120/FFT_tutorial_NI.pdf
My problem is, that the result of the Matlab fft is already indipendent from the signal length and I do not understand if this is already a PSD or a ASD.
Let's take the Matlab example Noisy Signal: https://ch.mathworks.com/help/matlab/ref/fft.html
If we make the FFT on the same signal, but twice or ten times longer, the FFT amplitude does not change.
This because of the line:
P2 = abs(Y/L);
where the amplitude is divided through the signal length. But why is the formula different from the PSD or the ASD formula and we still obtain amplitudes indipendent from the signal length?
In this example it is shown, that the two signals, ones for 50s, ones for 500s, has almost the same amplitudes.
% Signal 1
sps = 1000; % Sampling frequency
T = 1/sps; % Sampling period
Frequency1 = 150; % frequency 1 [Hz]
SignalAmplitude1 = 1; % mm/s
Frequency2 = 45; % dominant frequency [Hz]
SignalAmplitude2 = 1.2; % mm/s
L = 50; % Length of signal, sek.
L = L*1000; % convert to ms
time = (0:L-1)*T; % Time vector
Signal = cos(2*pi*Frequency1*time)*SignalAmplitude1 + sin(2*pi*Frequency2*time)*SignalAmplitude2;
f = sps*(0:(L/2))/L;
FFTcomplex = fft(Signal);
P2 = abs(FFTcomplex)/L;
P1 = P2(:,round(1:L/2+1));
P1(:,2:end-1) = 2*P1(:,2:end-1);
Ampl_FFT_1 = P1;
% Signal 2
sps = 1000; % Sampling frequency
T = 1/sps; % Sampling period
Frequency1 = 150; % frequency 1 [Hz]
SignalAmplitude1 = 1; % mm/s
Frequency2 = 45; % dominant frequency [Hz]
SignalAmplitude2 = 1.2; % mm/s
L = 500; % Length of signal, sek.
L = L*1000; % convert to ms
time = (0:L-1)*T; % Time vector
Signal = cos(2*pi*Frequency1*time)*SignalAmplitude1 + sin(2*pi*Frequency2*time)*SignalAmplitude2;
f = sps*(0:(L/2))/L;
FFTcomplex = fft(Signal);
P2 = abs(FFTcomplex)/L;
P1 = P2(:,round(1:L/2+1));
P1(:,2:end-1) = 2*P1(:,2:end-1);
Ampl_FFT_2 = P1;
sum(Ampl_FFT_2)-sum(Ampl_FFT_1)
I am trying to FM modulate a signal but the frequency of the modulated wave remains constant. We are not allowed to use fmmod or cumsum functions, only int() or quad() functions are allowed.
% Generation of FM
clc
clearvars
sampling_freq = 1000; % fs = 1Khz
time = 0:(1/sampling_freq):0.1;
syms t
message = 0.2*cos(2*pi*10*t); % m(t) = Am*sin(2*pi*fm*t)
carrier = 1*sin(2*pi*200*t); % c(t) = Ac*sin(2*pi*fc*t)
modulator_sensitivity = 50; % Modulator sensitivity
integrated(t) = int(message, t);
modulated = 1*cos(2*pi*200*t + 2*pi*modulator_sensitivity*integrated)
beta = (modulator_sensitivity * 0.2) / 10; % beta = (kf*Am)/fm
fplot(modulated, [time(1) time(end)])
title("Message and Modulated Signal")
hold on
fplot(message, [time(1) time(end)])
Plotted message and modulated waves
I'm trying to plot the equation shown in the image, but I'm not sure how to apply the Galois Seq. "gf()" here.
Can you please help me with this?
enter image description here
clear all
close all
clc
%%
Fs = 1000; % Sampling frequency
T = 1/Fs; % Sampling period
L = 1024; % Length of signal
t = 2*(0:L-1)*T; % Time vector
signal = 0;
m = 5;
for k=1:((2^m)-1)
g = gf(2^m);
signal = signal + g(k).*exp(1i*2*pi*k*t)/((2^m)-1);
end
figure
subplot(2,2,1)
plot(t,signal)
title('signal')
I am little bit confused with fft. That would be good if anyone can help me. first, I want to convert fft output in time domain. Where t = f/k and K = BW/Tm (BW = bandwidth & Tm = transmit time). After that again i need to take fft and ouput should be box (rectangular function) which is having width of BW(40e9).
f1 = 1e6; % first cutoff frequency
f2 = 4e6; % second cutoff frequency
BW = 40e9; % bandwidth
Tm = 0.2e-3; % transmit time
fs = 1e7; % sampling frequency
c = 3e8; % speed of light
w1 = f1/ (fs/2); % normalizing first cutoff frequency
w2 = f2/ (fs/2): % normalizing second cutoff frequency
[b,a] = butter(2, [w1,w2], 'bandpass');
load('fb2040');
x = fb2040(3,:);
y_filt = filter(b,a,x); % filtering
nfft = length(y_filt);
res = fft(y_filt, nfft)/ nfft;
f = fs/2 * linspace(0,1,nfft/2+1);
res = res(1:nfft/2+1);
figure, plot(f,abs(res));
xlabel('frequency in MHz');
ylabel('amp');
return