How to use frest.Sinestream to create a sine wave sound
3 views (last 30 days)
Show older comments
I use the code below to create a 6 secs long sine wave which contain 0~2 sec was 200 Hz, 2~4 sec was 100 Hz, 4~6 sec was 300 Hz.
result=frest.Sinestream('Amplitude',0.5,...
'Frequency',[200 100 300],...
'SamplesPerPeriod',ceil([44100/200 44100/100 44100/300]),...
'FreqUnits','Hz',...
'RampPeriods',[0.02/(1/200),0.02/(1/100),0.02/(1/300)],...
'NumPeriods',[200*2-4 100*2-2 300*2-6]);
The sine wave's sampling rate must be 44100 Hz, so each period's sample was according to it's frequency.(ex:0~2 sec was 200 Hz, so per period was 44100/200 samples.), and Ramp was 20ms long, so 200 Hz was 4 ramp period (0.02/(1/200)). and NumPeriods was 2 secs long each frequency. ex: 200 Hz*2-4(ramp period).
After that, the result was a Undefined function or method 'lt' for input arguments of type 'frest.Sinestream'. So it couldn't use wavwrite function to write into a wav file.
I found
x=generateTimeseries(result);
and x was a double timeseries, which x.Data can wavwrite into a wav file. Then I got a sine wave sound which has dynamic frequency. But, it was 6.0045 sec long, I found that the 0~2sec was incorrect. I though is because it's 'SamplesPerPeriod' was 44100/200=220.5 was not int. and I ceil it. How can I fix this problem?
Thanks
0 Comments
Accepted Answer
Arkadiy Turevskiy
on 19 Feb 2013
frest is part of Simulink Control Design. You need to have a license of this product to use frest. I ran your code and was able to get the signal you are trying to generate.
You can check the products on your license by typing
>>ver
HTH.
Arkadiy
0 Comments
More Answers (0)
See Also
Categories
Find more on Audio Processing Algorithm Design in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!