MATLAB Answers

Square wave generator similar to dsp.SineWave

10 views (last 30 days)
masnoob
masnoob on 8 Jan 2019
Commented: masnoob on 10 Jan 2019
I know squarewave() function, but I would like to know is there an equivalent system object square wave generator, just like dsp.SineWave so I can generate 1024 samples per loop for demodulation purposes in streaming processing of audio signals.
Thanks

  2 Comments

Walter Roberson
Walter Roberson on 8 Jan 2019
is this for use in simulink ? if so the repeating pattern generator can be used.
masnoob
masnoob on 8 Jan 2019
I actually have implemented stream processing where the entire process is real time based, contained within a while loop, currently using sine wave but I just want to produce square wave instead in matlab, not simulink.

Sign in to comment.

Accepted Answer

Gabriele Bunkheila
Gabriele Bunkheila on 9 Jan 2019
Please take a look at audioOscillator in Audio System Toolbox, which can generate sine, square, and sawtooth waveforms.

  3 Comments

masnoob
masnoob on 9 Jan 2019
Damn why I don't have the memory on this section when scrolling through all of the documentation of audio system toolbox. A great thanks to Gabriele, this is EXACTLY the tool I am looking for! Thanks alot !
Edit: Since you are from the audio system toolbox team, may I know is there a way to extract the frequency response of the graphicEQ System object ? (not using 'visualize()' since it create a new window)? Just like the plot shown in the top of documentation. I would like to plot it on a seperate figure, such as UIAxes in appdesigner for visualization purposes.
Gabriele Bunkheila
Gabriele Bunkheila on 9 Jan 2019
Glad to hear that helped!
As for visualizing the response of graphicEQ, if the visualize() doesn't work for you, then you may want to use coeffs() to extract the filter coefficients and then plot the response using a standard approach, such as the following:
% Create and configure the equalizer
g = graphicEQ;
g.Gains = 6*randn(size(g.Gains)); % random gains in dB
% Extract the coefficients
[B,A] = coeffs(g);
% Compute the response using the SOS argument format for coefficients
[h,f] = freqz([B;ones(1,size(B,2));A]',4096,g.SampleRate);
% Plot magnitude over frequency and customize appearance
hp = plot(f,db(abs(h)));
hp.Parent.XScale = 'log';
hp.Parent.XLim = [20, 20e3];
xlabel('Frequency (Hz)')
ylabel('Response (dB)')
grid('on')
masnoob
masnoob on 10 Jan 2019
Thanks Gabriele! the solution worked like a charm!

Sign in to comment.

More Answers (0)

Products


Release

R2018b