Reputation: 27
Why does my Fourier not work properly? Where did I do mistake? Is the time domain that I wrote correct or not? The signal equation that I used is this:
f = 5; %fixed signal frequency
fs = 100; %fixed sample frequency (100Hz)
A=1; %fixed amplitude (1)
l=1; % (sec) fixed signal length
k = app.FourierSerieslength.Value; %myFourier series length is 1 to 21
t = 0:1/fs:l-1/fs;
% y = A*sin(2*pi*f*t*k);
y = (4*A/pi)*1/k*sin(2*pi*f*t*k); %Fourier series for the square wave signal
plot(app.UIAxes,t,y);
My result for Fourier length 3 is:
and result for Fourier series length 10:
Is that correct for length 10?
Why do I not have a square wave?
Another question is that I use this Fourier series for Up-/Downsampling and no change in time-domain views?
Here is my code for upsampling:
up = app.UpSamplingSlider.Value;
y_up = zeros(1,length(y)*4);
y_up(1:4:4*length(y)) = y;
y_up = up*y_up;
stem(app.UIAxes3,y_up);
Upvotes: 1
Views: 303
Reputation: 60514
y = (4*A/pi)*1/k*sin(2*pi*f*t*k); %Fourier series for the square wave signal
No, it's not a series, it's a sine wave. When k=10
, this reduces to some constant times sin(pi*(0:99))
, which is zero everywhere (up to numerical precision). Whenever you see the vertical axis have a 10E-14
multiplier, you can be fairly sure it's just zeros up to floating-point precision.
To compute the Fourier series, you need to include the big Σ symbol in the equation:
y = zeros(size(t))
for k=1:2:21
y = y + (4*A/pi)*1/k*sin(2*pi*f*t*k);
end
Now when you plot this, you'll see an approximation to the square waveform. The larger the upper limit in the summation, the better the approximation.
Upvotes: 1