PSD of random track inputs - matlab

I am currently modelling a train on MATLAB/SIMULINK.
The article i following is:
https://link.springer.com/article/10.1007/s40864-016-0045-x
In the article track profile is represented by 2 slope power slope density(PSD) as the equation below:
equation
PSD of the track is represented as the equation below also:
psd equation where the Av is 0.0339 and the wc is 0.8245.
Regarding this PSD plot is found in article is:
PSD plot
I wrote the MATLAB code below for the same equation as below. However i found completely different plotting.
Can you help me about that what do you think i did wrong.
clc
clear all
%% PSD of track profile
f = 0:0.5:100; %Hz
% Av=0.0339; %Track condition identifier (cm2rad/m)
Av=0.0339*(10e-4)/(2*pi); %m2Hz/m
%wc=0.8245; %Constant pulsation for rail irregularity (rad/m)
fc=0.8245/(2*pi); %(Hz/m)
S=(0.25*Av.*fc.^2)./((f.^2+fc.^2).*f.^2);
semilogx(f, S)
xlabel('frequency [Hz]')
ylabel('power spectral density of track profile [m2/Hz]')
grid on
My plotting:
my plotting

Related

How do I fit experimental data to an ODE (michaelis-menten) equation to get the constants?

I'm trying to get the kf kr and kcat from the ODE equations given by the derivation of the Michaelis-Menten equation. (https://en.wikipedia.org/wiki/Michaelis%E2%80%93Menten_kinetics).
I have experimental data form a simulation and the aproximate values of the k. I need to get a good fit for the k and I don't know how to do it, I try with lsqcurvefit the problem is that I have 2 equations and too many variables and I couldn't find any example of sth similar. If u execute the code u can see both plots the one of the equation and the experimental but I dont know how to put it together.
Thank you in advance
(plot taked from the code)
close all; clear all; clc
%Michaelis Menten Kinetics
%Simple Model for Single Substrate Catalyzed Reactions
% Initial Data
global e0 s0 c0 volum
volum=50^3;
e0=10/volum;
s0=500/volum;
c0=0;
% Load experimental data
data=dlmread("rk_output.txt");
% Assign the data vectors
global timeR subs enz compl prod
timeR=data(:,2); % time
subs=data(:,3)/volum; % Substrate
enz=data(:,4)/volum; % Enzyme
compl=data(:,5)/volum; % Complex
prod=data(:,6)/volum; % Product
% Unknown coefficients
global k
k=[1.66, 7.1E-4, 3.5E-4]; %k1 k2 k-1
% Fitting Curves to Data using Nonlinear Regression
fun=#(t,sc) [k(3)*sc(2)-k(1)*sc(1)*(e0-sc(2)); k(1)*sc(1)*(e0-sc(2))-(k(3)+k(2))*sc(2) ];
time_period=linspace(0,1000,500);
initial=[s0,c0];
[t,sc]=ode45(fun,time_period,initial);
% Assign the data vectors
substrate=sc(:,1);
complex=sc(:,2);
enzyme=(e0-complex);
product=(initial(1)-substrate-complex);
% Plot the raw data
figure(1)
plot(timeR,enz,timeR,compl,t,enzyme,t,complex)
xlabel ('time (ns)')
ylabel ('Particles')
title ('Figure 1')
legend('EnzymeReal','ComplexReal','Enzyme','Complex')

Matlab not plotting the exact fourier signal

I'm trying to plot a simple signal in fourier domain using Matlab. It's not plotting the correct signal. Here is my code:
clc;
clear all;
close all;
x=1:0.001:10;
f1=sin(2*pi*10*x);
f2=sin(2*pi*15*x);
f3=sin(2*pi*30*x);
f=f1+f2+f3;
plot(2*pi*x,fft(f1));
figure
plot(x,fft(f1));
I've expected a peak at 10 since the frequency is 10. But it is giving a peak at some other point
Here are the two plot images:
This is the image for plot(x,fft(f1))
This is the image for plot(2*pi*x,fft(f1))
It is not showing the peak at 10.I even tried using abs(fft(f1)). No luck :/
Isn't it the correct way to plot signal in fourier domain?
The fft function assumes unit time step. In order to correct for non unit time step you need to define the frequency component based on the nyquist rate. The following code plots the magnitude of the fft with the correct frequency axis.
clc;
clear all;
close all;
x=1:0.001:10;
% ^ this is your sampling time step
f1=sin(2*pi*10*x);
f2=sin(2*pi*15*x);
f3=sin(2*pi*30*x);
% bounds of fourier transform based on sampling rate
Fs = 1/0.001;
ff = linspace(-Fs/2,Fs/2,numel(x));
F1 = fftshift(fft(f1)/numel(x));
F2 = fftshift(fft(f2)/numel(x));
F3 = fftshift(fft(f3)/numel(x));
figure();
plot(ff,abs(F1),'-r'); hold on;
plot(ff,abs(F2),'-b');
plot(ff,abs(F3),'-k');
Edit: To answer OPs question in the comment.
Speaking in normalized frequency units (assuming sampling rate of 1). The fft function returns the frequency response from 0 to 2*pi radians, but due to some signal processing properties and the way that discrete signals are interpreted when performing an FFT, the signal is actually periodic so the pi to 2*pi section is identical to the -pi to 0 section. To display the plot with the DC component (0 frequency) in the center we use fftshift which does a circular shift equal to 1/2 the length of the signal on the data returned by fft. Before you take the ifft make sure you use ifftshift to put it back in the right place.
Edit2: The normalization term (/numel(x)) is necessary to estimate the continuous time fourier transform using the discrete fourier transform. I don't remember the precise mathematical reason off the top of my head but the examples in the MATLAB documentation also imply the necessity of this normalization.
Edit 3: The original link that I had is down. I may come back to add a more detailed answer but in the mean time I definitely recommend that anyone interested in understanding the relationship between the fundamentals of the FS, FT, DTFT, and DFT watch Professor Oppenheim's hilariously old, but amazingly informative and straightforward lectures on MIT OpenCourseWare.

Analyzing wav files in MATLAB

So I have this piano recording (in .wav format). I am able to do an FFT on the whole recording and identify frequencies.
However, according to some articles I read, its best if the wav file is broken down into windows, where each window would include one particular note.
For this I need to initially plot a "power envelope" of my time domain signal (considering the note average energy concept) therefore there'll be one increase and one decrease for each note and note onsets can be determined by checking the local minima.
This is where 'windows' are introduced, where each window consists of only one onset and then FFT is performed on each window.
Im having difficulty in plotting the power envelope and moving onto breaking it down into windows. Would appreciate some help with the Matlab coding for this.
The code I've used is pretty straightforward:
[wave,fs] = wavread ('c scale fast.wav'); % read file into memory */
%sound(wave,fs); % see what it sounds like */
wave = wave.*hamming(length(wave));
t = 0:1/fs:(length(wave)-1)/fs; % and get sampling frequency */
figure(2);
subplot(2,1,1);
plot(t,wave);
title('Wave File');
ylabel('Amplitude');
xlabel('Length (in seconds)');
L = length(wave);
NFFT = 2^nextpow2(L); % Next power of 2 from length of y
Y = fft(wave,NFFT)/L;
f = fs/2*linspace(0,1,NFFT/2+1);
% Plot single-sided amplitude spectrum.
subplot(2,1,2);
plot(f,2*abs(Y(1:NFFT/2+1)))
title('Single-Sided Amplitude Spectrum of y(t)')
xlabel('Frequency (Hz)')
ylabel('|Y(f)|')
After my signal (abs value of my wav file) is convolved with the Gaussian filter i try taking the 1st and 2nd derivatives, but i don't get an output when i try to plot it.
edges=fconv(abs(song),detect);
tedges=edges(P/2:N+P/2-1);
tedges=tedges/max(abs(tedges));
W= diff(tedge);
Z= diff(W);
It is when i try to plot W and Z that I don't get the output I need. My graph is empty in other words. I can't figure out what I'm doing wrong here...
Useful: http://blogs.mathworks.com/videos/2009/12/31/basics-finding-a-subset-of-a-matrix/
Basic flow:
for v=1:window_length:length(data)
data_subsection=data(v:v+window_length);
subsection_fft = fft(data_subsection);
plot(...);
end

PSD estimation via FFT

I estimate Power Spectral Density (PSD) for Gaussian monopulse in UWB band. I have two codes, using fft. But there is a problem with y axes, since I don't know its dimension (I need PSD in dBm/MHz). And also it should be a mistake in the first code, since it shows only one value at the y axes.
Code1
fs=1e11;
g=0.1e-9;
tmax=1e-9;
fftl=2048;
t=(-tmax:1./fs:tmax)';
s=t./(g.^3.*sqrt(2.*pi)).*exp(-t.^2./(2.*g.^2))./2.5e19;
figure(1)
plot(t,s);
xlabel('Time, s');
ylabel('Amplitude, V');
ffts=abs(fft(s,fftl));
ffts=2.*ffts./fftl;
fftp=abs(ffts.*conj(ffts))./2;
fftps=(fftp-30)./1e-6;
f=0:fs./fftl:fs./2-fs./fftl;
figure(2)
plot(f,fftps(1:length(f))),grid;
xlabel('Frequency, Hz');
Code2
fs=1e11;
g=0.1e-9;
tmax=1e-9;
t=(-tmax:1./fs:tmax)';
s=t./(g.^3.*sqrt(2.*pi)).*exp(-t.^2./(2.*g.^2))./2.5e19;
figure(1)
plot(t,s);
xlabel('Time, s');
ylabel('Amplitude, V');
S=fft(s,8192);
f=fs.*(0:4095)./8192;
Pss=S.*conj(S)./8192;
figure(2)
plot(f,Pss(1:4096));
Thank you so much for any help!
Your second plot should give you a plot with units V^2/Hz.
dBm units are measure of power relative to 1 mW, so you have to know the impedance of your measurement.
So to get to mW/Hz you would want to multiply by 1e6/R, where R is your impedance. Then take 10*log10 of the result and you have dBm/Hz.

Confusion Regarding The Fourier Series In Matlab

I am currently studying DSP and i'm using the Matlab software package to work my way through the the problems. I am currently just starting to attempt to learn about the fourier series and am having trouble with the following problem.
Generate an 100hz triangle wave using Fourier Series.
Now, i cant quite understand this part of the problem about using the fourier series.
I have generated a 100hz triangle wave with the following matlab code:
t = 0:1/10000:1;
f=100;
x1 = sawtooth(2*pi*f*t, 0.5);
x2 = fft(x1);
plot(t,x1);
axis([0 0.10 -1 1]);
grid on;
Now what code would i use within matlab to plot the fourier series of this triangle wave?
Thanks to anyone who may have some input for this particular problem.
I think what the question is asking is for you to figure out the 'a' and 'b' coefficients and then generate the sawtooth wave by summing sines and cosines at the appropriate frequencies. It's not too hard to find the Fourier coefficients for a sawtooth wave online, but I encourage you to work it out and use that to check your answer :)
Then do something like this
n_harmonics = 10;
n = zeros(1, n_harmonics);
a = ?; % for you to figure out - probably a function of n
b = ?; % same idea
t = linspace(0, 2*pi);
x = zeros(size(t));
for nx = 1 : n,
x = x + a(nx)*cos(nx*t) + b(nx)*sin(nx*t);
end
plot(t, x)
Note the Fourier series is not the same thing as the Fourier transform, which is what fft is estimating. Most texts on signal processing will start with the Fourier series and build on that to get to the Fourier transform. Note also that there are tons of important and subtle differences when moving from continuous time to discrete time. Again, most textbooks will probably start with continuous time and then use that as a basis to introduce the discrete-time concepts.