Question

Generating a square wave This function approximates a square wave by summing a series of sinusoidal functions of various freq
0 0
Add a comment Improve this question Transcribed image text
Answer #1

The name of the function is my_square and can be called from the command window:

function my_square(k)
w=1;
fs=1000;
t=0:1/fs:15;
f=[-0.5*fs:fs/(length(t)-1):0.5*fs];
x=0;
for i=1:k
x=x+sin(w*t*(2*i-1))/(2*i-1);
end
X=fft(x);
X=fftshift(X);
figure;
subplot(2,1,1);
plot(t,x);
val=int2str(k);
tit=strcat('The plot for k=',val);
title(tit);xlabel('time'),ylabel('Value');
subplot(2,1,2);
plot(f,abs(X));
title('Magnitude Spectrum');xlabel('frequency');ylabel('Magnitude');
end

Now, calling my_square(25) from command window provides the following plot:

Add a comment
Know the answer?
Add Answer to:
Generating a square wave This function approximates a square wave by summing a series of sinusoid...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Program from problem 1: (Using MATLAB) % Sampling frequency and sampling period fs = 10000; ts...

    Program from problem 1: (Using MATLAB) % Sampling frequency and sampling period fs = 10000; ts = 1/fs; % Number of samples, assume 1000 samples l = 1000; t = 0:1:l-1; t = t.*ts; % Convert the sample index into time for generation and plotting of signal % Frequency and amplitude of the sensor f1 = 110; a1 = 1.0; % Frequency and amplitude of the power grid noise f2 = 60; a2 = 0.7; % Generating the sinusoidal waves...

  • This is a MATLAB Question. Below is my base code for a Fourier Series of a...

    This is a MATLAB Question. Below is my base code for a Fourier Series of a half triangle wave. So I am being asked to isolate the first 8 components so that only those first 8 components of the half triangle function are calculated by MATLAB fft function, and then afterwards I am asked to do the same thing but with the first 20 components rather than the first 8. How do I isolate the first x number of components...

  • Can you write hand solutions and matlab code please? Q3) There is a square wave with...

    Can you write hand solutions and matlab code please? Q3) There is a square wave with the period of T=21. The amplitude is 3 between 0 and it The amplitude is 0 between 1 and 2 T. 2 3 4 5 a) Find the Fourier series coefficients of this square wave. a = x()ật Il x(t)cos(kt)dt bx = ( x(t)sin(kt)dt b) Using Matlab, plot the truncated Fourier series; (1) For k 0 to 10 (II) For k 0 to 1000...

  • Using Matlab, plot the following ultrasound pressure wave as a function of x for t =...

    Using Matlab, plot the following ultrasound pressure wave as a function of x for t = 1 P(t, x) = P_0 e^- x cos(omega t - beta x) Where alpha = 0.1 neper/m, where neper is a dimensionless quantity, beta = 1 rad/min, omega = 1 red/s, P_0 = 10 N/m^2. Submit your ".m" file as the resulting graph labeled appropriately.

  • Can someone explain each part of this solution I don’t understand Example 1 square wave Derive...

    Can someone explain each part of this solution I don’t understand Example 1 square wave Derive the Fourier series (FS) representation of a square wave of period T with duty cycle τ-AT, where 0< B<1. The square wave is symmetrically defined over one period by a Heaviside unit-step function, as in Eq. (28) It! <汁 (77) The ordinary unit-step could also be used, but the Heaviside is more natural here because the FS representation will pass through the 1/2 point...

  • Use MATLAB to : ("j" is the imaginary number.) The term lo is the fundamental frequency...

    Use MATLAB to : ("j" is the imaginary number.) The term lo is the fundamental frequency of the periodic signal, 2/T, where T is the period. Frequencies nlo, where n is an integer, are the harmonics. This infinite sum is an exact representation of the original function. If we use a finite sum, where n goes from -N to N, we will get an approximation "X-(t)". In this problem we will calculate and plot the Fourier series representation of a...

  • NB! This task is required to be solved in matlab. this task also requires the use...

    NB! This task is required to be solved in matlab. this task also requires the use of the function displayDualSpectrum(); which i have pasted in the bottom. the tasks that i need help with are A), B) and C). this is a multi-part question. Task - Frequency mixing We use a basic signal that can be described mathematically as follows: with this We shall then make an amplitude modulated signal: where fc is the carrier frequency. the code below specifies...

  • Can you please help me answer Task 2.b? Please show all work. fs=44100; no_pts=8192; t=([0:no_pts-1]')/fs; y1=sin(2...

    Can you please help me answer Task 2.b? Please show all work. fs=44100; no_pts=8192; t=([0:no_pts-1]')/fs; y1=sin(2*pi*1000*t); figure; plot(t,y1); xlabel('t (second)') ylabel('y(t)') axis([0,.004,-1.2,1.2]) % constrain axis so you can actually see the wave sound(y1,fs); % play sound using windows driver. %% % Check the frequency domain signal. fr is the frequency vector and f1 is the magnitude of F{y1}. fr=([0:no_pts-1]')/no_pts*fs; %in Hz fr=fr(1:no_pts/2); % single-sided spectrum f1=abs(fft(y1)); % compute fft f1=f1(1:no_pts/2)/fs; %% % F is the continuous time Fourier. (See derivation...

  • Problem 2: Consider the following periodic signals x(t), a square wave, and yt), a saw tooth...

    Problem 2: Consider the following periodic signals x(t), a square wave, and yt), a saw tooth 2T The pulses width of x(t) т, wave. Both have the same amplitude A and the same frequency - equal T. The duty-cycle of x(t) is defined as d- T. -A From tables of Fourier Series ofvarious periodic signals, the following formulas are given for your convenience x(= Ad+2Adnacos at+2Ad sna cos 2at+2Adl sun 3xdcos3at яd 2лd Зяd 24 (sin a 1 sin 2asin3ajain...

  • [MATLAB Scriptfile task] Design N-band tone vocoder with a given figure (below) in MATLAB implementing the...

    [MATLAB Scriptfile task] Design N-band tone vocoder with a given figure (below) in MATLAB implementing the given script file(bands_cutoff). This program should be able to process any sound(.wav) file. Then, graph the band-passed signals and amplitude envelopes extracted(after rectification and low-pass filtering) and waveforms of the original sound and vocoded sound. Additionally, using the output of the script file, make spectrograms of the original sound and the synthesized sound. Bandpass filter Modulation Band-limiting Envelope detection BPF RECT LPF BPF sine...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT