# Using odd harmonics creat a sine wave (square) for 1khz

18 Ansichten (letzte 30 Tage)
Nabeel Ahmed am 28 Jun. 2021
Kommentiert: Stephen23 am 30 Jun. 2021
Using MATLAB
##### 0 Kommentare-1 ältere Kommentare anzeigen-1 ältere Kommentare ausblenden

Melden Sie sich an, um zu kommentieren.

### Antworten (1)

Bhavya Chopra am 30 Jun. 2021
Please note, Frequency of square wave is same as the fundamental frequency (F0), we initialize F0 as 1000. The Sampling Frequency (samplingRate) and time for which the sound is produced (secs) can also be adjusted. A square wave for 1kHz can be created in MATLAB using odd harmonics as follows:
samplingRate = 48000; % Sampling Frequency
F0 = 1000; % Fundamental Frequency
secs = 10; % Time for which the sound will play
t = linspace(0, secs, samplingRate*secs); % Create time vector
w = 2*pi*F0; % Radian value to create tone with Frequency F0
s = sin(w*t) + sin(3*w*t)/3 + ... % Create Square Wave using odd harmonics
sin(5*w*t)/5 + sin(7*w*t)/7;
sound(s, samplingRate) % Producing sound
The square wave can also be plotted as follows:
plot(t(1:100), s(1:100)); % Plotting the square wave for 100 samples
title("Square Wave Plot");
xlabel("Time");
ylabel("Amplitude");
Generated plot:
##### 1 KommentarKeine anzeigenKeine ausblenden
Stephen23 am 30 Jun. 2021

Melden Sie sich an, um zu kommentieren.

### Kategorien

Find more on Transforms in Help Center and File Exchange

R2021a

### Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by